buildMacData method
Packs the selected fields, unpacks them again, then concatenates the normalised values. The round trip is what makes the terminal and the host agree on padding.
Implementation
Uint8List buildMacData(IsoMsg message) {
final IsoMsg applied = IsoMsg();
for (final int field in selectedFields) {
final IsoComponent<Object>? component = message.getComponent(field);
if (component != null) applied.setComponent(field, component);
}
applied.setComponent(0, message.getComponent(0));
applied.markDirty();
applied.recalcBitMap();
final IsoBuffer buffer = IsoBuffer.allocate(9999);
_packager.pack(applied, buffer);
buffer.flip();
_packager.unpack(applied, buffer);
applied.setComponent(0, message.getComponent(0));
final List<int> out = <int>[];
for (final int field in selectedFields) {
final IsoComponent<Object>? component = applied.getComponent(field);
if (component == null) continue;
final Object? value = component.value;
if (value is Uint8List) {
out.addAll(value);
} else if (value is String) {
out.addAll(value.codeUnits.map((int unit) => unit & 0xFF));
}
}
return Uint8List.fromList(out);
}