parseODIDMessage<T extends ODIDMessage> function

T? parseODIDMessage<T extends ODIDMessage>(
  1. Uint8List messageData
)

Parses ODID message from array of raw bytes messageData. Optional parameter T can constrain the expected message type. In case the specified type does not match parsed message type, null is returned.

Implementation

T? parseODIDMessage<T extends ODIDMessage>(Uint8List messageData) {
  final messageType = determineODIDMessageType(messageData);

  if (T != ODIDMessage && messageType is! T) {
    // TODO or throw here instead of null?
    return null;
  }

  // Check that message length is exactly 25 bytes for standard message (not message pack)
  if (messageType != MessagePack && messageData.length != maxMessageSize) {
    return null;
  }

  final parser = _parserMapping[messageType];

  if (parser == null) {
    return null;
  }

  return parser.parse(messageData) as T?;
}