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) {
    throw ArgumentError.value(t, 't', 'Not a record type.');
  }
  final r = <dynamic, dynamic>{};
  int idx = 0;
  final fields =
      record is RecordClass ? record.fields : (record as TupleClass).fields;
  for (final entry in fields) {
    final hash = entry.key;
    final type = entry.value;
    // [hash, type]
    if (idx >= _fields.length ||
        idlLabelToId(_fields[idx].key) != idlLabelToId(hash)) {
      // skip field
      entry.value.decodeValue(x, type);
      continue;
    }
    final expectedEntry = _fields[idx];
    final expectKey = expectedEntry.key, expectType = expectedEntry.value;
    r[expectKey] = expectType.decodeValue(x, type);
    idx++;
  }
  if (idx < _fields.length) {
    throw RangeError.index(
      idx,
      _fields.length,
      'idx',
      'Cannot find field ${_fields[idx].key}',
    );
  }
  return r;
}