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); }
void encode(ByteBuf buf) { if (bytes == null) { ByteBufUtil.copy(codeAsText, buf); buf.writeByte(SP); buf.writeCharSequence(reasonPhrase, CharsetUtil.US_ASCII); } else { buf.writeBytes(bytes); } } }
private static void writeUnencodedChunk(ByteBuf in, ByteBuf out, int dataLength) { out.writeByte(1); writeChunkLength(out, dataLength + 4); calculateAndWriteChecksum(in, out); out.writeBytes(in, dataLength); }
private static void encodeCopyWithOffset(ByteBuf out, int offset, int length) { if (length < 12 && offset < 2048) { out.writeByte(COPY_1_BYTE_OFFSET | length - 4 << 2 | offset >> 8 << 5); out.writeByte(offset & 0x0ff); } else { out.writeByte(COPY_2_BYTE_OFFSET | length - 1 << 2); out.writeByte(offset & 0x0ff); out.writeByte(offset >> 8 & 0x0ff); } }
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); }
@Override public void write(int b) throws IOException { buffer.writeByte(b); }
public ByteBuf encodeDataFrame(ByteBufAllocator allocator, int streamId, boolean last, ByteBuf data) { byte flags = last ? SPDY_DATA_FLAG_FIN : 0; int length = data.readableBytes(); ByteBuf frame = allocator.ioBuffer(SPDY_HEADER_SIZE + length).order(ByteOrder.BIG_ENDIAN); frame.writeInt(streamId & 0x7FFFFFFF); frame.writeByte(flags); frame.writeMedium(length); frame.writeBytes(data, data.readerIndex(), length); return frame; }
@Override public ByteBuf writeByte(int value) { buf.writeByte(value); return this; }
private void writeBulkStringHeader(ByteBufAllocator allocator, BulkStringHeaderRedisMessage msg, List<Object> out) { final ByteBuf buf = allocator.ioBuffer(RedisConstants.TYPE_LENGTH + (msg.isNull() ? RedisConstants.NULL_LENGTH : RedisConstants.LONG_MAX_LENGTH + RedisConstants.EOL_LENGTH)); buf.writeByte(RedisMessageType.BULK_STRING.value()); if (msg.isNull()) { buf.writeShort(RedisConstants.NULL_SHORT); } else { buf.writeBytes(numberToBytes(msg.bulkStringLength())); buf.writeShort(RedisConstants.EOL_SHORT); } out.add(buf); }
private static void encodePasswordAuthRequest(Socks5PasswordAuthRequest msg, ByteBuf out) { out.writeByte(0x01); final String username = msg.username(); out.writeByte(username.length()); ByteBufUtil.writeAscii(out, username); final String password = msg.password(); out.writeByte(password.length()); ByteBufUtil.writeAscii(out, password); }
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()); } }
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 writeControlFrameHeader(ByteBuf buffer, int type, byte flags, int length) { buffer.writeShort(version | 0x8000); buffer.writeShort(type); buffer.writeByte(flags); buffer.writeMedium(length); }
@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 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 encodeInitialLine(ByteBuf buf, HttpResponse response) throws Exception { response.protocolVersion().encode(buf); buf.writeByte(SP); response.status().encode(buf); ByteBufUtil.writeShortBE(buf, CRLF_SHORT); }