-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
The custom codecs that Pigeon generates know how to handle the data classes generated as part of the interface. However, for some reason the generated serialization/deserialization code for classes manually calls the serialization for any data class fields. This adds unnecessary duplication/complexity to the code; we should have it just return the class at that point in the structure, not the serialization of the class, and let the codec serialize it. This will need to be done across all generators at the same time, since the two endpoints need to match, or there will be type errors.
As an example, the Dart code for AllNullableTypesWrapper in our test code is:
class AllNullableTypesWrapper {
AllNullableTypesWrapper({
required this.values,
});
AllNullableTypes values;
Object encode() {
return <Object?>[
values.encode(),
];
}
static AllNullableTypesWrapper decode(Object result) {
result as List<Object?>;
return AllNullableTypesWrapper(
values: AllNullableTypes.decode(result[0]! as List<Object?>),
);
}
}
We should be able to just have encode's array contain values instead of values.encode(), and the decode be values: result[0]! as AllNullableTypes.