Closed hellt closed 4 years ago
By default, marshalling to textproto will leave out fields that are set to their default value. This will be the case when you set encoding
to JSON``, or leave an empty set of fields in
use_modelsor
path`.
Please see the small program here that demonstrates this:
package main
import (
"fmt"
gpb "github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/ygot/ygot"
"google.golang.org/protobuf/encoding/prototext"
)
func main() {
// Prints an empty message
p := &gpb.GetRequest{Path: []*gpb.Path{}}
fmt.Printf("%s\n", prototext.Format(p))
// Prints a populated Path field.
if pp, err := ygot.StringToStructuredPath("/interfaces/interface[name=eth0]/state/oper-status"); err == nil {
p.Path = []*gpb.Path{pp}
}
fmt.Printf("%s\n", prototext.Format(p))
// Doesn't print the encoding field
p.Encoding = gpb.Encoding_JSON
fmt.Printf("%s\n", prototext.Format(p))
// Prints the encoding field
p.Encoding = gpb.Encoding_ASCII
fmt.Printf("%s\n", prototext.Format(p))
}
Thanks @robshakir !
int32 0
, as well as DataType ALL
is mapped to 0
Closing, since there is no option to override default behavior of the text marshaller
Hi, I am trying to log a gNMI proto message contents before sending it off to the target, I thought I could use the following:
but unfortunately prototext marshaller fails to recognize (?) all of the fields for this GetRequest, since the output contains only the path information: