Skip to content

[pigeon] Simplify nested class serialization #119351

@stuartmorgan-g

Description

@stuartmorgan-g

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectp: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions