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:com.whizzosoftware.wzwave.frame.RequestNodeInfo.java

License:Open Source License

public RequestNodeInfo(ByteBuf buffer) {
    super(buffer);
    retVal = buffer.readByte();
}

From source file:com.whizzosoftware.wzwave.frame.SendData.java

License:Open Source License

public SendData(ByteBuf buffer) {
    super(buffer);
    if (dataFrameLength == 4) {
        this.retVal = buffer.readByte();
    } else if (dataFrameLength == 5) {
        this.callbackId = buffer.readByte();
        this.tx = buffer.readByte();
    } else if (dataFrameLength > 5) {
        this.nodeId = buffer.readByte();
        byte dataLength = buffer.readByte();
        this.sendData = buffer.readBytes(dataLength).array();
        this.tx = buffer.readByte();
        this.callbackId = buffer.readByte();
    }//from w  ww  .  j  av a 2  s  .co m
}

From source file:com.whizzosoftware.wzwave.frame.SetDefault.java

License:Open Source License

public SetDefault(ByteBuf buffer) {
    super(buffer);
    buffer.readByte(); // funcId
}

From source file:com.whizzosoftware.wzwave.frame.Version.java

License:Open Source License

public Version(ByteBuf buffer) {
    super(buffer);
    libraryVersion = new String(buffer.readBytes(12).array()).trim();
    libraryType = buffer.readByte();
}

From source file:com.whizzosoftware.wzwave.node.NodeInfo.java

License:Open Source License

public NodeInfo(byte nodeId, ByteBuf buffer, int nodeInfoLength) {
    this.nodeId = nodeId;
    buffer.readByte();
    basicDeviceClass = buffer.readByte();
    genericDeviceClass = buffer.readByte();
    specificDeviceClass = buffer.readByte();
    commandClasses = buffer.readBytes(nodeInfoLength - 3).array();
}

From source file:com.witjit.game.server.communication.handler.ClientDispatchHandler.java

/**
 *
 * @param ctx//from w w w . j a v a2 s . c o  m
 * @param msg
 * @throws Exception
 */
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (!(msg instanceof ByteBuf)) {
        //TODO: handle error message.
        return;
    }

    ByteBuf mb = (ByteBuf) msg;

    byte target = mb.readByte();
    short id = mb.readShort();
    mb.discardReadBytes();

    ClientChannelData channelData = ChannelData.get(ctx.channel());
    ClientSessionPoint sessionPoint = channelData.getBindSessionPoint();
    sessionPoint.transit(target, MessageID.make(id), msg);
}

From source file:com.xiovr.unibot.bot.network.impl.ConnectionDecoderImpl.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    // System.out.println("Run decoder bytes="+ in.readableBytes());

    for (;;) {/*  ww  w  .j a v a2s  .c o  m*/
        if (in.readableBytes() < 2)
            return;

        // System.out.println("Decoder size=" + in.readableBytes());
        in.markReaderIndex();

        // int dataLen = in.readUnsignedShort() - 2;
        byte b1 = in.readByte();
        byte b2 = in.readByte();
        int dataLen = (b1 & 0xFF) | ((b2 << 8) & 0xFF00);

        // System.out.println("packet len =" + dataLen);

        // System.out.println("readable bytes =" + in.readableBytes());
        if (in.readableBytes() < dataLen - 2) {
            in.resetReaderIndex();
            return;
        }
        Packet pck = PacketPool.obtain();
        pck.clear();

        byte[] pckArr = pck.getBuf().array();
        // byte[] inArr = in.array();
        in.readBytes(pckArr, 2, dataLen - 2);
        pck.putHeader(dataLen);
        pck.setPosition(dataLen);
        // int rIndex = in.readerIndex();
        // System.arraycopy(inArr, rIndex-2, pckArr, 0, dataLen+2);
        // in.readerIndex(rIndex+dataLen);
        out.add(pck);
        // System.out.println("DECODER END");
    }
}

From source file:com.xx_dev.apn.proxy.utils.ByteBufLogUtil.java

License:Apache License

public static String toLogString(ByteBuf byteBuf) {
    StringBuilder sb = new StringBuilder();
    byteBuf.readerIndex(0);//from  ww  w  .j a  v a  2s .  c  o  m
    while (byteBuf.isReadable()) {
        sb.append(String.valueOf((int) byteBuf.readByte())).append(",");
    }

    byteBuf.readerIndex(0);
    return sb.toString();
}

From source file:com.yea.remote.netty.codec.NettyMessageDecoder.java

License:Apache License

