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

Add the DescSet type #745

Merged
merged 10 commits into from
Mar 13, 2024
Merged

Add the DescSet type #745

merged 10 commits into from
Mar 13, 2024

Conversation

timostamm
Copy link
Member

Introduce the type DescSet, a set of descriptors with convenient accessors to look up descriptors by name.
This type is the successor to DescriptorSet and registries, and combines the features of both.

For example, if generated files exports the messages User and Foo, a set of the descriptors can be created with:

// before:
const reg = createRegistry( User, Foo );

// now:
const set = createDescSet( UserDesc, FooDesc );

To create a set of descriptors from a google.protobuf.FileDescriptorSet message:

declare const fileDescriptorSet: FileDescriptorSet;

// before:
const set = createDescriptorSet( fileDescriptorSet );

// now:
const set = createDescFileSet( fileDescriptorSet );

This creates a DescSet that also includes file descriptors, a DescFileSet. The old function createDescriptorSet() and the interface DescriptorSet are not removed by this PR, and continue to work as expected.

Descriptor sets can be merged by passing multiple input sets to the variadic function createDescSet() or createDescFileSet():

const a = createDescSet( UserDesc, FooDesc );
const b = createDescriptorSet( fileDescriptorSet );
const set = createDescSet( a, b );

This feature makes it trivial to create "registries" from multiple generated file descriptors. If a descriptor is given multiple times (identified by the same type name), the one given last wins.

@timostamm
Copy link
Member Author

(This is based on #743, which needs to be merged first.)

Base automatically changed from tstamm/embed-descriptors to v2 March 13, 2024 13:02
@timostamm timostamm merged commit a57887e into v2 Mar 13, 2024
5 checks passed
@timostamm timostamm deleted the tstamm/desc-set branch March 13, 2024 13:34
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