deserializePayload method

  1. @override
int deserializePayload(
  1. UsblConfigBuilder builder,
  2. ByteData byteData,
  3. Endian endianness,
  4. int offset,
)
override

Call to deserialize only the payload, no header. The Builder is to allow passing the message to build into. returns a int with a serialized size

Implementation

@override
int deserializePayload(imc.UsblConfigBuilder builder, ByteData byteData,
    Endian endianness, int offset) {
  var byteOffset = offset;

  // field op
  builder.op = imc.UsblConfigEnumOp(byteData.getUint8(byteOffset));
  byteOffset += 1;
  // field modems
  var modemsMMsgsNumber = byteData.getUint16(byteOffset, endianness);
  byteOffset += 2;
  builder.modems = [];
  for (var i = 0; i < modemsMMsgsNumber; i++) {
    var modemsSId = byteData.getUint16(byteOffset, endianness);
    byteOffset += 2;
    if (modemsSId != imc.ImcId.nullId) {
      var pMsgBuilder = imc.messagesBuilders[
              imc.idsToMessages[modemsSId] ?? imc.ImcId.nullId.toString()]
          ?.call()
          .newInstance(builder);
      var pMsgSerializer = imc.messagesSerializers[
              imc.idsToMessages[modemsSId] ?? imc.ImcId.nullId.toString()]
          ?.call();
      if (pMsgBuilder != null && pMsgSerializer != null) {
        var mPSize = pMsgSerializer.deserializePayload(
            pMsgBuilder, byteData, endianness, byteOffset);
        byteOffset += mPSize;
        builder.modems.add(pMsgBuilder.build() as imc.UsblModem);
      }
    }
  }

  return byteOffset - offset;
}