Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions ygnmi/gnmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,12 +517,22 @@ func populateSetRequest(req *gpb.SetRequest, path *gpb.Path, val interface{}, op
} else if s, ok := val.(string); ok && strings.HasSuffix(path.Origin, "_cli") {
typedVal = &gpb.TypedValue{Value: &gpb.TypedValue_AsciiVal{AsciiVal: s}}
} else if opt.preferProto {
typedVal, err = ygot.EncodeTypedValue(val, gpb.Encoding_JSON_IETF, &ygot.RFC7951JSONConfig{AppendModuleName: true, PreferShadowPath: preferShadowPath})
typedVal, err = ygot.EncodeTypedValue(val, gpb.Encoding_JSON_IETF, &ygot.RFC7951JSONConfig{AppendModuleName: opt.appendModuleName, PreferShadowPath: preferShadowPath})
} else {
typedVal = &gpb.TypedValue{Value: &gpb.TypedValue_JsonIetfVal{}}
// Since the GoStructs are generated using preferOperationalState, we
// need to turn on preferShadowPath to prefer marshalling config paths.
typedVal.Value.(*gpb.TypedValue_JsonIetfVal).JsonIetfVal, err = ygot.Marshal7951(val, ygot.JSONIndent(" "), &ygot.RFC7951JSONConfig{AppendModuleName: true, PreferShadowPath: preferShadowPath})
var b []byte
b, err = ygot.Marshal7951(val, ygot.JSONIndent(" "), &ygot.RFC7951JSONConfig{AppendModuleName: opt.appendModuleName, PreferShadowPath: preferShadowPath})

// Respect the encoding option.
switch opt.encoding {
case gpb.Encoding_JSON:
typedVal = &gpb.TypedValue{Value: &gpb.TypedValue_JsonVal{JsonVal: b}}
case gpb.Encoding_JSON_IETF:
fallthrough
default:
typedVal = &gpb.TypedValue{Value: &gpb.TypedValue_JsonIetfVal{JsonIetfVal: b}}
}
}

if err != nil && opt.setFallback && path.Origin != "openconfig" {
Expand Down
10 changes: 9 additions & 1 deletion ygnmi/ygnmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,15 @@
setFallback bool
sampleInterval uint64
datapointValidator ValidateFn
appendModuleName bool
ft FunctionalTranslator
}

// resolveOpts applies all the options and returns a struct containing the result.
func resolveOpts(opts []Option) *opt {
o := &opt{
encoding: gpb.Encoding_PROTO,
encoding: gpb.Encoding_PROTO,
appendModuleName: true,
}
for _, opt := range opts {
opt(o)
Expand Down Expand Up @@ -333,6 +335,12 @@
}
}

func WithAppendModuleName(append bool) Option {

Check warning on line 338 in ygnmi/ygnmi.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported function WithAppendModuleName should have comment or be unexported (revive)
return func(o *opt) {
o.appendModuleName = append
}
}

// WithFT creates an option to set a functional translator that intercepts and translates gNMI
// subscriptions and notifications.
//
Expand Down
Loading