doDecode static method

NDEFRecord doDecode(
  1. TypeNameFormat tnf,
  2. Uint8List type,
  3. Uint8List payload, {
  4. Uint8List? id,
  5. TypeFactory typeFactory = NDEFRecord.defaultTypeFactory,
})

Decode a NDEFRecord record from raw data.

Implementation

static NDEFRecord doDecode(
    TypeNameFormat tnf, Uint8List type, Uint8List payload,
    {Uint8List? id,
    TypeFactory typeFactory = NDEFRecord.defaultTypeFactory}) {
  var record = typeFactory(tnf, utf8.decode(type));
  if (payload.length < record.minPayloadLength) {
    throw ArgumentError(
        "Payload length must be >= ${record.minPayloadLength}");
  }
  if (record.maxPayloadLength != null &&
      payload.length < record.maxPayloadLength!) {
    throw ArgumentError(
        "Payload length must be <= ${record.maxPayloadLength}");
  }
  record.id = id;
  record.type = type;
  // use setter for implicit decoding
  record.payload = payload;
  return record;
}