decodePacketHeader static method

Tuple2<int, int> decodePacketHeader(
  1. Uint8List buffer
)

Implementation

static Tuple2<int, int> decodePacketHeader(Uint8List buffer) {
  final byteData = ByteData.sublistView(buffer);
  int offset = 0;

  // payloadLength
  var db = ByteData(4)
    ..setUint8(0, buffer[0])
    ..setUint8(1, buffer[1])
    ..setUint8(2, buffer[2])
    ..setUint8(3, 0);

  final payloadLength = db.getUint32(0, Endian.little);
  offset += 3;

  // sequence number
  final sequenceNumber = byteData.getUint8(offset);

  return Tuple2(payloadLength, sequenceNumber);
}