decodeFrame function

(int, Uint8List) decodeFrame(
  1. String hex
)

Implementation

(int, Uint8List) decodeFrame(String hex) {
  if (hex.length < 12) {
    throw FormatException(
      'Frame hex must be at least 12 characters (6 header bytes), '
      'got ${hex.length}',
    );
  }
  final bytes = fromHex(hex);
  final bd = ByteData.sublistView(bytes);
  final msgType = bd.getUint16(0, Endian.big);
  final payloadLength = bd.getUint32(2, Endian.big);
  final payload = Uint8List.sublistView(bytes, 6, 6 + payloadLength);
  return (msgType, payload);
}