c_forwards function

Uint8List c_forwards(
  1. List<CandidType> candids
)

Serialize a List of CandidTypes into the binary over-the-wire format.

Implementation

Uint8List c_forwards(List<CandidType> candids) {
    candids.forEach((CandidType c){ if (c.type_mode==true) { throw Exception('c_forwards must be with the candids of the type_mode=false'); }});
    List<int> candidbytes = magic_bytes.toList();
    List<int> params_list_types_bytes_section = [];
    List<int> params_list_values_bytes_section = [];
    for (CandidType candid in candids) {
        params_list_types_bytes_section.addAll(candid._T_forward()); // sleb128-bytes() of either primtype -opcode or type_table_i    // composite-types (types with a T-function that has more data/parameters beside the opcode) use the type_table_forward list for the T function to put the types and gives back the type_table_i-leb128-code-bytes.
        params_list_values_bytes_section.addAll(candid._M_forward());
    }
    candidbytes.addAll(leb128.encodeUnsigned(BigInt.from(type_table_forward.length)));
    for (List<int> type_bytes in type_table_forward) { candidbytes.addAll(type_bytes); }
    candidbytes.addAll(leb128.encodeUnsigned(BigInt.from(candids.length)));
    candidbytes.addAll(params_list_types_bytes_section);
    candidbytes.addAll(params_list_values_bytes_section);
    type_table_forward.clear();
    return Uint8List.fromList(candidbytes);
}