List of usage examples for io.netty.buffer ByteBuf writeByte
public abstract ByteBuf writeByte(int value);
From source file:com.twitter.http2.HttpFrameEncoderTest.java
License:Apache License
@Test public void testContinuedHttpPushPromiseFrame() throws Exception { int streamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01; int promisedStreamId = RANDOM.nextInt() & 0x7FFFFFFF | 0x01; ByteBuf headerBlock = Unpooled.buffer(2 * HTTP_MAX_LENGTH); for (int i = 0; i < 2 * HTTP_MAX_LENGTH; i++) { headerBlock.writeByte(RANDOM.nextInt()); }/* w w w .jav a 2s.c om*/ ByteBuf frame = releaseLater( ENCODER.encodePushPromiseFrame(streamId, promisedStreamId, headerBlock.duplicate())); assertPushPromiseFrame(frame, streamId, promisedStreamId, headerBlock); }
From source file:com.uber.tchannel.codecs.CodecUtils.java
License:Open Source License
public static void encodeSmallString(String value, ByteBuf buffer) { byte[] raw = value.getBytes(); buffer.writeByte(raw.length); buffer.writeBytes(raw);// w w w. j a v a 2s .c o m }
From source file:com.uber.tchannel.codecs.CodecUtils.java
License:Open Source License
public static void encodeSmallHeaders(Map<String, String> headers, ByteBuf buffer) { buffer.writeByte(headers.size()); for (Map.Entry<String, String> header : headers.entrySet()) { CodecUtils.encodeSmallString(header.getKey(), buffer); CodecUtils.encodeSmallString(header.getValue(), buffer); }//from ww w .ja v a 2s. c o m }
From source file:com.uber.tchannel.codecs.TFrameCodec.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, TFrame frame, ByteBuf out) throws Exception { // size:2//from w w w. j a v a 2s. c o m out.writeShort(frame.size + TFrame.FRAME_HEADER_LENGTH); // type:1 out.writeByte(frame.type); // reserved:1 out.writeZero(1); // id:4 out.writeInt((int) frame.id); // reserved:8 out.writeZero(8); // payload:16+ out.writeBytes(frame.payload); }
From source file:com.uber.tchannel.codecs.TFrameCodec.java
License:Open Source License
public static ByteBuf encode(ByteBufAllocator allocator, TFrame frame) { ByteBuf buffer = allocator.buffer(TFrame.FRAME_HEADER_LENGTH, TFrame.FRAME_HEADER_LENGTH); // size:2//from w w w. j a v a2 s .c o m buffer.writeShort(frame.size + TFrame.FRAME_HEADER_LENGTH); // type:1 buffer.writeByte(frame.type); // reserved:1 buffer.writeZero(1); // id:4 buffer.writeInt((int) frame.id); // reserved:8 buffer.writeZero(8); // TODO: refactor if (frame.payload instanceof CompositeByteBuf) { CompositeByteBuf cbf = (CompositeByteBuf) frame.payload; cbf.addComponent(0, buffer); cbf.writerIndex(cbf.writerIndex() + TFrame.FRAME_HEADER_LENGTH); return cbf; } return Unpooled.wrappedBuffer(buffer, frame.payload); }
From source file:com.uber.tchannel.frames.CallRequestContinueFrame.java
License:Open Source License
@Override public ByteBuf encodeHeader(ByteBufAllocator allocator) { ByteBuf buffer = allocator.buffer(2, 6); // flags:1/*from w ww .j av a2 s . co m*/ buffer.writeByte(getFlags()); // csumtype:1 buffer.writeByte(getChecksumType().byteValue()); // checksum -> (csum:4){0,1} CodecUtils.encodeChecksum(getChecksum(), getChecksumType(), buffer); return buffer; }
From source file:com.uber.tchannel.frames.CallRequestFrame.java
License:Open Source License
@Override public ByteBuf encodeHeader(ByteBufAllocator allocator) { ByteBuf buffer = allocator.buffer(1024); // flags:1/*from w w w .j av a 2 s .co m*/ buffer.writeByte(getFlags()); // ttl:4 buffer.writeInt((int) getTTL()); // tracing:25 CodecUtils.encodeTrace(getTracing(), buffer); // service~1 CodecUtils.encodeSmallString(getService(), buffer); // nh:1 (hk~1, hv~1){nh} CodecUtils.encodeSmallHeaders(getHeaders(), buffer); // csumtype:1 buffer.writeByte(getChecksumType().byteValue()); // (csum:4){0,1} CodecUtils.encodeChecksum(getChecksum(), getChecksumType(), buffer); return buffer; }
From source file:com.uber.tchannel.frames.CallResponseContinueFrame.java
License:Open Source License
@Override public ByteBuf encodeHeader(ByteBufAllocator allocator) { ByteBuf buffer = allocator.buffer(2, 6); // flags:1/*from w w w .j av a2 s . c o m*/ buffer.writeByte(getFlags()); // csumtype:1 buffer.writeByte(getChecksumType().byteValue()); // checksum -> (csum:4){0,1} CodecUtils.encodeChecksum(getChecksum(), getChecksumType(), buffer); return buffer; }
From source file:com.uber.tchannel.frames.CallResponseFrame.java
License:Open Source License
@Override public ByteBuf encodeHeader(ByteBufAllocator allocator) { ByteBuf buffer = allocator.buffer(1024); // flags:1//from w w w.j ava 2 s.c om buffer.writeByte(getFlags()); // code:1 buffer.writeByte(getResponseCode().byteValue()); // tracing:25 CodecUtils.encodeTrace(getTracing(), buffer); // headers -> nh:1 (hk~1 hv~1){nh} CodecUtils.encodeSmallHeaders(getHeaders(), buffer); // csumtype:1 buffer.writeByte(getChecksumType().byteValue()); // (csum:4){0,1} CodecUtils.encodeChecksum(getChecksum(), getChecksumType(), buffer); return buffer; }
From source file:com.uber.tchannel.frames.ErrorFrame.java
License:Open Source License
@Override public ByteBuf encodeHeader(ByteBufAllocator allocator) { ByteBuf buffer = allocator.buffer(28); // code:1//from w ww .j a v a2 s. c om buffer.writeByte(getErrorType().byteValue()); // tracing:25 CodecUtils.encodeTrace(getTracing(), buffer); // message~2 CodecUtils.encodeString(getMessage(), buffer); return buffer; }