serializePayload method
Call to serialize only the payload, no header, returns a int with a serialized size
Implementation
@override
int serializePayload(imc.Event? message, ByteData byteData, int offset) {
if (message == null) return 0;
var byteOffset = offset;
// field topic
var topicEncoded = utf8.encode(message.topic);
var topicSSize = topicEncoded.length;
byteData.setUint16(byteOffset, topicSSize, imc.endianSer);
byteOffset += 2;
for (var b in topicEncoded) {
byteData.setUint8(byteOffset++, b);
}
// field data
var dataEncoded = utf8.encode(message.data);
var dataSSize = dataEncoded.length;
byteData.setUint16(byteOffset, dataSSize, imc.endianSer);
byteOffset += 2;
for (var b in dataEncoded) {
byteData.setUint8(byteOffset++, b);
}
return byteOffset - offset;
}