decodeValue method

  1. @override
Map decodeValue(
  1. Pipe x,
  2. CType t
)
override

Implementation

@override
Map decodeValue(Pipe x, CType t) {
  final record = checkType(t);

  if (record is RecordClass || record is TupleClass) {
    final r = {};
    var idx = 0;
    var fields = (record is RecordClass)
        ? record.fields
        : (record as TupleClass).fields;
    for (var entry in fields) {
      var hash = entry.key;
      var type = entry.value;
      // [hash, type]
      if (idx >= _fields.length ||
          idlLabelToId(_fields[idx].key) != idlLabelToId(hash)) {
        // skip field
        entry.value.decodeValue(x, type);
        continue;
      }
      var expectedEntry = _fields[idx];

      var expectKey = expectedEntry.key, expectType = expectedEntry.value;
      r[expectKey] = expectType.decodeValue(x, type);
      idx++;
    }
    if (idx < _fields.length) {
      throw 'Cannot find field ${_fields[idx].key}';
    }
    return r;
  } else {
    throw 'Not a record type';
  }
}