Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement message set wire format #836

Merged
merged 30 commits into from
Jun 27, 2023
Merged

Implement message set wire format #836

merged 30 commits into from
Jun 27, 2023

Conversation

osa1
Copy link
Member

@osa1 osa1 commented Jun 6, 2023

Message set wire format is old and deprecated format used instead of extensions
in ancient protos.

This adds a new GeneratedMessage subclass $_MessageSet to override binary
serialization and deserialization methods for message sets. Message set
messages now extend $_MessageSet instead of GeneratedMessage.

The new class is prefixed as $_ to make the addition backwards compatible.

@osa1 osa1 requested a review from sigurdm June 6, 2023 11:24
@osa1 osa1 changed the title Implement message set format Implement support for message set wire format Jun 13, 2023
@osa1 osa1 changed the title Implement support for message set wire format Implement message set wire format Jun 13, 2023
@osa1 osa1 force-pushed the osa1/message_set branch from 989d196 to 9646a5c Compare June 13, 2023 09:44
@osa1 osa1 marked this pull request as ready for review June 13, 2023 10:16
protobuf/CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@sigurdm sigurdm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a few nits.

protobuf/CHANGELOG.md Outdated Show resolved Hide resolved
protobuf/lib/src/protobuf/message_set.dart Show resolved Hide resolved
protoc_plugin/test/message_set_test.dart Outdated Show resolved Hide resolved
protobuf/lib/src/protobuf/message_set.dart Show resolved Hide resolved
continue outer;
}
} else {
throw UnsupportedError('Invalid message set item (tag = $tagNumber)');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it is better to ignore the extra field here.

I wonder what other implementations do.

Probably OK to throw. We don't have anywhere to put unknown fields.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we could ignore the field as the encoding is basically a repeated message encoding, and when decoding messages extra fields are always OK.

OTOH if there's an extra field here it probably means some kind of non-standard behavior or a bug in the program generating the message.

No strong opinions either way..

@osa1
Copy link
Member Author

osa1 commented Jun 26, 2023

One concern here is binary sizes and runtime performance when the new class is not used.

For binary sizes I checked a large internal dart2js app that currently does not use message sets. The binary size increased 0.007% so that should be OK. I don't know yet why the size increased though. Because the difference is so small I suspect it may just be some non-determinism in compilation.

For runtime performance I checked the benchmarks in the repo. The binaries before and after this PR are identical, so it seems like at least for small apps that don't use the feature there will be no difference in generated code and runtime performance.

@osa1 osa1 merged commit 2996e1d into google:master Jun 27, 2023
@osa1 osa1 deleted the osa1/message_set branch June 27, 2023 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants