toBuffer method

List<int> toBuffer()

Converts the protocol buffer data to a byte buffer.

Implementation

List<int> toBuffer() {
  if (values.length != fieldIds.length) {
    throw TronPluginException(
        "The values and field IDs must have the same length.",
        details: {
          "values": values,
          "fieldIds": fieldIds,
          "class": runtimeType.toString()
        });
  }
  final bytes = DynamicByteTracker();
  for (int i = 0; i < values.length; i++) {
    final value = values[i];
    final tagNumber = fieldIds[i];
    List<int> encode;
    if (value == null) continue;
    if (value is TronBaseContract) {
      encode = ProtocolBufferEncoder.encode(tagNumber, value.toBuffer());
    } else if (value is TronEnumerate) {
      encode = ProtocolBufferEncoder.encode(tagNumber, value.value);
    } else {
      encode = ProtocolBufferEncoder.encode(tagNumber, value);
    }
    bytes.add(encode);
  }
  return bytes.toBytes();
}