Example usage for io.netty.buffer ByteBuf readShort

List of usage examples for io.netty.buffer ByteBuf readShort

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf readShort.

Prototype

public abstract short readShort();

Source Link

Document

Gets a 16-bit short integer at the current readerIndex and increases the readerIndex by 2 in this buffer.

Usage

From source file:io.datty.msgpack.core.AbstractMessageReader.java

License:Apache License

public int readUnsignedShort(ByteBuf buffer) {
    return buffer.readShort() & 0xFFFF;
}

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;
    }// ww  w  . j  av  a 2s  .co 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 w  ww .  j av  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 short decodeShort(ByteBuf buffer) {
    return buffer.readShort();
}

From source file:io.hydramq.core.type.converters.MessagePropertiesConverter.java

License:Open Source License

@Override
public MessageProperties read(final ConversionContext context, final ByteBuf buffer) {
    MessageProperties properties = new MessageProperties();
    int flags = buffer.readInt();
    if ((flags & HAS_STRING_PROPERTIES) == HAS_STRING_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setString(context.read(String.class, buffer), context.read(String.class, buffer));
        }/*from   w  ww .  ja va  2  s .c  o m*/
    }
    if ((flags & HAS_BOOLEAN_PROPERTIES) == HAS_BOOLEAN_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setBoolean(context.read(String.class, buffer), buffer.readBoolean());
        }
    }
    if ((flags & HAS_INTEGER_PROPERTIES) == HAS_INTEGER_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setInteger(context.read(String.class, buffer), buffer.readInt());
        }
    }
    if ((flags & HAS_LONG_PROPERTIES) == HAS_LONG_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setLong(context.read(String.class, buffer), buffer.readLong());
        }
    }
    if ((flags & HAS_FLOAT_PROPERTIES) == HAS_FLOAT_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setFloat(context.read(String.class, buffer), buffer.readFloat());
        }
    }
    if ((flags & HAS_DOUBLE_PROPERTIES) == HAS_DOUBLE_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setDouble(context.read(String.class, buffer), buffer.readDouble());
        }
    }
    if ((flags & HAS_BYTES_PROPERTIES) == HAS_BYTES_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setBytes(context.read(String.class, buffer), context.read(byte[].class, buffer));
        }
    }
    if ((flags & HAS_SHORT_PROPERTIES) == HAS_SHORT_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setShort(context.read(String.class, buffer), buffer.readShort());
        }
    }
    if ((flags & HAS_BYTE_PROPERTIES) == HAS_BYTE_PROPERTIES) {
        int count = buffer.readInt();
        for (int i = 0; i < count; i++) {
            properties.setByte(context.read(String.class, buffer), buffer.readByte());
        }
    }

    return properties;
}

From source file:io.netlibs.bgp.netty.codec.UpdatePacketDecoder.java

License:Apache License

private ExtendedCommunityPathAttribute decodeExtendedCommunityPathAttribute(final ByteBuf buffer) {
    final ExtendedCommunityPathAttribute attr = new ExtendedCommunityPathAttribute();

    if ((buffer.readableBytes() < 8) || ((buffer.readableBytes() % 8) != 0)) {
        throw new OptionalAttributeErrorException();
    }//from   w w  w.j  a v  a  2 s.c  o m

    while (buffer.isReadable()) {
        AbstractExtendedCommunityInterface extcomm;
        // we need to check whether this is a transitive or non-transitive value
        // and then determine whether we need to red the lower type byte
        byte higherType = buffer.readByte();
        byte higherTypeCompare = (byte) (higherType & ~(1 << 6));
        if (((higherType >> 6) & 1) == 0) {
            // bit 7 is not set in the byte, therefore this is a transitive type
            // clear bit 8, not interested in this value
            TransitiveExtendedCommunityType transCommType = TransitiveExtendedCommunityType
                    .fromCode((byte) (higherType & (~(3 << 6))));

            switch (transCommType) {
            case TWO_OCTET_AS_SPECIFIC:
                TransitiveTwoOctetASSpecificExtCommSubTypes twoOctASNLowerType = TransitiveTwoOctetASSpecificExtCommSubTypes
                        .fromCode(buffer.readByte());
                switch (twoOctASNLowerType) {
                case ROUTE_TARGET:
                    extcomm = new TransitiveTwoByteASNFourByteAdministratorRT((int) buffer.readShort(),
                            (long) buffer.readInt());
                    break;
                default:
                    // all non-RT types are currently unimplemented
                    extcomm = new UnknownTransitiveTwoByteASNSpecificExtendedCommunity(transCommType,
                            twoOctASNLowerType, buffer.readBytes(6).array());
                }
                break;

            case TWO_OCTET_IPv4_ADDRESS_SPECIFIC:

                TransitiveIPv4AddressSpecificExtCommSubTypes ipv4LowerType = TransitiveIPv4AddressSpecificExtCommSubTypes
                        .fromCode(buffer.readByte());

                switch (ipv4LowerType) {
                case ROUTE_TARGET:
                    try {
                        extcomm = new TransitiveIPv4AddressTwoByteAdministratorRT(
                                (Inet4Address) InetAddresses
                                        .fromLittleEndianByteArray(buffer.readBytes(4).array()),
                                (int) buffer.readShort());
                    } catch (UnknownHostException e) {
                        ByteBuf data = Unpooled.buffer();
                        data.getByte(ipv4LowerType.toCode());
                        data.readBytes(buffer.readBytes(6));
                        extcomm = new UnknownTransitiveExtendedCommunity(transCommType, data.array());
                    }
                    break;

                default:

                    // all non-RT types are currently unimplemented
                    extcomm = new UnknownTransitiveIPv4AddressSpecificExtendedCommunity(transCommType,
                            ipv4LowerType, buffer.readBytes(6).array());
                    break;

                }
                break;

            default:
                // by default, just create an unknown type, reading the subsequent
                // 7 bytes (we have already read byte 1)
                extcomm = new UnknownTransitiveExtendedCommunity(transCommType, buffer.readBytes(7).array());
            }
        } else {
            // bit 7 is set, these are non-transitive
            NonTransitiveExtendedCommunityType nonTransCommType = NonTransitiveExtendedCommunityType
                    .fromCode((byte) (higherType & (~(3 << 6))));
            // all non-transitive types are currently unimplemented
            extcomm = new UnknownNonTransitiveExtendedCommunity(nonTransCommType, buffer.readBytes(7).array());
        }
        attr.getMembers().add(extcomm);
    }
    return attr;
}

