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

EmitJSON/ConstructJSON/Marshal7951 support for structs containing ordered maps. #825

Merged
merged 10 commits into from
May 23, 2023

Conversation

wenovus
Copy link
Collaborator

@wenovus wenovus commented Apr 28, 2023

Note: ordered maps themselves cannot be processed by these functions (aside from Marshal7951 which can).

Ideally Go supports type constraints of unions of interfaces but it
doesn't, and I think it is too early to change the input parameters of
these functions from ygot.GoStruct -> interface{} or add even more
methods to achieve what ygnmi does with the query types -- which would
bloat the generated code for a small gain which might not be so useful
right now.

wenovus and others added 6 commits April 28, 2023 11:30
Initially I made the choice to use a non-pointer so that the user would
not need to initialize this field before using it.

The advantage is all methods can hang off of the type rather than
needing methods to hang off the parent type in order to nil-check and
initialize.

However, this creates problems that a pointer field solves:
1. Avoid needing value-receivers in order to make the field satisfy
   certain interfaces (e.g. ygot.GoStruct). Mixing receiver types is
   confusing for the reader.
2. Helps avoid awkward reflection code that need to access the pointer
   receiver methods since `CanAddr()=false` for non-pointer objects:
   https://go.dev/play/p/5vYVVUS-GfD
3. Users of ygot are used to declaring every struct as pointers, so
   using pointers makes things congruent with existing generated code.
…containing ordered maps.

Note: ordered maps themselves cannot be processed by these functions.

Ideally Go supports type constraints of unions of interfaces but it
doesn't, and I think it is too early to change the input parameters of
these functions from ygot.GoStruct -> interface{} or add even more
methods to achieve what ygnmi does with the query types -- which would
bloat the generated code for a small gain which might not be so useful
right now.
@wenovus wenovus requested review from DanG100 and bormanp April 28, 2023 23:46
@coveralls
Copy link

coveralls commented Apr 28, 2023

Coverage Status

Changes Unknown when pulling afe4ab1 on ordered-map-emitjson into ** on master**.

@wenovus wenovus changed the title EmitJSON/ConstructIETFJSON/ConstructInternalJSON support for structs containing ordered maps. EmitJSON/ConstructJSON/Marshal7951 support for structs containing ordered maps. Apr 29, 2023
@wenovus wenovus merged commit 28581a1 into master May 23, 2023
@wenovus wenovus deleted the ordered-map-emitjson branch May 23, 2023 17:36
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.

3 participants