getPayloadLength static method

int getPayloadLength(
  1. Uint8List message,
  2. int headerLength, {
  3. dynamic offset = 0,
})

calculates the message payload length for a given headerLength

Implementation

static int getPayloadLength(Uint8List message, int headerLength,
    {offset = 0}) {
  if (message.length >= headerLength) {
    if (headerLength == 5) {
      return (message[offset + 1] & 0xFF) << 24 |
          (message[offset + 2] & 0xFF) << 16 |
          (message[offset + 3] & 0xFF) << 8 |
          (message[offset + 4] & 0xFF);
    } else {
      return (message[offset + 1] & 0xFF) << 16 |
          (message[offset + 2] & 0xFF) << 8 |
          (message[offset + 3] & 0xFF);
    }
  }
  return 0;
}