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

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

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

ByteBuf.readUnsignedIntLE介绍

[英]Gets an unsigned 32-bit integer at the current readerIndexin the Little Endian Byte Order and increases the readerIndexby 4 in this buffer.
[中]获取当前ReaderIndex处的一个无符号32位整数,按小尾数字节顺序,并在此缓冲区中将ReaderIndex增加4。

代码示例

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

@Override
public long readUnsignedIntLE() {
  return buf.readUnsignedIntLE();
}

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

@Override
public long readUnsignedIntLE() {
  return buf.readUnsignedIntLE();
}

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

@Override
public long readUnsignedIntLE() {
  return buf.readUnsignedIntLE();
}

代码示例来源:origin: micronaut-projects/micronaut-core

@Override
public long readUnsignedIntLE() {
  return byteBuf.readUnsignedIntLE();
}

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

@Override
public long readUnsignedIntLE() {
  checkReadableBytes(4);
  return buffer.readUnsignedIntLE();
}

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

@Override
public long readUnsignedIntLE() {
  checkReadableBytes(4);
  return buffer.readUnsignedIntLE();
}

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

private void decodeStat(Position position, ByteBuf buf) {
  buf.readUnsignedIntLE(); // ACC ON time
  buf.readUnsignedIntLE(); // UTC time
  position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
  position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedIntLE());
  position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedIntLE());
  buf.readUnsignedShortLE(); // current fuel consumption
  position.set(Position.KEY_STATUS, buf.readUnsignedIntLE());
  buf.skipBytes(8);
}

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

@Override
public long readUnsignedIntLE() {
  checkReadableBytes(4);
  return buffer.readUnsignedIntLE();
}

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

@Override
protected Object decode(
    Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
  ByteBuf buf = (ByteBuf) msg;
  prefix = buf.toString(buf.readerIndex(), 4, StandardCharsets.US_ASCII);
  buf.skipBytes(prefix.length()); // prefix @NTC by default
  serverId = buf.readUnsignedIntLE();
  deviceUniqueId = buf.readUnsignedIntLE();
  int length = buf.readUnsignedShortLE();
  buf.skipBytes(2); // header and data XOR checksum
  if (length == 0) {
    return null; // keep alive message
  }
  String type = buf.toString(buf.readerIndex(), 3, StandardCharsets.US_ASCII);
  buf.skipBytes(type.length());
  if (type.equals("*>S")) {
    return processHandshake(channel, remoteAddress, buf);
  } else {
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
    if (deviceSession != null) {
      if (type.equals("*>T")) {
        return processSingle(deviceSession, channel, buf);
      } else if (type.equals("*>A")) {
        return processArray(deviceSession, channel, buf);
      }
    }
  }
  return null;
}

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

@Override
protected Object decode(
    ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
  if (buf.readableBytes() < 4) {
    return null;
  }
  long length = buf.getUnsignedIntLE(buf.readerIndex());
  if (length < 1024) {
    if (buf.readableBytes() >= length + 4) {
      buf.readUnsignedIntLE();
      return buf.readRetainedSlice((int) length);
    }
  } else {
    int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0);
    if (endIndex >= 0) {
      ByteBuf frame = buf.readRetainedSlice(endIndex - buf.readerIndex());
      buf.readByte();
      if (frame.readableBytes() > 0) {
        return frame;
      }
    }
  }
  return null;
}

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

@Override
protected Object decode(
    ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
  // Check minimum length
  if (buf.readableBytes() < MESSAGE_HEADER) {
    return null;
  }
  // Check for preamble
  boolean hasPreamble = false;
  if (buf.getUnsignedIntLE(buf.readerIndex()) == PREAMBLE) {
    hasPreamble = true;
  }
  // Check length and return buffer
  int length = buf.getUnsignedShortLE(buf.readerIndex() + 6);
  if (buf.readableBytes() >= length) {
    if (hasPreamble) {
      buf.readUnsignedIntLE();
      length -= 4;
    }
    return buf.readRetainedSlice(length);
  }
  return null;
}

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

private Object decodeMpip(
    Channel channel, SocketAddress remoteAddress, ByteBuf buf,
    int version, ByteBuf id, short type, DeviceSession deviceSession) {
  if (type == 0x4001) {
    sendResponse(channel, remoteAddress, version, id, (short) type, null);
    return readPosition(deviceSession, buf);
  } else if (type == 0x2001) {
    sendResponse(channel, remoteAddress, id, (short) 0x1001);
    buf.readUnsignedIntLE(); // index
    buf.readUnsignedIntLE(); // unix time
    buf.readUnsignedByte();
    return readPosition(deviceSession, buf);
  } else if (type == 0x4201 || type == 0x4202 || type == 0x4206) {
    return readPosition(deviceSession, buf);
  } else if (type == 0x4204) {
    List<Position> positions = new LinkedList<>();
    for (int i = 0; i < 8; i++) {
      Position position = readPosition(deviceSession, buf);
      buf.skipBytes(31);
      positions.add(position);
    }
    return positions;
  }
  return null;
}

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

