List of usage examples for io.netty.buffer ByteBuf readByte
public abstract byte readByte();
From source file:io.crate.protocols.postgres.types.CharType.java
License:Apache License
@Override public Object readBinaryValue(ByteBuf buffer, int valueLength) { assert valueLength == 1 : "char must have 1 byte"; return buffer.readByte(); }
From source file:io.datty.msgpack.core.AbstractMessageReader.java
License:Apache License
public byte readByte(ByteBuf buffer) { return buffer.readByte(); }
From source file:io.datty.msgpack.core.AbstractMessageReader.java
License:Apache License
public short readUnsignedByte(ByteBuf buffer) { return (short) (buffer.readByte() & 0xFF); }
From source file:io.github.stormcloud_dev.stormcloud.seralization.RORObjectDecoder.java
License:Apache License
private Object readNextObject(ByteBuf buf) { if (buf.readableBytes() < 12) { return null; }/*from w ww .ja v a 2 s . c o m*/ byte[] header = new byte[8]; buf.readBytes(8).readBytes(header); //Handshake header if (Arrays.equals(header, new byte[] { -66, -70, -2, -54, 11, -80, -83, -34 })) { if (buf.readableBytes() >= 8) { buf.readBytes(8); //We read the rest of the handshake packet //Contains the length (inclusive the header) and 2 unknown numbers return new HandshakeFrame(); } else { return null; } } int length = buf.readByte(); buf.readBytes(3); byte id = buf.readByte(); if (id != 16) { int readerIndex = buf.readerIndex(), writerIndex = buf.writerIndex(); byte[] bytes = new byte[buf.readableBytes()]; buf.readBytes(buf.readableBytes()).readBytes(bytes); buf.setIndex(readerIndex, writerIndex); // Print packets - debugging purposes //System.out.println("ID: " + id + " - " + Arrays.toString(bytes)); } switch (id) { case 0: //if (length < 39) return null; return new PositionInfoServerBoundFrame(buf.readDouble(), buf.readDouble(), buf.readByte(), buf.readByte(), buf.readByte(), buf.readByte(), buf.readByte(), buf.readByte()); case 1: return new SetReadyServerBoundFrame(buf.readByte()); case 2: return new SetPlayerServerBoundFrame(buf.readDouble(), buf.readDouble(), readString(buf)); case 3: return new AddPlayerServerBoundFrame(buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readInt(), buf.readInt(), readString(buf)); case 4: return new ChatPlayerServerBoundFrame(readString(buf)); case 5: return new UpdatePlayerServerBoundFrame(buf.readInt(), buf.readDouble(), buf.readDouble(), readString(buf)); case 6: return new KeyPlayerServerBoundFrame(buf.readShort(), buf.readShort(), buf.readByte(), buf.readByte(), buf.readByte(), buf.readByte(), buf.readShort(), buf.readByte()); case 7: return new HealPlayerServerBoundFrame(buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readDouble()); case 8: return new NPCHPServerBoundFrame(buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readShort(), buf.readShort(), buf.readShort()); case 9: return new MDeadServerBoundFrame(); case 10: return new NPCTargetServerBoundFrame(buf.readDouble(), buf.readDouble(), buf.readInt(), buf.readShort(), buf.readByte()); case 11: return new KeyMonsterServerBoundFrame(buf.readDouble(), buf.readDouble(), buf.readByte(), buf.readByte(), buf.readByte(), buf.readByte(), buf.readShort()); case 12: return new CreateObjectServerBoundFrame(buf.readDouble(), buf.readDouble(), buf.readDouble()); case 13: return new CreateLevelObjectServerBoundFrame(buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readInt()); case 14: return new SyncAlarmServerBoundFrame(buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readInt()); case 15: return new SpawnClassicServerBoundFrame(buf.readShort(), buf.readDouble(), buf.readDouble(), buf.readByte(), buf.readShort(), buf.readShort(), buf.readShort()); case 16: return new LagPlayerServerBoundFrame(readString(buf)); case 17: return new DisPlayerServerBoundFrame(); case 18: return new TransportServerBoundFrame(buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readByte()); case 19: return new ActivateObjectServerBoundFrame(buf.readDouble(), buf.readDouble(), buf.readShort(), buf.readShort(), buf.readByte(), buf.readByte()); case 20: return new SpawnItemServerBoundFrame(buf.readDouble(), buf.readDouble(), buf.readInt()); case 21: return new SyncVarServerBoundFrame(buf.readDouble()); case 22: return new SpawnBossServerBoundFrame(buf.readDouble(), buf.readDouble(), buf.readByte(), buf.readDouble()); case 23: return new SpawnClassicBossServerBoundFrame(buf.readDouble(), buf.readDouble(), buf.readInt(), buf.readInt(), buf.readDouble(), buf.readByte(), buf.readShort(), buf.readShort(), buf.readShort(), buf.readDouble()); case 24: return new LevelUpServerBoundFrame(); case 25: return new ItemPickupServerBoundFrame(buf.readInt(), buf.readByte()); case 26: return new ChatSystemServerBoundFrame(buf.readByte(), readString(buf)); case 27: return new TestServerBoundFrame(); case 28: return new ItemSwapServerBoundFrame(); case 29: return readItemProcFrame(buf); case 30: return new ShrineProcServerBoundFrame(buf.readByte()); case 31: return new SpawnDroneServerBoundFrame(buf.readShort(), buf.readShort(), buf.readShort(), buf.readShort(), buf.readShort(), buf.readShort(), buf.readShort()); case 32: return new SetPriceServerBoundFrame(buf.readShort(), buf.readShort()); case 33: return new CreateChestServerBoundFrame(); case 34: return new UpdateBuffsServerBoundFrame(buf.readDouble(), buf.readShort(), buf.readShort()); case 35: return new SpawnImpmServerboundFrame(buf.readShort(), buf.readShort(), buf.readShort(), buf.readByte(), buf.readByte()); case 36: return new UpdateChest4ServerBoundFrame(buf.readShort()); case 37: return new EliteTeleportServerBoundFrame(buf.readShort(), buf.readShort()); case 38: return new UpdateHpServerBoundFrame(buf.readShort()); case 39: return new UpdateDiffServerBoundFrame(buf.readByte(), buf.readByte(), buf.readByte(), buf.readByte(), buf.readByte(), buf.readByte(), buf.readByte(), buf.readByte(), buf.readByte(), buf.readByte(), buf.readByte(), buf.readByte()); case 40: return new SpawnGhostServerBoundFrame(buf.readShort(), buf.readShort(), buf.readFloat(), buf.readFloat()); case 41: return new StopTimeServerBoundFrame(buf.readShort()); case 42: return new LandLizardServerBoundFrame(buf.readShort(), buf.readShort()); case 43: return new DestroyObjectServerBoundFrame(); case 44: return new CreateSlimeServerBoundFrame(buf.readShort(), buf.readShort(), buf.readFloat(), buf.readShort(), buf.readShort(), buf.readShort(), buf.readByte(), buf.readShort(), buf.readDouble()); case 45: return new CrewChoiceServerBoundFrame(buf.readShort()); case 46: return new CreateItemServerBoundFrame(buf.readShort(), buf.readShort(), buf.readShort()); case 47: return new ActivateSwitchServerBoundFrame(buf.readShort(), buf.readShort()); default: return null; } }
From source file:io.github.stormcloud_dev.stormcloud.seralization.RORObjectDecoder.java
License:Apache License
private Object readItemProcFrame(ByteBuf buf) { short id = buf.readShort(); switch (id) { case 1://from ww w.jav a 2s . co m return new PauldronItemProcFrame(buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readShort(), readString(buf)); case 3: return new DebuffsItemProcFrame(buf.readDouble(), buf.readShort(), buf.readShort(), buf.readShort()); case 4: return new MortarItemProcFrame(buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readShort()); case 5: return new ScopeItemProcFrame(buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readShort()); case 6: return new PlasmaChainItemProcFrame(buf.readShort(), buf.readDouble(), buf.readShort(), buf.readShort()); case 8: return new BleedItemProcFrame(buf.readDouble(), buf.readShort(), buf.readShort()); case 9: return new LightningItemProcFrame(buf.readDouble(), buf.readDouble(), buf.readShort(), readString(buf)); case 10: return new MissileItemProcFrame(buf.readDouble(), buf.readDouble(), buf.readShort(), buf.readShort(), buf.readShort()); case 11: return new MineItemProcFrame(buf.readShort(), buf.readShort(), buf.readShort(), buf.readShort(), buf.readShort()); case 12: return new EnemyMissileItemProcFrame(buf.readDouble(), buf.readDouble(), buf.readShort(), buf.readShort(), buf.readShort()); case 13: return new StickyItemProcFrame(buf.readShort(), buf.readShort(), buf.readShort()); case 14: return new MeteorItemProcFrame(buf.readDouble(), buf.readDouble()); case 15: return new GoldItemProcFrame(buf.readDouble(), buf.readDouble(), buf.readDouble()); case 16: return new BottleItemProcFrame(buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readByte()); case 17: return new HornItemProcFrame(buf.readShort(), buf.readDouble(), buf.readDouble(), buf.readByte(), buf.readDouble()); default: return null; } }
From source file:io.github.vastframework.codecs.primitives.DecodingPrimitiveSupport.java
License:Apache License
default byte decodeByte(ByteBuf buffer) { return buffer.readByte(); }
From source file:io.grpc.alts.internal.BufUnwrapperTest.java
License:Apache License
@Test public void writableNioBuffers_worksWithNormal() { ByteBuf buf = alloc.buffer(1); try (BufUnwrapper unwrapper = new BufUnwrapper()) { ByteBuffer[] internalBufs = unwrapper.writableNioBuffers(buf); Truth.assertThat(internalBufs).hasLength(1); internalBufs[0].put((byte) 'a'); buf.writerIndex(1);//from www.j a v a 2s.c om assertEquals('a', buf.readByte()); } finally { buf.release(); } }
From source file:io.grpc.alts.internal.FakeChannelCrypter.java
License:Apache License
@Override public void decrypt(ByteBuf out, ByteBuf tag, List<ByteBuf> ciphertext) throws GeneralSecurityException { checkState(!destroyCalled);//from w w w . j a v a 2 s . c om for (ByteBuf buf : ciphertext) { out.writeBytes(buf); } while (tag.isReadable()) { if (tag.readByte() != TAG_BYTE) { throw new AEADBadTagException("Tag mismatch!"); } } }
From source file:io.grpc.netty.GrpcHpackDecoder.java
License:Apache License
/** * Decode the header block into header fields. * <p>/*from w ww .java 2 s. c o m*/ * This method assumes the entire header block is contained in {@code in}. */ public void decode(int streamId, ByteBuf in, Http2Headers headers) throws Http2Exception { int index = 0; long headersLength = 0; int nameLength = 0; int valueLength = 0; byte state = READ_HEADER_REPRESENTATION; boolean huffmanEncoded = false; CharSequence name = null; IndexType indexType = IndexType.NONE; while (in.isReadable()) { switch (state) { case READ_HEADER_REPRESENTATION: byte b = in.readByte(); if (maxDynamicTableSizeChangeRequired && (b & 0xE0) != 0x20) { // HpackEncoder MUST signal maximum dynamic table size change throw MAX_DYNAMIC_TABLE_SIZE_CHANGE_REQUIRED; } if (b < 0) { // Indexed Header Field index = b & 0x7F; switch (index) { case 0: throw DECODE_ILLEGAL_INDEX_VALUE; case 0x7F: state = READ_INDEXED_HEADER; break; default: headersLength = indexHeader(streamId, index, headers, headersLength); } } else if ((b & 0x40) == 0x40) { // Literal Header Field with Incremental Indexing indexType = IndexType.INCREMENTAL; index = b & 0x3F; switch (index) { case 0: state = READ_LITERAL_HEADER_NAME_LENGTH_PREFIX; break; case 0x3F: state = READ_INDEXED_HEADER_NAME; break; default: // Index was stored as the prefix name = readName(index); state = READ_LITERAL_HEADER_VALUE_LENGTH_PREFIX; } } else if ((b & 0x20) == 0x20) { // Dynamic Table Size Update index = b & 0x1F; if (index == 0x1F) { state = READ_MAX_DYNAMIC_TABLE_SIZE; } else { setDynamicTableSize(index); state = READ_HEADER_REPRESENTATION; } } else { // Literal Header Field without Indexing / never Indexed indexType = ((b & 0x10) == 0x10) ? IndexType.NEVER : IndexType.NONE; index = b & 0x0F; switch (index) { case 0: state = READ_LITERAL_HEADER_NAME_LENGTH_PREFIX; break; case 0x0F: state = READ_INDEXED_HEADER_NAME; break; default: // Index was stored as the prefix name = readName(index); state = READ_LITERAL_HEADER_VALUE_LENGTH_PREFIX; } } break; case READ_MAX_DYNAMIC_TABLE_SIZE: setDynamicTableSize(decodeULE128(in, (long) index)); state = READ_HEADER_REPRESENTATION; break; case READ_INDEXED_HEADER: headersLength = indexHeader(streamId, decodeULE128(in, index), headers, headersLength); state = READ_HEADER_REPRESENTATION; break; case READ_INDEXED_HEADER_NAME: // Header Name matches an entry in the Header Table name = readName(decodeULE128(in, index)); state = READ_LITERAL_HEADER_VALUE_LENGTH_PREFIX; break; case READ_LITERAL_HEADER_NAME_LENGTH_PREFIX: b = in.readByte(); huffmanEncoded = (b & 0x80) == 0x80; index = b & 0x7F; if (index == 0x7f) { state = READ_LITERAL_HEADER_NAME_LENGTH; } else { if (index > maxHeaderListSizeGoAway - headersLength) { headerListSizeExceeded(maxHeaderListSizeGoAway); } nameLength = index; state = READ_LITERAL_HEADER_NAME; } break; case READ_LITERAL_HEADER_NAME_LENGTH: // Header Name is a Literal String nameLength = decodeULE128(in, index); if (nameLength > maxHeaderListSizeGoAway - headersLength) { headerListSizeExceeded(maxHeaderListSizeGoAway); } state = READ_LITERAL_HEADER_NAME; break; case READ_LITERAL_HEADER_NAME: // Wait until entire name is readable if (in.readableBytes() < nameLength) { throw notEnoughDataException(in); } name = readStringLiteral(in, nameLength, huffmanEncoded); state = READ_LITERAL_HEADER_VALUE_LENGTH_PREFIX; break; case READ_LITERAL_HEADER_VALUE_LENGTH_PREFIX: b = in.readByte(); huffmanEncoded = (b & 0x80) == 0x80; index = b & 0x7F; switch (index) { case 0x7f: state = READ_LITERAL_HEADER_VALUE_LENGTH; break; case 0: headersLength = insertHeader(streamId, headers, name, EMPTY_STRING, indexType, headersLength); state = READ_HEADER_REPRESENTATION; break; default: // Check new header size against max header size if ((long) index + nameLength > maxHeaderListSizeGoAway - headersLength) { headerListSizeExceeded(maxHeaderListSizeGoAway); } valueLength = index; state = READ_LITERAL_HEADER_VALUE; } break; case READ_LITERAL_HEADER_VALUE_LENGTH: // Header Value is a Literal String valueLength = decodeULE128(in, index); // Check new header size against max header size if ((long) valueLength + nameLength > maxHeaderListSizeGoAway - headersLength) { headerListSizeExceeded(maxHeaderListSizeGoAway); } state = READ_LITERAL_HEADER_VALUE; break; case READ_LITERAL_HEADER_VALUE: // Wait until entire value is readable if (in.readableBytes() < valueLength) { throw notEnoughDataException(in); } CharSequence value = readStringLiteral(in, valueLength, huffmanEncoded); headersLength = insertHeader(streamId, headers, name, value, indexType, headersLength); state = READ_HEADER_REPRESENTATION; break; default: throw new Error("should not reach here state: " + state); } } // we have read all of our headers, and not exceeded maxHeaderListSizeGoAway see if we have // exceeded our actual maxHeaderListSize. This must be done here to prevent dynamic table // corruption if (headersLength > maxHeaderListSize) { headerListSizeExceeded(streamId, maxHeaderListSize, true); } }
From source file:io.hekate.cluster.seed.multicast.MulticastSeedNodeProvider.java
License:Apache License
private SimpleChannelInboundHandler<DatagramPacket> createSenderHandler(SeedNode thisNode) { return new SimpleChannelInboundHandler<DatagramPacket>() { @Override//from w w w .ja va 2 s. c om public void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception { ByteBuf buf = msg.content(); if (buf.readableBytes() > 4 && buf.readInt() == Utils.MAGIC_BYTES) { MessageTYpe msgType = MessageTYpe.values()[buf.readByte()]; if (msgType == MessageTYpe.SEED_NODE_INFO) { String cluster = decodeUtf(buf); InetSocketAddress address = decodeAddress(buf); SeedNode otherNode = new SeedNode(address, cluster); if (!thisNode.equals(otherNode)) { if (DEBUG) { log.debug("Received seed node info message [node={}]", otherNode); } boolean discovered = false; synchronized (mux) { if (isRegistered()) { if (!seedNodes.contains(otherNode)) { discovered = true; seedNodes.add(otherNode); } } } if (discovered) { log.info("Seed node discovered [address={}]", otherNode.address()); } } } } } }; }