/** * Encode a {@link CharSequence} in <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> and write * it to a {@link ByteBuf}. * <p> * It behaves like {@link #reserveAndWriteUtf8(ByteBuf, CharSequence, int)} with {@code reserveBytes} * computed by {@link #utf8MaxBytes(CharSequence)}.<br> * This method returns the actual number of bytes written. */ public static int writeUtf8(ByteBuf buf, CharSequence seq) { return reserveAndWriteUtf8(buf, seq, utf8MaxBytes(seq)); }
/** * Encode a {@link CharSequence} in <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> and write * it to a {@link ByteBuf}. * <p> * It behaves like {@link #reserveAndWriteUtf8(ByteBuf, CharSequence, int)} with {@code reserveBytes} * computed by {@link #utf8MaxBytes(CharSequence)}.<br> * This method returns the actual number of bytes written. */ public static int writeUtf8(ByteBuf buf, CharSequence seq) { return reserveAndWriteUtf8(buf, seq, utf8MaxBytes(seq)); }
/** * Encode a {@link CharSequence} in <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> and write * it to a {@link ByteBuf}. * <p> * It behaves like {@link #reserveAndWriteUtf8(ByteBuf, CharSequence, int)} with {@code reserveBytes} * computed by {@link #utf8MaxBytes(CharSequence)}.<br> * This method returns the actual number of bytes written. */ public static int writeUtf8(ByteBuf buf, CharSequence seq) { return reserveAndWriteUtf8(buf, seq, utf8MaxBytes(seq)); }
/** * Encode a {@link CharSequence} in <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> and write * it to a {@link ByteBuf}. * <p> * It behaves like {@link #reserveAndWriteUtf8(ByteBuf, CharSequence, int)} with {@code reserveBytes} * computed by {@link #utf8MaxBytes(CharSequence)}.<br> * This method returns the actual number of bytes written. */ public static int writeUtf8(ByteBuf buf, CharSequence seq) { return reserveAndWriteUtf8(buf, seq, utf8MaxBytes(seq)); }
/** * Encode a {@link CharSequence} in <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> and write * it to a {@link ByteBuf}. * <p> * It behaves like {@link #reserveAndWriteUtf8(ByteBuf, CharSequence, int)} with {@code reserveBytes} * computed by {@link #utf8MaxBytes(CharSequence)}.<br> * This method returns the actual number of bytes written. */ public static int writeUtf8(ByteBuf buf, CharSequence seq) { return reserveAndWriteUtf8(buf, seq, utf8MaxBytes(seq)); }
/** * Encode a {@link CharSequence} in <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> and write * it to a {@link ByteBuf}. * <p> * It behaves like {@link #reserveAndWriteUtf8(ByteBuf, CharSequence, int)} with {@code reserveBytes} * computed by {@link #utf8MaxBytes(CharSequence)}.<br> * This method returns the actual number of bytes written. */ public static int writeUtf8(ByteBuf buf, CharSequence seq) { return reserveAndWriteUtf8(buf, seq, utf8MaxBytes(seq)); }
/** * Encode a {@link CharSequence} in <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> and write * it to a {@link ByteBuf}. * <p> * It behaves like {@link #reserveAndWriteUtf8(ByteBuf, CharSequence, int)} with {@code reserveBytes} * computed by {@link #utf8MaxBytes(CharSequence)}.<br> * This method returns the actual number of bytes written. */ public static int writeUtf8(ByteBuf buf, CharSequence seq) { return reserveAndWriteUtf8(buf, seq, utf8MaxBytes(seq)); }
public static ByteBuf encode( ByteBufAllocator allocator, CharSequence fromDestination, CharSequence fromGroup, CharSequence toGroup, ByteBuf metadata) { ByteBuf byteBuf = FrameHeaderFlyweight.encodeFrameHeader(allocator, FrameType.BROADCAST); int fromDestinationLength = ByteBufUtil.utf8Bytes(fromDestination); byteBuf.writeInt(fromDestinationLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, fromDestination, fromDestinationLength); int fromGroupLength = ByteBufUtil.utf8Bytes(fromGroup); byteBuf.writeInt(fromGroupLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, fromGroup, fromGroupLength); int toGroupLength = ByteBufUtil.utf8Bytes(toGroup); byteBuf.writeInt(toGroupLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, toGroup, toGroupLength); byteBuf.writeBytes(metadata, metadata.readerIndex(), metadata.readableBytes()); return byteBuf; }
public static ByteBuf encode( ByteBufAllocator allocator, CharSequence fromDestination, CharSequence fromGroup, CharSequence toGroup, ByteBuf metadata) { ByteBuf byteBuf = FrameHeaderFlyweight.encodeFrameHeader(allocator, FrameType.GROUP); int fromDestinationLength = ByteBufUtil.utf8Bytes(fromDestination); byteBuf.writeInt(fromDestinationLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, fromDestination, fromDestinationLength); int fromGroupLength = ByteBufUtil.utf8Bytes(fromGroup); byteBuf.writeInt(fromGroupLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, fromGroup, fromGroupLength); int toGroupLength = ByteBufUtil.utf8Bytes(toGroup); byteBuf.writeInt(toGroupLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, toGroup, toGroupLength); byteBuf.writeBytes(metadata, metadata.readerIndex(), metadata.readableBytes()); return byteBuf; }
public static ByteBuf encode( ByteBufAllocator allocator, CharSequence fromDestination, CharSequence fromGroup, CharSequence toGroup, ByteBuf metadata) { ByteBuf byteBuf = FrameHeaderFlyweight.encodeFrameHeader(allocator, FrameType.BROADCAST); int fromDestinationLength = ByteBufUtil.utf8Bytes(fromDestination); byteBuf.writeInt(fromDestinationLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, fromDestination, fromDestinationLength); int fromGroupLength = ByteBufUtil.utf8Bytes(fromGroup); byteBuf.writeInt(fromGroupLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, fromGroup, fromGroupLength); int toGroupLength = ByteBufUtil.utf8Bytes(toGroup); byteBuf.writeInt(toGroupLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, toGroup, toGroupLength); byteBuf.writeBytes(metadata, metadata.readerIndex(), metadata.readableBytes()); return byteBuf; }
public static ByteBuf encode( ByteBufAllocator allocator, CharSequence fromDestination, CharSequence fromGroup, CharSequence toGroup, ByteBuf metadata) { ByteBuf byteBuf = FrameHeaderFlyweight.encodeFrameHeader(allocator, FrameType.GROUP); int fromDestinationLength = ByteBufUtil.utf8Bytes(fromDestination); byteBuf.writeInt(fromDestinationLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, fromDestination, fromDestinationLength); int fromGroupLength = ByteBufUtil.utf8Bytes(fromGroup); byteBuf.writeInt(fromGroupLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, fromGroup, fromGroupLength); int toGroupLength = ByteBufUtil.utf8Bytes(toGroup); byteBuf.writeInt(toGroupLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, toGroup, toGroupLength); byteBuf.writeBytes(metadata, metadata.readerIndex(), metadata.readableBytes()); return byteBuf; }
public static ByteBuf encode( ByteBufAllocator allocator, CharSequence fromDestination, CharSequence fromGroup, CharSequence toDestination, CharSequence toGroup, ByteBuf metadata) { ByteBuf byteBuf = FrameHeaderFlyweight.encodeFrameHeader(allocator, FrameType.DESTINATION); int fromDestinationLength = ByteBufUtil.utf8Bytes(fromDestination); byteBuf.writeInt(fromDestinationLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, fromDestination, fromDestinationLength); int fromGroupLength = ByteBufUtil.utf8Bytes(fromGroup); byteBuf.writeInt(fromGroupLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, fromGroup, fromGroupLength); int toDestinationLength = ByteBufUtil.utf8Bytes(toDestination); byteBuf.writeInt(toDestinationLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, toDestination, toDestinationLength); int toGroupLength = ByteBufUtil.utf8Bytes(toGroup); byteBuf.writeInt(toGroupLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, toGroup, toGroupLength); byteBuf.writeBytes(metadata, metadata.readerIndex(), metadata.readableBytes()); return byteBuf; }
public static ByteBuf mapToByteBuf(ByteBufAllocator allocator, Map<String, String> map) { if (map == null || map.isEmpty()) { return Unpooled.EMPTY_BUFFER; } ByteBuf byteBuf = allocator.buffer(); for (Map.Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); int keyLength = NumberUtils.requireUnsignedShort(ByteBufUtil.utf8Bytes(key)); byteBuf.writeShort(keyLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, key, keyLength); String value = entry.getValue(); int valueLength = NumberUtils.requireUnsignedShort(ByteBufUtil.utf8Bytes(value)); byteBuf.writeShort(valueLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, value, keyLength); } return byteBuf; }
public static ByteBuf encode( ByteBufAllocator allocator, CharSequence brokerId, CharSequence clusterId, long accessKey, ByteBuf accessToken) { Objects.requireNonNull(brokerId); Objects.requireNonNull(clusterId); ByteBuf byteBuf = FrameHeaderFlyweight.encodeFrameHeader(allocator, FrameType.BROKER_SETUP); int brokerIdLength = ByteBufUtil.utf8Bytes(brokerId); byteBuf.writeInt(brokerIdLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, brokerId, brokerIdLength); int clusterIdLength = ByteBufUtil.utf8Bytes(clusterId); byteBuf.writeInt(clusterIdLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, clusterId, clusterIdLength); int authTokenSize = accessToken.readableBytes(); byteBuf .writeLong(accessKey) .writeInt(authTokenSize) .writeBytes(accessToken, accessToken.readerIndex(), authTokenSize); return byteBuf; }
public static ByteBuf encode( ByteBufAllocator allocator, CharSequence fromDestination, CharSequence fromGroup, CharSequence toGroup, ByteBuf shardKey, ByteBuf metadata) { ByteBuf byteBuf = FrameHeaderFlyweight.encodeFrameHeader(allocator, FrameType.SHARD); int fromDestinationLength = ByteBufUtil.utf8Bytes(fromDestination); byteBuf.writeInt(fromDestinationLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, fromDestination, fromDestinationLength); int fromGroupLength = ByteBufUtil.utf8Bytes(fromGroup); byteBuf.writeInt(fromGroupLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, fromGroup, fromGroupLength); int toGroupLength = ByteBufUtil.utf8Bytes(toGroup); byteBuf.writeInt(toGroupLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, toGroup, toGroupLength); int shardKeyLength = shardKey.readableBytes(); byteBuf .writeInt(shardKeyLength) .writeBytes(shardKey, shardKey.readerIndex(), shardKeyLength) .writeBytes(metadata, metadata.readerIndex(), metadata.readableBytes()); return byteBuf; }
public static ByteBuf encode( ByteBufAllocator allocator, String service, String method, ByteBuf tracing, ByteBuf metadata) { ByteBuf byteBuf = allocator.buffer().writeShort(VERSION); int serviceLength = NumberUtils.requireUnsignedShort(ByteBufUtil.utf8Bytes(service)); byteBuf.writeShort(serviceLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, service, serviceLength); int methodLength = NumberUtils.requireUnsignedShort(ByteBufUtil.utf8Bytes(method)); byteBuf.writeShort(methodLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, method, methodLength); byteBuf.writeShort(tracing.readableBytes()); byteBuf.writeBytes(tracing, tracing.readerIndex(), tracing.readableBytes()); byteBuf.writeBytes(metadata, metadata.readerIndex(), metadata.readableBytes()); return byteBuf; }
public static ByteBuf encode( ByteBufAllocator allocator, CharSequence brokerId, CharSequence clusterId, long accessKey, ByteBuf accessToken) { Objects.requireNonNull(brokerId); Objects.requireNonNull(clusterId); ByteBuf byteBuf = FrameHeaderFlyweight.encodeFrameHeader(allocator, FrameType.BROKER_SETUP); int brokerIdLength = ByteBufUtil.utf8Bytes(brokerId); byteBuf.writeInt(brokerIdLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, brokerId, brokerIdLength); int clusterIdLength = ByteBufUtil.utf8Bytes(clusterId); byteBuf.writeInt(clusterIdLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, clusterId, clusterIdLength); int authTokenSize = accessToken.readableBytes(); byteBuf .writeLong(accessKey) .writeInt(authTokenSize) .writeBytes(accessToken, accessToken.readerIndex(), authTokenSize); return byteBuf; }
public static ByteBuf encode( ByteBufAllocator allocator, CharSequence fromDestination, CharSequence fromGroup, CharSequence toDestination, CharSequence toGroup, ByteBuf metadata) { ByteBuf byteBuf = FrameHeaderFlyweight.encodeFrameHeader(allocator, FrameType.DESTINATION); int fromDestinationLength = ByteBufUtil.utf8Bytes(fromDestination); byteBuf.writeInt(fromDestinationLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, fromDestination, fromDestinationLength); int fromGroupLength = ByteBufUtil.utf8Bytes(fromGroup); byteBuf.writeInt(fromGroupLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, fromGroup, fromGroupLength); int toDestinationLength = ByteBufUtil.utf8Bytes(toDestination); byteBuf.writeInt(toDestinationLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, toDestination, toDestinationLength); int toGroupLength = ByteBufUtil.utf8Bytes(toGroup); byteBuf.writeInt(toGroupLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, toGroup, toGroupLength); byteBuf.writeBytes(metadata, metadata.readerIndex(), metadata.readableBytes()); return byteBuf; }
public static ByteBuf encode( ByteBufAllocator allocator, CharSequence fromDestination, CharSequence fromGroup, CharSequence toGroup, ByteBuf shardKey, ByteBuf metadata) { ByteBuf byteBuf = FrameHeaderFlyweight.encodeFrameHeader(allocator, FrameType.SHARD); int fromDestinationLength = ByteBufUtil.utf8Bytes(fromDestination); byteBuf.writeInt(fromDestinationLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, fromDestination, fromDestinationLength); int fromGroupLength = ByteBufUtil.utf8Bytes(fromGroup); byteBuf.writeInt(fromGroupLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, fromGroup, fromGroupLength); int toGroupLength = ByteBufUtil.utf8Bytes(toGroup); byteBuf.writeInt(toGroupLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, toGroup, toGroupLength); int shardKeyLength = shardKey.readableBytes(); byteBuf .writeInt(shardKeyLength) .writeBytes(shardKey, shardKey.readerIndex(), shardKeyLength) .writeBytes(metadata, metadata.readerIndex(), metadata.readableBytes()); return byteBuf; }
public static ByteBuf encode( ByteBufAllocator allocator, CharSequence destination, CharSequence group, long accessKey, ByteBuf accessToken) { Objects.requireNonNull(destination); Objects.requireNonNull(group); ByteBuf byteBuf = FrameHeaderFlyweight.encodeFrameHeader(allocator, FrameType.DESTINATION_SETUP); int destinationLength = ByteBufUtil.utf8Bytes(destination); byteBuf.writeInt(destinationLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, destination, destinationLength); int groupLength = ByteBufUtil.utf8Bytes(group); byteBuf.writeInt(groupLength); ByteBufUtil.reserveAndWriteUtf8(byteBuf, group, groupLength); int accessTokenSize = accessToken.readableBytes(); byteBuf .writeLong(accessKey) .writeInt(accessTokenSize) .writeBytes(accessToken, accessToken.readerIndex(), accessTokenSize); return byteBuf; }