@Override
public Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
    ByteBuf frame = (ByteBuf) super.decode(ctx, in);
    if (frame == null) {
        return null;
    }//from  www. j  a v  a  2s . c  o m
    ISerializer serializer = serializePool.borrow();
    try {
        Message message = new Message();
        byte[] sessionID = new byte[16];
        Header header = new Header();
        header.setCrcCode(frame.readInt());
        header.setLength(frame.readInt());
        frame.readBytes(sessionID);
        header.setSessionID(sessionID);
        header.setType(frame.readByte());
        header.setPriority(frame.readByte());
        header.setResult(frame.readByte());
        RemoteConstants.CompressionAlgorithm compressionAlgorithm = RemoteConstants.CompressionAlgorithm
                .valueOf(frame.readByte());
        if (compressionAlgorithm != null && compressionAlgorithm.code() > 0) {
            //
            serializer.setCompress(new Compress().setCompressionAlgorithm(compressionAlgorithm.algorithm()));
        }
        long basedate = frame.readLong();

        int attachmentSize = frame.readByte();
        if (attachmentSize > 0) {
            attachmentSize = frame.readByte();//?Date?String?
            if (attachmentSize > 0) {
                byte[] keyArray = null;
                byte[] valueArray = null;
                for (int i = 0; i < attachmentSize; i++) {
                    keyArray = new byte[frame.readShort()];
                    frame.readBytes(keyArray);
                    valueArray = new byte[frame.readShort()];
                    frame.readBytes(valueArray);

                    header.addAttachment(new String(keyArray, "ISO-8859-1"),
                            serializer.deserialize(valueArray));
                }
            }
            attachmentSize = frame.readByte();//Date?
            if (attachmentSize > 0) {
                byte[] keyArray = null;
                byte length = 0;
                for (int i = 0; i < attachmentSize; i++) {
                    keyArray = new byte[frame.readShort()];
                    frame.readBytes(keyArray);
                    length = frame.readByte();
                    if (length == 1) {
                        header.addAttachment(new String(keyArray, "ISO-8859-1"),
                                new Date(basedate - frame.readByte()));
                    } else if (length == 2) {
                        header.addAttachment(new String(keyArray, "ISO-8859-1"),
                                new Date(basedate - frame.readShort()));
                    } else if (length == 4) {
                        header.addAttachment(new String(keyArray, "ISO-8859-1"),
                                new Date(basedate - frame.readInt()));
                    } else {
                        header.addAttachment(new String(keyArray, "ISO-8859-1"),
                                new Date(basedate - frame.readLong()));
                    }
                }
            }
            attachmentSize = frame.readByte();//String?
            if (attachmentSize > 0) {
                byte[] keyArray = null;
                byte[] valueArray = null;
                for (int i = 0; i < attachmentSize; i++) {
                    keyArray = new byte[frame.readShort()];
                    frame.readBytes(keyArray);
                    valueArray = new byte[frame.readShort()];
                    frame.readBytes(valueArray);

                    header.addAttachment(new String(keyArray, "ISO-8859-1"),
                            new String(valueArray, "ISO-8859-1"));
                }
            }
        }
        header.addAttachment(NettyConstants.MessageHeaderAttachment.SEND_DATE.value(), new Date(basedate));
        header.addAttachment(NettyConstants.MessageHeaderAttachment.RECIEVE_DATE.value(), new Date());
        message.setHeader(header);

        if (frame.readableBytes() > 4) {
            int length = frame.readInt();//Body
            byte[] objArray = new byte[length];
            frame.readBytes(objArray);
            try {
                Object body = serializer.deserialize(objArray);
                message.setBody(body);
            } catch (Exception ex) {
                if (RemoteConstants.MessageType.SERVICE_RESP.value() == message.getHeader().getType()) {
                    message.getHeader().setType(RemoteConstants.MessageType.SUSPEND_RESP.value());
                    message.getHeader().setResult(RemoteConstants.MessageResult.FAILURE.value());
                    message.setBody(ex);
                } else if (RemoteConstants.MessageType.SERVICE_REQ.value() == message.getHeader().getType()) {
                    message.getHeader().setType(RemoteConstants.MessageType.SUSPEND_REQ.value());
                    message.getHeader().setResult(RemoteConstants.MessageResult.FAILURE.value());
                    message.setBody(ex);
                } else {
                    throw ex;
                }
            }
        }

        return message;
    } finally {
        serializePool.restore(serializer);
        frame.release();
    }
}

From source file:com.zz.learning.netty5.chap12.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;
    }/*from  www.  ja  v  a2  s . c  o m*/

    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(); // attachment
    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(); // key
            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) {
        //?4??0
        message.setBody(marshallingDecoder.decode(frame));
    }
    message.setHeader(header);
    return message;
}