io.netty.buffer.ByteBuf.readByte()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(375)

本文整理了Java中io.netty.buffer.ByteBuf.readByte()方法的一些代码示例,展示了ByteBuf.readByte()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuf.readByte()方法的具体详情如下:
包路径:io.netty.buffer.ByteBuf
类名称:ByteBuf
方法名:readByte

ByteBuf.readByte介绍

[英]Gets a byte at the current readerIndex and increases the readerIndex by 1 in this buffer.
[中]在当前readerIndex处获取一个字节,并在此缓冲区中将readerIndex增加1。

代码示例

代码示例来源:origin: mpusher/mpush

public static Packet decodePacket(Packet packet, ByteBuf in, int bodyLength) {
  packet.cc = in.readShort();//read cc
  packet.flags = in.readByte();//read flags
  packet.sessionId = in.readInt();//read sessionId
  packet.lrc = in.readByte();//read lrc
  //read body
  if (bodyLength > 0) {
    in.readBytes(packet.body = new byte[bodyLength]);
  }
  return packet;
}

代码示例来源:origin: GlowstoneMC/Glowstone

private static boolean readableVarInt(ByteBuf buf) {
  if (buf.readableBytes() > 5) {
    // maximum varint size
    return true;
  }
  int idx = buf.readerIndex();
  byte in;
  do {
    if (buf.readableBytes() < 1) {
      buf.readerIndex(idx);
      return false;
    }
    in = buf.readByte();
  } while ((in & 0x80) != 0);
  buf.readerIndex(idx);
  return true;
}

代码示例来源:origin: runelite/runelite

@Override
  protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
  {
    if (in.getByte(in.readerIndex()) != UpdateOpcodes.ENCRYPTION)
    {
      ctx.fireChannelRead(in.retain());
      return;
    }

    in.readByte();
    byte xorKey = in.readByte();
    in.readShort(); // always 0

    EncryptionPacket encryptionPacket = new EncryptionPacket();
    encryptionPacket.setKey(xorKey);
    out.add(encryptionPacket);
  }
}

代码示例来源:origin: waterguo/antsdb