private void decodeTag(Position position, ByteBuf buf, int tag) {
  if (tag >= 0x50 && tag <= 0x57) {
    position.set(Position.PREFIX_ADC + (tag - 0x50), buf.readUnsignedShortLE());
  } else if (tag >= 0x60 && tag <= 0x62) {
    position.set("fuel" + (tag - 0x60), buf.readUnsignedShortLE());
  } else if (tag >= 0xa0 && tag <= 0xaf) {
    position.set("can8BitR" + (tag - 0xa0 + 15), buf.readUnsignedByte());
  } else if (tag >= 0xb0 && tag <= 0xb9) {
    position.set("can16BitR" + (tag - 0xb0 + 5), buf.readUnsignedShortLE());
  } else if (tag >= 0xc4 && tag <= 0xd2) {
    position.set("can8BitR" + (tag - 0xc4), buf.readUnsignedByte());
  } else if (tag >= 0xd6 && tag <= 0xda) {
    position.set("can16BitR" + (tag - 0xd6), buf.readUnsignedShortLE());
  } else if (tag >= 0xdb && tag <= 0xdf) {
    position.set("can32BitR" + (tag - 0xdb), buf.readUnsignedIntLE());
  } else if (tag >= 0xe2 && tag <= 0xe9) {
    position.set("userData" + (tag - 0xe2), buf.readUnsignedIntLE());
  } else if (tag >= 0xf0 && tag <= 0xf9) {
    position.set("can32BitR" + (tag - 0xf0 + 5), buf.readUnsignedIntLE());
  } else {
    decodeTagOther(position, buf, tag);
  }
}

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

private void decodeLocation(Position position, ByteBuf buf) {
  DateBuilder dateBuilder = new DateBuilder()
      .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
      .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
  position.setTime(dateBuilder.getDate());
  int flags = buf.readUnsignedByte();
  position.setValid(BitUtil.to(flags, 2) > 0);
  double lat = buf.readUnsignedIntLE() / 3600000.0;
  double lon = buf.readUnsignedIntLE() / 3600000.0;
  position.setLatitude(BitUtil.check(flags, 2) ? lat : -lat);
  position.setLongitude(BitUtil.check(flags, 3) ? lon : -lon);
  position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShortLE()));
  position.setCourse(buf.readUnsignedShortLE() * 0.1);
  position.setAltitude(buf.readShortLE() * 0.1);
}

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

private Position parseUnitReport(
    DeviceSession deviceSession, ByteBuf buf, int sequenceNumber) {
  Position position = new Position(getProtocolName());
  position.setValid(true);
  position.set(Position.KEY_INDEX, sequenceNumber);
  position.setDeviceId(deviceSession.getDeviceId());
  buf.readUnsignedShortLE(); // report trigger
  position.set(Position.KEY_FLAGS, buf.readUnsignedShortLE());
  position.setLatitude(buf.readIntLE() * 0.0000001);
  position.setLongitude(buf.readIntLE() * 0.0000001);
  position.setAltitude(buf.readUnsignedShortLE());
  position.set(Position.KEY_SATELLITES, buf.readUnsignedShortLE());
  position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedShortLE());
  position.set("gpsAntennaState", buf.readUnsignedShortLE());
  position.setSpeed(buf.readUnsignedShortLE() * 0.194384);
  position.setCourse(buf.readUnsignedShortLE());
  position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
  position.set(Position.KEY_DISTANCE, buf.readUnsignedIntLE());
  position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001);
  position.set(Position.KEY_CHARGE, buf.readUnsignedShortLE());
  position.setTime(convertTimestamp(buf.readUnsignedIntLE()));
  return position;
}

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

private Position readPosition(DeviceSession deviceSession, ByteBuf buf) {
  Position position = new Position(getProtocolName());
  position.setDeviceId(deviceSession.getDeviceId());
  DateBuilder dateBuilder = new DateBuilder()
      .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
      .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
  position.setTime(dateBuilder.getDate());
  double lat = buf.readUnsignedIntLE() / 3600000.0;
  double lon = buf.readUnsignedIntLE() / 3600000.0;
  position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShortLE()));
  position.setCourse(buf.readUnsignedShortLE() * 0.1);
  int flags = buf.readUnsignedByte();
  if ((flags & 0x02) == 0) {
    lat = -lat;
  }
  if ((flags & 0x01) == 0) {
    lon = -lon;
  }
  position.setLatitude(lat);
  position.setLongitude(lon);
  position.setValid((flags & 0x0C) > 0);
  position.set(Position.KEY_SATELLITES, flags >> 4);
  return position;
}

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

