deserialize method
Call to deserialize the all message
Implementation
@override
imc.ButtonEvent? deserialize(Uint8List data, [int offset = 0]) {
var byteOffset = offset;
var byteData = data.buffer.asByteData(offset);
var (endianness, _) = imc.getEndianness(byteData, byteOffset);
byteOffset += 2;
if (endianness == null) {
return null;
}
var msgId = byteData.getUint16(byteOffset, endianness);
byteOffset += 2;
if (msgId != imc.ButtonEvent.staticId) {
return null;
}
var builder = imc.ButtonEventBuilder();
var payloadSize =
imc.deserializeHeader(builder, byteData, endianness, offset);
if (payloadSize == null) {
return null;
}
byteOffset = offset + imc.headerSize;
var calcCrc = imc.calcCrc(byteData, offset, imc.headerSize + payloadSize);
var readCrc = imc.getCrcFooter(
byteData, offset + imc.headerSize + payloadSize, endianness);
if (calcCrc != readCrc) {
return null;
}
// Payload
int payloadSizeRead;
try {
payloadSizeRead =
deserializePayload(builder, byteData, endianness, byteOffset);
} catch (_) {
return null;
}
// End payload
if (payloadSizeRead != payloadSize) {
return null;
}
byteOffset = offset + imc.headerSize + payloadSize;
return builder.build();
}