innerDecodeAndCollect method
dynamic
innerDecodeAndCollect()
Implementation
innerDecodeAndCollect(
Input input, TypeRef typeRef, Map<int, List<int>> idToLookups, Set<int> collected) {
if (typeRef.tag != 'perId') {
skipTypeRef(typeRef, input);
return;
}
void handleTypeRef(TypeRef typeRef) {
innerDecodeAndCollect(input, typeRef, idToLookups, collected);
}
final lookupIdxs = idToLookups[typeRef.value]!;
final currentIdx = lookupIdxs[0];
final current = lookup[currentIdx];
if (lookupIdxs.length == 1) {
collected.add(currentIdx);
}
switch (current.typeDef.tag) {
case 'enumeration':
final selectedIdx = U8Codec.codec.decode(input);
final result =
lookupIdxs.map((lookupIdx) => [lookup[lookupIdx].typeDef, lookupIdx]).firstWhere((x) {
final variant = x[0] as LookupTypeDef;
return variant.value.index == selectedIdx;
});
final collectedIdx = result[1] as int;
collected.add(collectedIdx);
final selected = result[0] as LookupTypeDef;
selected.value.fields.forEach((field) {
handleTypeRef(field.ty);
});
break;
case 'sequence':
final len = CompactBigIntCodec.codec.decode(input).toInt();
for (var i = 0; i < len; i++) {
handleTypeRef(current.typeDef.value);
}
break;
case 'array':
for (var i = 0; i < current.typeDef.value.len; i++) {
handleTypeRef(current.typeDef.value.typeParam);
}
break;
case 'composite':
current.typeDef.value.fields.forEach((e) => handleTypeRef(e.ty));
break;
case 'tuple':
current.typeDef.value.forEach((e) => handleTypeRef(e));
break;
case 'bitSequence':
throw Exception('bitSequence is not supported');
}
}