decodeValue method

  1. @override
Map<String, dynamic> decodeValue(
  1. Pipe x,
  2. CType t
)
override

Implementation

@override
Map<String, dynamic> decodeValue(Pipe x, CType t) {
  final variant = checkType(t);
  if (variant is! VariantClass) {
    throw ArgumentError.value(t, 't', 'Not a valid variant type');
  }
  final idx = lebDecode(x).toInt();
  if (idx >= variant._fields.length) {
    throw RangeError.index(
      idx,
      variant._fields.length,
      'variant index',
      'Invalid variant index: $idx',
    );
  }
  final entry = variant._fields[idx];
  final wireHash = entry.key, wireType = entry.value;
  for (final fEntry in _fields) {
    final key = fEntry.key, expectType = fEntry.value;
    if (idlLabelToId(wireHash) == idlLabelToId(key)) {
      final value = expectType.decodeValue(x, wireType);
      return {key: value};
    }
  }
  throw StateError('cannot find field hash $wireHash.');
}