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

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

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

ByteBuf.readUnsignedShort介绍

[英]Gets an unsigned 16-bit short integer at the current readerIndexand increases the readerIndex by 2 in this buffer.
[中]获取当前readerIndex处的无符号16位短整数,并在此缓冲区中将readerIndex增加2。

代码示例

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

@Override
public int readUnsignedShort() {
  return buf.readUnsignedShort();
}

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

@Override
public int readUnsignedShort() {
  return buf.readUnsignedShort();
}

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

@Override
public int readUnsignedShort() {
  return buf.readUnsignedShort();
}

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

@Override
public int readUnsignedShort() {
 return buffer.readUnsignedShort();
}

代码示例来源:origin: Graylog2/graylog2-server

public static Integer parseRecordShallow(ByteBuf bb) {
  final int start = bb.readerIndex();
  int usedTemplateId = bb.readUnsignedShort();
  int length = bb.readUnsignedShort();
  int end = bb.readerIndex() - 4 + length;
  bb.readerIndex(end);
  return usedTemplateId;
}

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

@Override
public int readUnsignedShort() {
  checkReadableBytes(2);
  return buffer.readUnsignedShort();
}

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

@Override
public int readUnsignedShort() {
  checkReadableBytes(2);
  return buffer.readUnsignedShort();
}

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

private static double decodeCoordinate(ByteBuf buf) {
  double degrees = buf.getUnsignedShort(buf.readerIndex()) / 100;
  double minutes = buf.readUnsignedShort() % 100 + buf.readUnsignedShort() * 0.0001;
  degrees += minutes / 60;
  byte hemisphere = buf.readByte();
  if (hemisphere == 'S' || hemisphere == 'W') {
    degrees = -degrees;
  }
  return degrees;
}

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

@Override
public int readUnsignedShort() {
  checkReadableBytes(2);
  return buffer.readUnsignedShort();
}

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

@Override
public final DnsQuestion decodeQuestion(ByteBuf in) throws Exception {
  String name = decodeName(in);
  DnsRecordType type = DnsRecordType.valueOf(in.readUnsignedShort());
  int qClass = in.readUnsignedShort();
  return new DefaultDnsQuestion(name, type, qClass);
}

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

@Override
protected Object decode(
    Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
  ByteBuf buf = (ByteBuf) msg;
  buf.skipBytes(3); // header
  buf.readUnsignedShort(); // length
  String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 3, StandardCharsets.US_ASCII);
  buf.skipBytes(3); // footer
  return decodeMessage(channel, remoteAddress, sentence);
}

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

private List<Position> decodeLocationBatch(DeviceSession deviceSession, ByteBuf buf) {
  List<Position> positions = new LinkedList<>();
  int count = buf.readUnsignedShort();
  buf.readUnsignedByte(); // location type
  for (int i = 0; i < count; i++) {
    int endIndex = buf.readUnsignedShort() + buf.readerIndex();
    positions.add(decodeLocation(deviceSession, buf));
    buf.readerIndex(endIndex);
  }
  return positions;
}

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

private Object decodeUdp(Channel channel, SocketAddress remoteAddress, ByteBuf buf) throws Exception {
  buf.readUnsignedShort(); // length
  buf.readUnsignedShort(); // packet id
  buf.readUnsignedByte(); // packet type
  int locationPacketId = buf.readUnsignedByte();
  String imei = buf.readSlice(buf.readUnsignedShort()).toString(StandardCharsets.US_ASCII);
  return parseData(channel, remoteAddress, buf, locationPacketId, imei);
}

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

@Override
public final DnsQuestion decodeQuestion(ByteBuf in) throws Exception {
  String name = decodeName(in);
  DnsRecordType type = DnsRecordType.valueOf(in.readUnsignedShort());
  int qClass = in.readUnsignedShort();
  return new DefaultDnsQuestion(name, type, qClass);
}

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

@Override
protected void decode(ChannelHandlerContext ctx, DatagramPacket packet, List<Object> out) throws Exception {
  final ByteBuf buf = packet.content();
  final DnsQuery query = newQuery(packet, buf);
  boolean success = false;
  try {
    final int questionCount = buf.readUnsignedShort();
    final int answerCount = buf.readUnsignedShort();
    final int authorityRecordCount = buf.readUnsignedShort();
    final int additionalRecordCount = buf.readUnsignedShort();
    decodeQuestions(query, buf, questionCount);
    decodeRecords(query, DnsSection.ANSWER, buf, answerCount);
    decodeRecords(query, DnsSection.AUTHORITY, buf, authorityRecordCount);
    decodeRecords(query, DnsSection.ADDITIONAL, buf, additionalRecordCount);
    out.add(query);
    success = true;
  } finally {
    if (!success) {
      query.release();
    }
  }
}

代码示例来源: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: redisson/redisson

private static DnsQuery newQuery(DatagramPacket packet, ByteBuf buf) {
  final int id = buf.readUnsignedShort();
  final int flags = buf.readUnsignedShort();
  if (flags >> 15 == 1) {
    throw new CorruptedFrameException("not a query");
  }
  final DnsQuery query =
    new DatagramDnsQuery(
      packet.sender(),
      packet.recipient(),
      id,
      DnsOpCode.valueOf((byte) (flags >> 11 & 0xf)));
  query.setRecursionDesired((flags >> 8 & 1) == 1);
  query.setZ(flags >> 4 & 0x7);
  return query;
}

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

private static DnsResponse newResponse(DatagramPacket packet, ByteBuf buf) {
  final int id = buf.readUnsignedShort();
  final int flags = buf.readUnsignedShort();
  if (flags >> 15 == 0) {
    throw new CorruptedFrameException("not a response");
  }
  final DnsResponse response = new DatagramDnsResponse(
    packet.sender(),
    packet.recipient(),
    id,
    DnsOpCode.valueOf((byte) (flags >> 11 & 0xf)), DnsResponseCode.valueOf((byte) (flags & 0xf)));
  response.setRecursionDesired((flags >> 8 & 1) == 1);
  response.setAuthoritativeAnswer((flags >> 10 & 1) == 1);
  response.setTruncated((flags >> 9 & 1) == 1);
  response.setRecursionAvailable((flags >> 7 & 1) == 1);
  response.setZ(flags >> 4 & 0x7);
  return response;
}

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

public Date readTime(ByteBuf buf) {
  long weekTime = (long) (readFloat(buf) * 1000);
  if (weekNumber == 0) {
    weekNumber = buf.readUnsignedShort();
  }
  DateBuilder dateBuilder = new DateBuilder().setDate(1980, 1, 6);
  dateBuilder.addMillis(weekNumber * 7 * 24 * 60 * 60 * 1000 + weekTime);
  return dateBuilder.getDate();
}

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

private Date decodeTime(ByteBuf buf) {
  DateBuilder dateBuilder = new DateBuilder()
      .setDate(buf.readUnsignedShort(), buf.readUnsignedByte(), buf.readUnsignedByte())
      .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
  return dateBuilder.getDate();
}

相关文章

ByteBuf类方法