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

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

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

ByteBuf.readUnsignedByte介绍

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

代码示例

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

/**
 * Refill the {@link ByteBuf} by one byte.
 */
void refill() {
  int readData = in.readUnsignedByte();
  bitBuffer = bitBuffer << 8 | readData;
  bitCount += 8;
}

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

@Override
public short readUnsignedByte() {
  return buf.readUnsignedByte();
}

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

@Override
public short readUnsignedByte() {
  return buf.readUnsignedByte();
}

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

/**
 * Refill the {@link ByteBuf} by one byte.
 */
void refill() {
  int readData = in.readUnsignedByte();
  bitBuffer = bitBuffer << 8 | readData;
  bitCount += 8;
}

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

@Override
public short readUnsignedByte() {
  return buf.readUnsignedByte();
}

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

@Override
public short readUnsignedByte() {
  return buf.readUnsignedByte();
}

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

/**
 * Refill the {@link ByteBuf} by one byte.
 */
void refill() {
  int readData = in.readUnsignedByte();
  bitBuffer = bitBuffer << 8 | readData;
  bitCount += 8;
}

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

@Override
public short readUnsignedByte() {
  checkReadableBytes(1);
  return buffer.readUnsignedByte();
}

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

private static Result<Integer> decodeMsbLsb(ByteBuf buffer, int min, int max) {
  short msbSize = buffer.readUnsignedByte();
  short lsbSize = buffer.readUnsignedByte();
  final int numberOfBytesConsumed = 2;
  int result = msbSize << 8 | lsbSize;
  if (result < min || result > max) {
    result = -1;
  }
  return new Result<Integer>(result, numberOfBytesConsumed);
}

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

@Override
public short readUnsignedByte() {
  checkReadableBytes(1);
  return buffer.readUnsignedByte();
}

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

private static void skipControlCharactersStandard(ByteBuf undecodedChunk) {
  for (;;) {
    char c = (char) undecodedChunk.readUnsignedByte();
    if (!Character.isISOControl(c) && !Character.isWhitespace(c)) {
      undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1);
      break;
    }
  }
}

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

/**
 * Reads the length varint (a series of bytes, where the lower 7 bits
 * are data and the upper bit is a flag to indicate more bytes to be
 * read).
 *
 * @param in The input buffer to read the preamble from
 * @return The calculated length based on the input buffer, or 0 if
 *   no preamble is able to be calculated
 */
private static int readPreamble(ByteBuf in) {
  int length = 0;
  int byteIndex = 0;
  while (in.isReadable()) {
    int current = in.readUnsignedByte();
    length |= (current & 0x7f) << byteIndex++ * 7;
    if ((current & 0x80) == 0) {
      return length;
    }
    if (byteIndex >= 4) {
      throw new DecompressionException("Preamble is greater than 4 bytes");
    }
  }
  return 0;
}

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

@Override
public String readLine() throws IOException {
  if (!buffer.isReadable()) {
    return null;
  }
  if (lineBuf != null) {
    lineBuf.setLength(0);
  }
  loop: do {
    int c = buffer.readUnsignedByte();
    switch (c) {
      case '\n':
        break loop;
      case '\r':
        if (buffer.isReadable() && (char) buffer.getUnsignedByte(buffer.readerIndex()) == '\n') {
          buffer.skipBytes(1);
        }
        break loop;
      default:
        if (lineBuf == null) {
          lineBuf = new StringBuilder();
        }
        lineBuf.append((char) c);
    }
  } while (buffer.isReadable());
  return lineBuf != null && lineBuf.length() > 0 ? lineBuf.toString() : StringUtil.EMPTY_STRING;
}

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

/**
 * If padding is present in the payload, reads the next byte as padding. The padding also includes the one byte
 * width of the pad length field. Otherwise, returns zero.
 */
private int readPadding(ByteBuf payload) {
  if (!flags.paddingPresent()) {
    return 0;
  }
  return payload.readUnsignedByte() + 1;
}

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

@Override
public short readUnsignedByte() {
  checkReadableBytes(1);
  return buffer.readUnsignedByte();
}

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

private void verifyCrc(ByteBuf in) {
  long crcValue = 0;
  for (int i = 0; i < 4; ++i) {
    crcValue |= (long) in.readUnsignedByte() << i * 8;
  }
  long readCrc = crc.getValue();
  if (crcValue != readCrc) {
    throw new DecompressionException(
        "CRC value mismatch. Expected: " + crcValue + ", Got: " + readCrc);
  }
}

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

private void verifyCrc(ByteBuf in) {
  long crcValue = 0;
  for (int i = 0; i < 4; ++i) {
    crcValue |= (long) in.readUnsignedByte() << i * 8;
  }
  long readCrc = crc.getValue();
  if (crcValue != readCrc) {
    throw new DecompressionException(
        "CRC value mismatch. Expected: " + crcValue + ", Got: " + readCrc);
  }
}

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

private boolean readGZIPFooter(ByteBuf buf) {
  if (buf.readableBytes() < 8) {
    return false;
  }
  verifyCrc(buf);
  // read ISIZE and verify
  int dataLength = 0;
  for (int i = 0; i < 4; ++i) {
    dataLength |= buf.readUnsignedByte() << i * 8;
  }
  int readLength = inflater.getTotalOut();
  if (dataLength != readLength) {
    throw new DecompressionException(
        "Number of bytes mismatch. Expected: " + dataLength + ", Got: " + readLength);
  }
  return true;
}

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

private boolean readGZIPFooter(ByteBuf buf) {
  if (buf.readableBytes() < 8) {
    return false;
  }
  verifyCrc(buf);
  // read ISIZE and verify
  int dataLength = 0;
  for (int i = 0; i < 4; ++i) {
    dataLength |= buf.readUnsignedByte() << i * 8;
  }
  int readLength = inflater.getTotalOut();
  if (dataLength != readLength) {
    throw new DecompressionException(
        "Number of bytes mismatch. Expected: " + dataLength + ", Got: " + readLength);
  }
  return true;
}

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

private static Result<MqttConnAckVariableHeader> decodeConnAckVariableHeader(ByteBuf buffer) {
  final boolean sessionPresent = (buffer.readUnsignedByte() & 0x01) == 0x01;
  byte returnCode = buffer.readByte();
  final int numberOfBytesConsumed = 2;
  final MqttConnAckVariableHeader mqttConnAckVariableHeader =
      new MqttConnAckVariableHeader(MqttConnectReturnCode.valueOf(returnCode), sessionPresent);
  return new Result<MqttConnAckVariableHeader>(mqttConnAckVariableHeader, numberOfBytesConsumed);
}

相关文章

ByteBuf类方法