private static void requestWriteBlock(Channel channel, Enum<?> storageType, OpWriteBlockProto.Builder writeBlockProtoBuilder) throws IOException { OpWriteBlockProto proto = STORAGE_TYPE_SETTER.set(writeBlockProtoBuilder, storageType).build(); int protoLen = proto.getSerializedSize(); ByteBuf buffer = channel.alloc().buffer(3 + CodedOutputStream.computeRawVarint32Size(protoLen) + protoLen); buffer.writeShort(DataTransferProtocol.DATA_TRANSFER_VERSION); buffer.writeByte(Op.WRITE_BLOCK.code); proto.writeDelimitedTo(new ByteBufOutputStream(buffer)); channel.writeAndFlush(buffer); }
/** * Writes a big-endian 16-bit short integer to the buffer. */ @SuppressWarnings("deprecation") public static ByteBuf writeShortBE(ByteBuf buf, int shortValue) { return buf.order() == ByteOrder.BIG_ENDIAN? buf.writeShort(shortValue) : buf.writeShortLE(shortValue); }
@Override public ByteBuf writeShort(int value) { buf.writeShort(value); return this; }
@Override public ByteBuf writeShortLE(int value) { buf.writeShort((short) value); return this; }
@Override public void writeShort(int v) throws IOException { buffer.writeShort((short) v); }
@Override public ByteBuf writeShort(int value) { buf.writeShort(ByteBufUtil.swapShort((short) value)); return this; }
private void writeControlFrameHeader(ByteBuf buffer, int type, byte flags, int length) { buffer.writeShort(version | 0x8000); buffer.writeShort(type); buffer.writeByte(flags); buffer.writeMedium(length); }
/** * Creates a new 2-byte big-endian buffer that holds the specified 16-bit integer. */ public static ByteBuf copyShort(int value) { ByteBuf buf = buffer(2); buf.writeShort(value); return buf; }
private static void writeBulkStringContent(ByteBufAllocator allocator, BulkStringRedisContent msg, List<Object> out) { out.add(msg.content().retain()); if (msg instanceof LastBulkStringRedisContent) { out.add(allocator.ioBuffer(RedisConstants.EOL_LENGTH).writeShort(RedisConstants.EOL_SHORT)); } }
private static ByteBuf newBinaryData(int statusCode, String reasonText) { if (reasonText == null) { reasonText = StringUtil.EMPTY_STRING; } ByteBuf binaryData = Unpooled.buffer(2 + reasonText.length()); binaryData.writeShort(statusCode); if (!reasonText.isEmpty()) { binaryData.writeCharSequence(reasonText, CharsetUtil.UTF_8); } binaryData.readerIndex(0); return binaryData; }
@Override public final void encodeQuestion(DnsQuestion question, ByteBuf out) throws Exception { encodeName(question.name(), out); out.writeShort(question.type().intValue()); out.writeShort(question.dnsClass()); }
private static void writeString(ByteBufAllocator allocator, byte type, String content, List<Object> out) { ByteBuf buf = allocator.ioBuffer(RedisConstants.TYPE_LENGTH + ByteBufUtil.utf8MaxBytes(content) + RedisConstants.EOL_LENGTH); buf.writeByte(type); ByteBufUtil.writeUtf8(buf, content); buf.writeShort(RedisConstants.EOL_SHORT); out.add(buf); }
private void encodeRecord0(DnsRecord record, ByteBuf out) throws Exception { encodeName(record.name(), out); out.writeShort(record.type().intValue()); out.writeShort(record.dnsClass()); out.writeInt((int) record.timeToLive()); }
private void writeIntegerMessage(ByteBufAllocator allocator, IntegerRedisMessage msg, List<Object> out) { ByteBuf buf = allocator.ioBuffer(RedisConstants.TYPE_LENGTH + RedisConstants.LONG_MAX_LENGTH + RedisConstants.EOL_LENGTH); buf.writeByte(RedisMessageType.INTEGER.value()); buf.writeBytes(numberToBytes(msg.value())); buf.writeShort(RedisConstants.EOL_SHORT); out.add(buf); }
private void encodeRawRecord(DnsRawRecord record, ByteBuf out) throws Exception { encodeRecord0(record, out); ByteBuf content = record.content(); int contentLen = content.readableBytes(); out.writeShort(contentLen); out.writeBytes(content, content.readerIndex(), contentLen); }
@Override protected void encodeHeader(ByteBuf buf, BinaryMemcacheRequest msg) { buf.writeByte(msg.magic()); buf.writeByte(msg.opcode()); buf.writeShort(msg.keyLength()); buf.writeByte(msg.extrasLength()); buf.writeByte(msg.dataType()); buf.writeShort(msg.reserved()); buf.writeInt(msg.totalBodyLength()); buf.writeInt(msg.opaque()); buf.writeLong(msg.cas()); }
@Override protected void encodeHeader(ByteBuf buf, BinaryMemcacheResponse msg) { buf.writeByte(msg.magic()); buf.writeByte(msg.opcode()); buf.writeShort(msg.keyLength()); buf.writeByte(msg.extrasLength()); buf.writeByte(msg.dataType()); buf.writeShort(msg.status()); buf.writeInt(msg.totalBodyLength()); buf.writeInt(msg.opaque()); buf.writeLong(msg.cas()); }
@Override protected void encode(ChannelHandlerContext ctx, Socks4CommandResponse msg, ByteBuf out) throws Exception { out.writeByte(0); out.writeByte(msg.status().byteValue()); out.writeShort(msg.dstPort()); out.writeBytes(msg.dstAddr() == null? IPv4_HOSTNAME_ZEROED : NetUtil.createByteArrayFromIpAddressString(msg.dstAddr())); } }
private void encodeCommandRequest(Socks5CommandRequest msg, ByteBuf out) throws Exception { out.writeByte(msg.version().byteValue()); out.writeByte(msg.type().byteValue()); out.writeByte(0x00); final Socks5AddressType dstAddrType = msg.dstAddrType(); out.writeByte(dstAddrType.byteValue()); addressEncoder.encodeAddress(dstAddrType, msg.dstAddr(), out); out.writeShort(msg.dstPort()); } }
private void encodeCommandResponse(Socks5CommandResponse msg, ByteBuf out) throws Exception { out.writeByte(msg.version().byteValue()); out.writeByte(msg.status().byteValue()); out.writeByte(0x00); final Socks5AddressType bndAddrType = msg.bndAddrType(); out.writeByte(bndAddrType.byteValue()); addressEncoder.encodeAddress(bndAddrType, msg.bndAddr(), out); out.writeShort(msg.bndPort()); } }