@Override
public void read(MysqlClientHandler handler, ByteBuf in) {
  int begin = in.readerIndex();
  in.readByte();
  tableName = BufferUtils.readStringWithLength(in);
  in.readByte();
  colCount = (int)BufferUtils.readLength(in);
  colTypeDef = BufferUtils.readBytes(in, colCount);
  in.readBytes(nullBitMap);
  int end = in.readerIndex();
  if (_log.isTraceEnabled())
    in.readerIndex(begin);
    byte[] bytes = new byte[end - begin];
    in.readBytes(bytes);
    String dump = '\n' + UberUtil.hexDump(bytes);
    _log.trace("Packet Info:\n"
        + this.toString()
        + "\nTableMapPacket packet:\n"

代码示例来源:origin: com.whizzosoftware.foscam/foscam-camera-discovery

if (buf.isReadable()) {
  do {
    b = buf.readByte();
  } while (b != 'M' && buf.isReadable());
  if (buf.readableBytes() > 0) {
    logger.trace("Found possible start of order");
    b = buf.readByte();
    if (b == 'O' && buf.isReadable()) {
      b = buf.readByte();
      if (b == '_' && buf.isReadable()) {
        b = buf.readByte();
        if (b == 'I' && buf.isReadable()) {
          Integer operationCode = popINT16(buf);
              Integer length = popINT32(buf);
              if (length != null && popBytes(buf, 4)) {
                if (buf.readableBytes() >= length) {
                  byte[] text = new byte[length];
                  buf.readBytes(text);

代码示例来源:origin: org.apache.plc4x/plc4j-protocol-s7

protected void decode(ChannelHandlerContext ctx, IsoTPMessage in, List<Object> out) {
  if (logger.isTraceEnabled()) {
    logger.trace("Got Data: {}", ByteBufUtil.hexDump(in.getUserData()));
  if (userData.readableBytes() == 0) {
    return;
  if (userData.readByte() != S7_PROTOCOL_MAGIC_NUMBER) {
    logger.warn("Expecting S7 protocol magic number.");
    if (logger.isDebugEnabled()) {
  MessageType messageType = MessageType.valueOf(userData.readByte());
  boolean isResponse = messageType == MessageType.ACK_DATA;
  userData.readShort();  // Reserved (is always constant 0x0000)
  short tpduReference = userData.readShort();
  short headerParametersLength = userData.readShort();
  short userDataLength = userData.readShort();
  byte errorClass = 0;
  byte errorCode = 0;
  if (isResponse) {
    errorClass = userData.readByte();
    errorCode = userData.readByte();

代码示例来源:origin: alibaba/Sentinel

@Override
  public ClusterResponse decode(ByteBuf source) {
    if (source.readableBytes() >= 6) {
      int xid = source.readInt();
      int type = source.readByte();
      int status = source.readByte();

      EntityDecoder<ByteBuf, ?> decoder = ResponseDataDecodeRegistry.getDecoder(type);
      if (decoder == null) {
        RecordLog.warn("Unknown type of response data decoder: {0}", type);
        return null;
      }

      Object data;
      if (source.readableBytes() == 0) {
        data = null;
      } else {
        data = decoder.decode(source);
      }

      return new ClusterResponse<>(xid, type, status, data);
    }
    return null;
  }
}

代码示例来源:origin: weibocom/motan

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
  if (in.readableBytes() <= MotanConstants.NETTY_HEADER) {
    return;
  }
  in.markReaderIndex();
  short type = in.readShort();
  if (type != MotanConstants.NETTY_MAGIC_TYPE) {
    in.resetReaderIndex();
    throw new MotanFrameworkException("NettyDecoder transport header not support, type: " + type);
  }
  in.skipBytes(1);
  int rpcVersion = (in.readByte() & 0xff) >>> 3;
  switch (rpcVersion) {
    case 0:
      decodeV1(ctx, in, out);
      break;
    case 1:
      decodeV2(ctx, in, out);
      break;
    default:
      decodeV2(ctx, in, out);
  }
}

代码示例来源:origin: traccar/traccar

private long readValue(ByteBuf buf, int length, boolean signed) {
  switch (length) {
    case 1:
      return signed ? buf.readByte() : buf.readUnsignedByte();
    case 2:
      return signed ? buf.readShort() : buf.readUnsignedShort();
    case 4:
      return signed ? buf.readInt() : buf.readUnsignedInt();
    default:
      return buf.readLong();
  }
}

代码示例来源:origin: traccar/traccar

switch (buf.readInt()) {
  case 0x20D:
    position.set(Position.KEY_RPM, value.readShortLE());
    break;
  case 0x58C:
    value.readByte();
    value.readShort(); // index
    switch (value.readByte()) {
      case 0x01:
        position.set("setpointZone1", value.readIntLE() * 0.1);

代码示例来源:origin: alibaba/fescar

@Override
  public boolean decode(ByteBuf in) {
    int i = in.readableBytes();
    if (i < 3) {
      return false;
    }
    i -= 3;
    this.identified = (in.readByte() == 1);

    short len = in.readShort();
    if (len > 0) {
      if (i < len) {
        return false;
      }

      byte[] bs = new byte[len];
      in.readBytes(bs);
      this.setVersion(new String(bs, UTF8));
    }

    return true;
  }
}

代码示例来源:origin: org.opendaylight.netconf/netconf-netty-util

@Override
public void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws IOException, SAXException {
  if (in.isReadable()) {
    if (LOG.isTraceEnabled()) {
      LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in));
      if (!isWhitespace(in.readByte())) {
        in.readerIndex(in.readerIndex() - 1);
        break;
    if (in.readerIndex() != 0 && LOG.isWarnEnabled()) {
      final byte[] strippedBytes = new byte[in.readerIndex()];
      in.getBytes(0, strippedBytes, 0, in.readerIndex());

代码示例来源:origin: whizzosoftware/WZWave

cbuf.addComponent(previousBuf.copy());
  cbuf.addComponent(in);
  cbuf.writerIndex(previousBuf.readableBytes() + in.readableBytes());
  data = cbuf;
  if (data.readableBytes() == 1 && isSingleByteFrame(data, data.readerIndex())) {
    out.add(createSingleByteFrame(data));
  } else {
    boolean foundFrame = false;
    for (int searchStartIx = data.readerIndex(); searchStartIx < data.readerIndex() + data.readableBytes(); searchStartIx++) {
      if (data.getByte(searchStartIx) == DataFrame.START_OF_FRAME) {
        int frameEndIx = scanForFrame(data, searchStartIx);
          if (df != null) {
            out.add(df);
            data.readByte(); // discard checksum
            foundFrame = true;
          } else {
in.readBytes(in.readableBytes());
logger.trace("Done processing received data: {}", out);

代码示例来源:origin: traccar/traccar

@Override
protected Object decode(
    ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
  if (buf.readableBytes() >= MESSAGE_HEADER) {
    int length = Integer.parseInt(buf.toString(2, 2, StandardCharsets.US_ASCII)) + 5;
    if (buf.readableBytes() >= length) {
      ByteBuf frame = buf.readRetainedSlice(length);
      while (buf.isReadable() && buf.getUnsignedByte(buf.readerIndex()) != '$') {
        buf.readByte();
      }
      return frame;
    }
  }
  return null;
}

代码示例来源:origin: mpusher/mpush

private Packet decodeFrame(ByteBuf in) {
  int readableBytes = in.readableBytes();
  int bodyLength = in.readInt();
  if (readableBytes < (bodyLength + Packet.HEADER_LEN)) {
    return null;
  }
  if (bodyLength > maxPacketSize) {
    throw new TooLongFrameException("packet body length over limit:" + bodyLength);
  }
  return decodePacket(new Packet(in.readByte()), in, bodyLength);
}

代码示例来源:origin: traccar/traccar

while (buf.readableBytes() > 0) {
    for (int i = 1; i < n; i++) {
      if (k == 1) {
        data.append(buf.readByte()).append(" ");
      } else if (k == 2) {
        data.append(buf.readShort()).append(" ");
    for (int i = 1; i < m; i++) {
      if (k == 1) {
        data.append(buf.readByte()).append(" ");
      } else if (k == 2) {
        data.append(buf.readShort()).append(" ");

代码示例来源:origin: traccar/traccar

private long readValue(ByteBuf buf, int length, boolean signed) {
  switch (length) {
    case 1:
      return signed ? buf.readByte() : buf.readUnsignedByte();
    case 2:
      return signed ? buf.readShort() : buf.readUnsignedShort();
    case 4:
      return signed ? buf.readInt() : buf.readUnsignedInt();
    default:
      return buf.readLong();
  }
}

代码示例来源:origin: runelite/runelite

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
{
  byte opcode = in.getByte(in.readerIndex());
  if (opcode != UpdateOpcodes.ARCHIVE_REQUEST_HIGH
    && opcode != UpdateOpcodes.ARCHIVE_REQUEST_LOW)
  {
    ctx.fireChannelRead(in.retain());
    return;
  }
  byte priority = in.readByte();
  int index = in.readByte() & 0xFF;
  int archiveId = in.readShort() & 0xFFFF;
  ArchiveRequestPacket archiveRequest = new ArchiveRequestPacket();
  archiveRequest.setPriority(priority == 1);
  archiveRequest.setIndex(index);
  archiveRequest.setArchive(archiveId);
  out.add(archiveRequest);
}

代码示例来源:origin: alibaba/Sentinel

private boolean decodeParam(ByteBuf source, List<Object> params) {
  byte paramType = source.readByte();
      params.add(source.readInt());
      return true;
    case ClusterConstants.PARAM_TYPE_STRING:
      int length = source.readInt();
      byte[] bytes = new byte[length];
      source.readBytes(bytes);
      return true;
    case ClusterConstants.PARAM_TYPE_BYTE:
      params.add(source.readByte());
      return true;
    case ClusterConstants.PARAM_TYPE_SHORT:
      params.add(source.readShort());
      return true;
    default:

代码示例来源:origin: org.opendaylight.controller/netconf-netty-util

@Override
public void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws IOException, SAXException {
  if (in.isReadable()) {
    if (LOG.isTraceEnabled()) {
      LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in));
      if (!isWhitespace(in.readByte())) {
        in.readerIndex(in.readerIndex() - 1);
        break;
    if (in.readerIndex() != 0 && LOG.isWarnEnabled()) {
      final byte[] strippedBytes = new byte[in.readerIndex()];
      in.getBytes(0, strippedBytes, 0, in.readerIndex());

相关文章

ByteBuf类方法