ygot icon indicating copy to clipboard operation
ygot copied to clipboard

Unable to unmarshal empty leafs within union types

Open wenovus opened this issue 4 years ago • 2 comments

#292 would fix the case for straight-up empty-type leaves. But it doesn't address unmarshalling a union leaf that contains an empty type.

  1. Is this unlikely to occur in practice?
  2. I'd prefer to only solve this for the simple union case to avoid unnecessary work.
  3. When solving this for the simple union case, an easy way would be to generate the following for the To_XXX methods, would this be acceptable, since it prevents having both YANGEmpty and bool within the same union type?:
switch v := i.(type) {
case bool:                                                                                                                   
   return YANGEmpty(v), nil
}

in addition to the obvious

func (YANGEmpty) Documentation_for_Platform_Component_Power_Union() {}

You could argue that the former is not necessary, but it really helps simplify the unmarshalling code, as otherwise it would require lots of generated code analogous to ΛEnumTypeMap in order to create the YANGEmpty type from the correct package when unmarshalling from either JSON or TypedValue.

wenovus avatar Sep 07 '21 23:09 wenovus

My personal take is that this doesn't need to be part of the v1 milestone since it doesn't introduce any backwards incompatibility issues, and is likely a corner case not usually encountered.

wenovus avatar Sep 07 '21 23:09 wenovus

This issue is only relevant when unmarshalling JSON. When unmarshalling a TypedValue, YANGEmpty and bool are indistinguishable from one another in their encoding.

wenovus avatar Sep 10 '21 01:09 wenovus