encodeNdefMessage function
Encode an NDEF message (containing several NDEFRecords) to byte array.
Set canonicalize
to set the MB and ME fields automatically in the first / last record.
Implementation
Uint8List encodeNdefMessage(List<NDEFRecord> records,
{bool canonicalize = true}) {
if (records.isEmpty) {
return Uint8List(0);
}
for (var r in records) {
r.flags.resetPositionFlag();
}
if (canonicalize) {
records.first.flags.MB = true;
records.last.flags.ME = true;
}
var encoded = <int>[];
for (var r in records) {
encoded.addAll(r.encode());
}
return Uint8List.fromList(encoded);
}