encodeType static method

String encodeType(
  1. String primaryType,
  2. Map<String, List<TypedDataField>> types
)

Encodes the type of an object by encoding a comma delimited list of its members

Implementation

static String encodeType(
    String primaryType, Map<String, List<TypedDataField>> types) {
  var result = '';
  final unsortedDeps = findTypeDependencies(primaryType, types)
    ..removeWhere((type) => type == primaryType);
  var deps = [primaryType, ...List.of(unsortedDeps)..sort()];
  deps.forEach((type) {
    if (!types.containsKey(type)) {
      throw new ArgumentError('No type definition specified: ' + type);
    }
    result +=
        "${type}(${types[type]!.map((field) => '${field.type} ${field.name}').join(',')})";
  });
  return result;
}