Add PathAndStruct helper for generated non-leaf PathStruct types.#533
Add PathAndStruct helper for generated non-leaf PathStruct types.#533
Conversation
A common use case is where a user would like to construct a path and populate its corresponding `GoStruct` at the same time. This helper obviates the need to retrieve the struct using the `GetOrCreateXXX` functions on top of using the path API.
| if err := goPathStructTemplate.Execute(&structBuf, structData); err != nil { | ||
| return GoPathStructCodeSnippet{}, util.AppendErr(errs, err) | ||
| } | ||
| if err := goPathAndStructHelperTemplate.Execute(&structBuf, structData); err != nil { |
There was a problem hiding this comment.
Should generating the path and struct helper be optional? In general we've tried to have these other features that are new types of output flag-controlled in the library - even if we have it as on by default, it'd probably be nice to have something whereby a user can turn this off if they don't want it to save on generated code size.
| *ygot.NodePath | ||
| } | ||
|
|
||
| // PathAndStruct returns the path struct and an empty oc.List for the path "/root-module/list-container/list". |
There was a problem hiding this comment.
This is interesting -- for YANG container types it seems pretty clear to just return the struct, but in the case I call this with pathlib.ListContainer().ListAny().PathAndStruct() should I get back oc.List{} or map[...]*oc.List{}?
|
One alternative is for Replace on an intermediate node to always construct a new value and accept a lambda that can modify it, e.g. Not advocating for it, just thinking through the options. |
|
Wen, is this change defunct at this point -- or should we try and merge it? |
greg-dennis
left a comment
There was a problem hiding this comment.
I think maybe we should include this in the space of changes that will be considered for a merged/revised gNMI API in H1. At this point, this feels a little too much of a piecemeal contribution to me, and we might benefit from incorporating it into the more holistic look that is planned.
|
When generics is ready a better design for this might be just to provide the function |
A common use case is where a user would like to construct a path and populate its corresponding
GoStructat the same time. This helper obviates the need to retrieve the struct using theGetOrCreateXXXfunctions on top of using the path API.This can be convenient for long paths such as the following example:
Before
After
This helper is not generated for leaves, since their types can be accessed using
ygothelper functions such asygot.Int32().