private Position parseSnapshot4(
    DeviceSession deviceSession, ByteBuf buf, int sequenceNumber) {
  Position position = new Position(getProtocolName());
  position.set(Position.KEY_INDEX, sequenceNumber);
  position.setDeviceId(deviceSession.getDeviceId());
  buf.readUnsignedByte(); // report trigger
  buf.readUnsignedByte(); // position fix source
  buf.readUnsignedByte(); // GNSS fix quality
  buf.readUnsignedByte(); // GNSS assistance age
  long flags = buf.readUnsignedIntLE();
  position.setValid((flags & 0x0400) == 0x0400);
  position.setTime(convertTimestamp(buf.readUnsignedIntLE()));
  position.setLatitude(buf.readIntLE() * 0.0000001);
  position.setLongitude(buf.readIntLE() * 0.0000001);
  position.setAltitude(buf.readUnsignedShortLE());
  position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
  position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte());
  position.setSpeed(buf.readUnsignedShortLE() * 0.194384);
  position.setCourse(buf.readUnsignedShortLE() * 0.1);
  position.set("maximumSpeed", buf.readUnsignedByte());
  position.set("minimumSpeed", buf.readUnsignedByte());
  position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
  position.set(Position.PREFIX_IO + 1, buf.readUnsignedByte()); // supply voltage 1
  position.set(Position.PREFIX_IO + 2, buf.readUnsignedByte()); // supply voltage 2
  position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001);
  return position;
}

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

private Position parsePositionReport2(
    DeviceSession deviceSession, ByteBuf buf, int sequenceNumber, long timestamp) {
  Position position = new Position(getProtocolName());
  position.set(Position.KEY_INDEX, sequenceNumber);
  position.setDeviceId(deviceSession.getDeviceId());
  position.setTime(convertTimestamp(timestamp));
  position.setLatitude(buf.readIntLE() * 0.0000001);
  position.setLongitude(buf.readIntLE() * 0.0000001);
  buf.readUnsignedByte(); // report trigger
  position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
  short flags = buf.readUnsignedByte();
  position.setValid((flags & 0x80) == 0x80 && (flags & 0x40) == 0x40);
  position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
  position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
  return position;
}

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

private Position parseTg2Report(
    DeviceSession deviceSession, ByteBuf buf, int sequenceNumber) {
  Position position = new Position(getProtocolName());
  position.setValid(true);
  position.set(Position.KEY_INDEX, sequenceNumber);
  position.setDeviceId(deviceSession.getDeviceId());
  buf.readUnsignedShortLE(); // report trigger
  buf.readUnsignedByte(); // reserved
  buf.readUnsignedByte(); // assisted GPS age
  position.setTime(convertTimestamp(buf.readUnsignedIntLE()));
  position.setLatitude(buf.readIntLE() * 0.0000001);
  position.setLongitude(buf.readIntLE() * 0.0000001);
  position.setAltitude(buf.readUnsignedShortLE());
  position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
  position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte());
  position.setSpeed(buf.readUnsignedShortLE() * 0.194384);
  position.setCourse(buf.readUnsignedShortLE());
  position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
  position.set("maximumSpeed", buf.readUnsignedShortLE());
  position.set("minimumSpeed", buf.readUnsignedShortLE());
  position.set(Position.PREFIX_IO + 1, buf.readUnsignedShortLE()); // VSAUT1 voltage
  position.set(Position.PREFIX_IO + 2, buf.readUnsignedShortLE()); // VSAUT2 voltage
  position.set(Position.PREFIX_IO + 3, buf.readUnsignedShortLE()); // solar voltage
  position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001);
  return position;
}

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

private Position parseTrackingData(
    DeviceSession deviceSession, ByteBuf buf, int sequenceNumber, long timestamp) {
  Position position = new Position(getProtocolName());
  position.set(Position.KEY_INDEX, sequenceNumber);
  position.setDeviceId(deviceSession.getDeviceId());
  position.setTime(convertTimestamp(timestamp));
  buf.readUnsignedByte(); // tracking mode
  short flags = buf.readUnsignedByte();
  position.setValid((flags & 0x01) == 0x01);
  buf.readUnsignedShortLE(); // duration
  position.setLatitude(buf.readIntLE() * 0.0000001);
  position.setLongitude(buf.readIntLE() * 0.0000001);
  position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
  position.setCourse(buf.readUnsignedByte() * 2.0);
  position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
  position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001);
  position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
  return position;
}

相关文章

ByteBuf类方法