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.ltln.modules.openflow.core.protocol.ver13.OFBsnVrfCounterSerializerVer13.java

public static OFBsnVrfCounter readFrom(ByteBuf bb) throws OFParseError {
    try {//from ww  w.  j  a va  2s  . c om
        return ofWireValue(bb.readByte());
    } catch (IllegalArgumentException e) {
        throw new OFParseError(e);
    }
}

From source file:com.ltln.modules.openflow.core.protocol.ver14.OFControllerRoleReasonSerializerVer14.java

public static OFControllerRoleReason readFrom(ByteBuf bb) throws OFParseError {
    try {/*from ww  w  .jav a 2  s .  c  om*/
        return ofWireValue(bb.readByte());
    } catch (IllegalArgumentException e) {
        throw new OFParseError(e);
    }
}

From source file:com.ltln.modules.openflow.core.protocol.ver14.OFRequestforwardReasonSerializerVer14.java

public static OFRequestforwardReason readFrom(ByteBuf bb) throws OFParseError {
    try {/*from w  w w. j av  a 2 s  .  co m*/
        return ofWireValue(U8.f(bb.readByte()));
    } catch (IllegalArgumentException e) {
        throw new OFParseError(e);
    }
}

From source file:com.ltln.modules.openflow.core.protocol.ver14.OFTableReasonSerializerVer14.java

public static OFTableReason readFrom(ByteBuf bb) throws OFParseError {
    try {//from   w ww  .  j  av  a2 s .  c  o  m
        return ofWireValue(bb.readByte());
    } catch (IllegalArgumentException e) {
        throw new OFParseError(e);
    }
}

From source file:com.mastfrog.scamper.codec.MessageCodec.java

License:Open Source License

/**
 * Determine if this codec recognizes this ByteBuf.
 * <p>// www.  ja v  a  2s.c  o  m
 * This method will move the reader index of the passed ByteBuf <i>forward one byte</i>
 * if it returns true.  If it returns false, the ByteBuf's state will be 
 * unaltered.
 * <p>
 * The default implementation checks if the first byte equals the return
 * value of <code>magicNumber()</code>.  Implementations that delegate
 * between multiple codecs should call this method for each until one
 * accepts it.
 * 
 * @param data
 * @return 
 */
public boolean accept(ByteBuf data) {
    int old = data.readerIndex();
    byte b = data.readByte();
    boolean result = magicNumber() == b;
    if (!result) {
        data.readerIndex(old);
    }
    return result;
}

From source file:com.mastfrog.scamper.codec.RawMessageCodec.java

License:Open Source License

@Override
public MessageTypeAndBuffer decode(ByteBuf buf, ChannelHandlerContext ctx, int sctpChannel) {
    byte first = buf.readByte();
    if (first == magicNumber()) {
        MessageType messageType = messageTypes.forByteBuf(buf);
        return new MessageTypeAndBuffer(messageType, buf, sctpChannel);
    }//from   w  ww .  ja  v a 2s  .co m
    return new MessageTypeAndBuffer(MessageType.createUnknown(-1, -1), buf.resetReaderIndex(), sctpChannel);
}

From source file:com.mastfrog.scamper.compression.CompressingCodec.java

License:Open Source License

@Override
public MessageTypeAndBuffer decode(ByteBuf buf, ChannelHandlerContext ctx, int sctpChannel) {
    byte magic = buf.readByte();
    if (magic == magicNumber()) {
        try {//from ww  w .  j  a v  a2 s .  c o m
            return decodeImpl(buf, ctx, sctpChannel);
        } catch (Exception ex) {
            return Exceptions.chuck(ex);
        }
    } else {
        buf.resetReaderIndex();
        return raw.decode(buf, ctx, sctpChannel);
    }
}

From source file:com.mastfrog.scamper.MessageTypeRegistry.java

License:Open Source License

/**
 * Decode a message type from the <i>current position</i> of the
 * passed ByteBuf.// w ww. j  a  v  a 2 s  .c  om
 * @param buf
 * @return 
 */
public MessageType forByteBuf(ByteBuf buf) {
    if (buf.readableBytes() >= 2) {
        byte one = buf.readByte();
        byte two = buf.readByte();
        for (MessageType mt : types) {
            if (mt.match(one, two)) {
                buf.discardReadBytes();
                return mt;
            }
        }
        return MessageType.createUnknown(one, two);
    }
    buf.resetReaderIndex();
    return MessageType.createUnknown((byte) 0, (byte) 0);
}

From source file:com.mikesilversides.mod1.ServerTest.StubClientHandler.java

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
    //ctx.write(msg);
    ByteBuf in = (ByteBuf) msg;
    final Byte inByte = in.readByte();
    System.out.println("received from stub1 byte = " + inByte);
    in.release();/*from   w ww .  ja  v  a 2s . c om*/

    if (startSent) {
        if (inByte == 2) { // 2=ack
            System.out.println("received ack from stub1");
            startSent = false;
        } else {
            System.out.println("unexpected reply received, closing connection");
            ctx.close();
            stubClientPlayer.addChatMessage(
                    new ChatComponentText("unexpected stub1 reply received, connection closed"));
        }
    } else {
        //stubClientPlayer.addChatMessage(new ChatComponentText("stub1 sent byte = "+inByte));

        // This code creates a new task which will be executed by the server during the next tick,
        //  for example see MinecraftServer.updateTimeLightAndEntities(), just under section
        //      this.theProfiler.startSection("jobs");
        //  In this case, the task is to call messageHandlerOnServer.processMessage(message, sendingPlayer)
        //final WorldServer playerWorldServer = sendingPlayer.getServerForPlayer();
        //playerWorldServer.addScheduledTask(new Runnable() {
        MinecraftServer.getServer().addScheduledTask(new Runnable() {
            public void run() {
                processMessage(inByte);
            }
        });
    }
}

From source file:com.mobius.software.android.iotbroker.mqtt.parser.MQParser.java

License:Open Source License

public static ByteBuf next(ByteBuf buf) throws MalformedMessageException {
    buf.markReaderIndex();//from  www.  java  2  s.  c  o m
    MessageType type = MessageType.valueOf(((buf.readByte() >> 4) & 0xf));

    switch (type) {
    case PINGREQ:
    case PINGRESP:
    case DISCONNECT:
        buf.resetReaderIndex();
        return Unpooled.buffer(2);
    default:
        LengthDetails length = decodeLength(buf);
        buf.resetReaderIndex();
        if (length.getLength() == 0)
            return null;
        int result = length.getLength() + length.getSize() + 1;
        return result <= buf.readableBytes() ? Unpooled.buffer(result) : null;
    }
}