From source file:io.netlibs.bgp.netty.protocol.open.CapabilityCodec.java

License:Apache License

private static Capability decodeMultiProtocolCapability(final ByteBuf buffer) {
    final MultiProtocolCapability cap = new MultiProtocolCapability();

    assertFixedLength(buffer, BGPv4Constants.BGP_CAPABILITY_LENGTH_MULTIPROTOCOL);

    cap.setAfi(AddressFamily.fromCode(buffer.readShort()));
    buffer.readByte(); // reserved

    int safiCode = Ints.fromBytes((byte) 0, (byte) 0, (byte) 0, buffer.readByte());
    cap.setSafi(SubsequentAddressFamily.fromCode(safiCode));

    return cap;/*from w  w  w  .j  av  a2 s  .c o m*/
}

From source file:io.reactiverse.pgclient.impl.codec.decoder.MessageDecoder.java

License:Apache License

private void decodeRowDescription(ByteBuf in) {
    ColumnDesc[] columns = new ColumnDesc[in.readUnsignedShort()];
    for (int c = 0; c < columns.length; ++c) {
        String fieldName = Util.readCStringUTF8(in);
        int tableOID = in.readInt();
        short columnAttributeNumber = in.readShort();
        int typeOID = in.readInt();
        short typeSize = in.readShort();
        int typeModifier = in.readInt();
        int textOrBinary = in.readUnsignedShort(); // Useless for now
        ColumnDesc column = new ColumnDesc(fieldName, tableOID, columnAttributeNumber,
                DataType.valueOf(typeOID), typeSize, typeModifier, DataFormat.valueOf(textOrBinary));
        columns[c] = column;// w  w w  . ja va2 s.c  om
    }
    RowDescription rowDesc = new RowDescription(columns);
    inflight.peek().handleRowDescription(rowDesc);
}

From source file:it.jnrpe.net.JNRPERequestDecoder.java

License:Apache License

/**
 * Method decode.//from w ww.  j a v  a  2 s  . co  m
 * @param ctx ChannelHandlerContext
 * @param in ByteBuf
 * @param out List<Object>
 * @throws Exception
 */
@Override
protected final void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out)
        throws Exception {

    STAGE stage = state();

    switch (stage) {
    case PACKET_VERSION:
        packetVersion = PacketVersion.fromIntValue(in.readShort());
        checkpoint(STAGE.PACKET_TYPE_CODE);
    case PACKET_TYPE_CODE:
        PacketType type = PacketType.fromIntValue(in.readShort());
        switch (type) {
        case QUERY:
            packet = new JNRPERequest();
            break;
        case RESPONSE:
            packet = new JNRPEResponse();
            break;
        default:
            throw new Exception("Unknown packet type: " + stage);
        }

        packet.setPacketVersion(packetVersion);
        checkpoint(STAGE.CRC);
    case CRC:
        packet.setCRC(in.readInt());
        checkpoint(STAGE.RESULT_CODE);
    case RESULT_CODE:
        packet.setResultCode(in.readShort());
        checkpoint(STAGE.BUFFER);
    case BUFFER:
        byte[] buff = new byte[PACKETBUFFER_LENGTH];
        in.readBytes(buff);
        packet.setBuffer(ztString2String(buff));
        checkpoint(STAGE.DUMMY);
    case DUMMY:
        byte[] dummy = new byte[DUMMYLENGTH];
        packet.setDummy(dummy);
        out.add(packet);
        reset();
        break;
    default:
        throw new Error("Shouldn't reach here.");
    }
}

From source file:mal.carbonization.network.FluidTransportMessageServer.java

License:Open Source License

@Override
public void fromBytes(ByteBuf buf) {
    xpos = buf.readInt();/*  www.  j  av a  2 s.  co  m*/
    ypos = buf.readInt();
    zpos = buf.readInt();

    int fluidID = buf.readShort();
    if (fluidID > 0)
        tank.setFluid(new FluidStack(fluidID, buf.readInt()));
    else
        tank.setFluid(null);
    int capacity = buf.readInt();
    tank.setCapacity(capacity);

    maxcooldown = buf.readInt();
    cooldown = buf.readInt();
    transferAmount = buf.readInt();

    int bsize = buf.readInt();
    sidestates = new byte[bsize];
    for (int i = 0; i < bsize; i++) {
        sidestates[i] = buf.readByte();
    }
    //System.out.println(sidestates[0]);
}