Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does golang provide an easy way to output human readable protobuf

Is there a good way to get a human readable string representation of protobuf objects in golang? Something equivalent to https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.message#Message.DebugString?

I am using https://github.com/golang/protobuf.

like image 751
Charles L. Avatar asked Feb 19 '16 21:02

Charles L.


People also ask

How do I create a Protobuf file in Golang?

There are two requirements for the full process. protoc binary installed on your path go get -u github.com/gogo/protobuf/... You can generate the proto files, the marshal/unmarshal and the rest of protobuf stuff for your Go types, the RPC client and server interface and the RPC server implementation for your packages.

What is PB in Golang?

func (pb *ProgressBar) Prefix(prefix string) *ProgressBar.

Why is Protobuf faster?

Protobuf, on the other hand, usually compresses data better and has built-in protocol documentation via the schema. Another major factor is the CPU performance — the time it takes for the library to serialize and deserializes a message. In this post, we want to compare just the performance in JavaScript.


1 Answers

I believe you're looking for proto.MarshalTextString.

p := &example.Test{
  Label: proto.String("this"),
  Reps:  []int64{4, 3, 2, 1},
  InnerTest: &example.Test_InnerTest{
    InnerLabel: proto.String("is the end"),
  },
}

fmt.Println(proto.MarshalTextString(p))

You can see an example in the Go package test.

like image 122
Pascal Corpet Avatar answered Oct 03 '22 09:10

Pascal Corpet