List of usage examples for io.netty.buffer ByteBuf getByte
public abstract byte getByte(int index);
From source file:com.twitter.http2.HttpCodecUtil.java
License:Apache License
/** * Reads a big-endian unsigned medium integer from the buffer. *///from w w w . j av a 2s . co m static int getUnsignedMedium(ByteBuf buf, int offset) { return (buf.getByte(offset) & 0xFF) << 16 | (buf.getByte(offset + 1) & 0xFF) << 8 | buf.getByte(offset + 2) & 0xFF; }
From source file:com.twitter.http2.HttpCodecUtil.java
License:Apache License
/** * Reads a big-endian (31-bit) integer from the buffer. *//* w w w . ja v a 2 s. c o m*/ static int getUnsignedInt(ByteBuf buf, int offset) { return (buf.getByte(offset) & 0x7F) << 24 | (buf.getByte(offset + 1) & 0xFF) << 16 | (buf.getByte(offset + 2) & 0xFF) << 8 | buf.getByte(offset + 3) & 0xFF; }
From source file:com.twitter.http2.HttpCodecUtil.java
License:Apache License
/** * Reads a big-endian signed integer from the buffer. *//*from w ww.jav a 2 s .co m*/ static int getSignedInt(ByteBuf buf, int offset) { return (buf.getByte(offset) & 0xFF) << 24 | (buf.getByte(offset + 1) & 0xFF) << 16 | (buf.getByte(offset + 2) & 0xFF) << 8 | buf.getByte(offset + 3) & 0xFF; }
From source file:com.twitter.http2.HttpCodecUtil.java
License:Apache License
/** * Reads a big-endian signed long from the buffer. *//* w ww . j a v a 2 s . c o m*/ static long getSignedLong(ByteBuf buf, int offset) { return ((long) buf.getByte(offset) & 0xFF) << 56 | ((long) buf.getByte(offset + 1) & 0xFF) << 48 | ((long) buf.getByte(offset + 2) & 0xFF) << 40 | ((long) buf.getByte(offset + 3) & 0xFF) << 32 | ((long) buf.getByte(offset + 4) & 0xFF) << 24 | ((long) buf.getByte(offset + 5) & 0xFF) << 16 | ((long) buf.getByte(offset + 6) & 0xFF) << 8 | (long) buf.getByte(offset + 7) & 0xFF; }
From source file:com.twitter.http2.HttpFrameDecoder.java
License:Apache License
/** * Reads the HTTP/2 Frame Header and sets the length, type, flags, and streamId member variables. * * @param buffer input buffer containing the entire 9-octet header *///from w ww. j av a2s . c o m private void readFrameHeader(ByteBuf buffer) { int frameOffset = buffer.readerIndex(); length = getUnsignedMedium(buffer, frameOffset); type = buffer.getUnsignedByte(frameOffset + 3); flags = buffer.getByte(frameOffset + 4); streamId = getUnsignedInt(buffer, frameOffset + 5); buffer.skipBytes(HTTP_FRAME_HEADER_SIZE); }
From source file:com.twitter.http2.HttpFrameEncoderTest.java
License:Apache License
private static void assertDataFrame(ByteBuf frame, int streamId, boolean last, ByteBuf data) { byte type = 0x00; byte flags = 0x00; if (last) {//from w w w .j a v a 2 s . c o m flags |= 0x01; } int length = assertFrameHeader(frame, type, flags, streamId); assertEquals(data.readableBytes(), length); for (int i = 0; i < length; i++) { assertEquals(data.getByte(i), frame.readByte()); } assertFalse(frame.isReadable()); }
From source file:com.uber.tchannel.messages.RequestFormatTest.java
License:Open Source License
@Test public void testThriftHeader() throws Exception { ThriftRequest<Example> request = new ThriftRequest.Builder<Example>("keyvalue-service", "KeyValue::setValue").build(); ByteBuf arg2 = request.getArg2(); assertEquals(2, arg2.readableBytes()); assertEquals(0, arg2.getByte(0)); assertEquals(0, arg2.getByte(1));/* w w w .j ava 2s . c o m*/ request.release(); }
From source file:com.uber.tchannel.messages.RequestFormatTest.java
License:Open Source License
@Test public void testJsonHeader() throws Exception { JsonRequest<Example> request = new JsonRequest.Builder<Example>("keyvalue-service", "KeyValue::setValue") .build();/* w ww . j ava 2 s .com*/ ByteBuf arg2 = request.getArg2(); assertEquals(2, arg2.readableBytes()); // "{}" assertEquals(0x7b, arg2.getByte(0)); assertEquals(0x7d, arg2.getByte(1)); request.release(); }
From source file:com.whizzosoftware.foscam.camera.protocol.OrderTest.java
License:Open Source License
@Test public void testToBytes() { Order order = new Order((byte) 1, "TEST".getBytes()); ByteBuf b = order.toByteBuf(); assertEquals(27, b.readableBytes()); // assert the "camera operate protocol" header assertEquals('M', b.getByte(0)); assertEquals('O', b.getByte(1)); assertEquals('_', b.getByte(2)); assertEquals('I', b.getByte(3)); // assert all the reserve bytes assertEquals((byte) 1, b.getByte(4)); for (int i = 5; i < 15; i++) { assertEquals(0, b.getByte(i));//from www .j a v a 2s. co m } // assert the text length assertEquals(4, b.getByte(15)); assertEquals(0, b.getByte(16)); assertEquals(0, b.getByte(17)); assertEquals(0, b.getByte(18)); // assert more reserve bytes for (int i = 19; i < 23; i++) { assertEquals(0, b.getByte(i)); } assertEquals('T', b.getByte(23)); assertEquals('E', b.getByte(24)); assertEquals('S', b.getByte(25)); assertEquals('T', b.getByte(26)); }
From source file:com.whizzosoftware.foscam.camera.protocol.OrderTest.java
License:Open Source License
@Test public void testToBytesLong() { // build 1024 length byte array byte b[] = new byte[65535]; for (int i = 0; i < 65535; i++) { b[i] = '*'; }// ww w .j av a 2s .c o m Order order = new Order((byte) 1, b); ByteBuf buf = order.toByteBuf(); // assert the "camera operate protocol" header assertEquals('M', buf.getByte(0)); assertEquals('O', buf.getByte(1)); assertEquals('_', buf.getByte(2)); assertEquals('I', buf.getByte(3)); // assert all the reserve bytes assertEquals((byte) 1, buf.getByte(4)); for (int i = 5; i < 15; i++) { assertEquals(0, buf.getByte(i)); } // assert the text length assertEquals((byte) 0xFF, buf.getByte(15)); assertEquals((byte) 0xFF, buf.getByte(16)); assertEquals((byte) 0x00, buf.getByte(17)); assertEquals((byte) 0x00, buf.getByte(18)); // assert more reserve bytes for (int i = 19; i < 23; i++) { assertEquals(0, buf.getByte(i)); } for (int i = 23; i < 65535 + 23; i++) { assertEquals('*', buf.getByte(i)); } }