Example usage for io.netty.buffer ByteBuf readByte

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

Introduction

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

Prototype

public abstract byte readByte();

Source Link

Document

Gets a byte at the current readerIndex and increases the readerIndex by 1 in this buffer.

Usage

From source file:books.netty.protocol.netty.codec.NettyMessageDecoder.java

License:Apache License

@Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
    ByteBuf frame = (ByteBuf) super.decode(ctx, in);
    if (frame == null) {
        return null;
    }/*  w w w .j a v a  2  s  .c  om*/

    NettyMessage message = new NettyMessage();
    Header header = new Header();
    header.setCrcCode(frame.readInt());
    header.setLength(frame.readInt());
    header.setSessionID(frame.readLong());
    header.setType(frame.readByte());
    header.setPriority(frame.readByte());

    int size = frame.readInt();
    if (size > 0) {
        Map<String, Object> attch = new HashMap<String, Object>(size);
        int keySize = 0;
        byte[] keyArray = null;
        String key = null;
        for (int i = 0; i < size; i++) {
            keySize = frame.readInt();
            keyArray = new byte[keySize];
            frame.readBytes(keyArray);
            key = new String(keyArray, "UTF-8");
            attch.put(key, marshallingDecoder.decode(frame));
        }
        keyArray = null;
        key = null;
        header.setAttachment(attch);
    }
    if (frame.readableBytes() > 4) {
        message.setBody(marshallingDecoder.decode(frame));
    }
    message.setHeader(header);
    return message;
}

From source file:books.netty.protocol.netty.codec.TestCodeC.java

License:Apache License

public NettyMessage decode(ByteBuf in) throws Exception {
    NettyMessage message = new NettyMessage();
    Header header = new Header();
    header.setCrcCode(in.readInt());/*  w  w  w .ja v a 2 s. co  m*/
    header.setLength(in.readInt());
    header.setSessionID(in.readLong());
    header.setType(in.readByte());
    header.setPriority(in.readByte());

    int size = in.readInt();
    if (size > 0) {
        Map<String, Object> attch = new HashMap<String, Object>(size);
        int keySize = 0;
        byte[] keyArray = null;
        String key = null;
        for (int i = 0; i < size; i++) {
            keySize = in.readInt();
            keyArray = new byte[keySize];
            in.readBytes(keyArray);
            key = new String(keyArray, "UTF-8");
            attch.put(key, marshallingDecoder.decode(in));
        }
        keyArray = null;
        key = null;
        header.setAttachment(attch);
    }
    if (in.readableBytes() > 4) {
        message.setBody(marshallingDecoder.decode(in));
    }
    message.setHeader(header);
    return message;
}

From source file:buildcraft.api.core.Position.java

License:Open Source License

@Override
public void readData(ByteBuf stream) {
    x = stream.readDouble();//from w w  w . j  a  v a  2 s .com
    y = stream.readDouble();
    z = stream.readDouble();
    orientation = ForgeDirection.getOrientation(stream.readByte());
}

From source file:buildcraft.core.lib.engines.TileEngineBase.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf stream) {
    int flags = stream.readUnsignedByte();
    energyStage = EnergyStage.values()[flags & 0x07];
    isPumping = (flags & 0x08) != 0;
    orientation = ForgeDirection.getOrientation(stream.readByte());
}

From source file:buildcraft.core.lib.network.ChannelHandler.java

License:Minecraft Mod Public

@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception {
    testMessageValidity(msg);// ww  w.j  av a 2  s.co m
    ByteBuf payload = msg.payload();
    byte discriminator = payload.readByte();
    Class<? extends Packet> clazz = discriminators.get(discriminator);
    if (clazz == null) {
        throw new NullPointerException(
                "Undefined message for discriminator " + discriminator + " in channel " + msg.channel());
    }
    Packet newMsg = clazz.newInstance();
    ctx.attr(INBOUNDPACKETTRACKER).get().set(new WeakReference<FMLProxyPacket>(msg));
    newMsg.readData(payload.slice());
    out.add(newMsg);
}

From source file:buildcraft.core.lib.network.PacketCoordinates.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    id = data.readByte();
    posX = data.readInt();
    posY = data.readShort();
    posZ = data.readInt();
}

From source file:buildcraft.core.lib.network.PacketGuiWidget.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    windowId = data.readByte();
    widgetId = data.readByte();/*from  w  ww.  j  a v  a 2  s.  co  m*/

    EntityPlayer player = FMLClientHandler.instance().getClient().thePlayer;

    if (player.openContainer instanceof BuildCraftContainer && player.openContainer.windowId == windowId) {
        ((BuildCraftContainer) player.openContainer).handleWidgetClientData(widgetId, data);
    }
}

From source file:buildcraft.core.lib.network.PacketUpdate.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    packetId = data.readByte();
    readIdentificationData(data);/*from   w w w  .j  av a  2 s  .c o m*/

    stream = data; // for further reading
}

From source file:buildcraft.core.network.PacketCoordinates.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    id = data.readByte();
    posX = data.readInt();
    posY = data.readInt();
    posZ = data.readInt();
}

From source file:buildcraft.core.network.PacketUpdate.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    packetId = data.readByte();
    posX = data.readInt();//  www.  j ava  2  s.c  o  m
    posY = data.readInt();
    posZ = data.readInt();

    payload = new PacketPayload();

    if (payload != null) {
        payload.readData(data);
    }
}