The proto2
package provides a single function GoStruct()
that returns a Go struct literal representation of a protobuf message.
This can be handy if you want to generate Go code from a protobuf message.
// msg is an arbitrary protobuf message
msg := &hotstuff.Proposal{
Block: &hotstuff.Block{
Parent: []byte{1, 2, 3},
QC: &hotstuff.QuorumCert{},
View: 1,
Command: []byte{4, 5, 6},
Proposer: 2,
},
AggQC: &hotstuff.AggQC{},
}
fmt.Println(proto2.GoStruct(msg))
This produces the following output:
&hotstuff.Proposal{
Block: &hotstuff.Block{
Parent: []byte{1, 2, 3},
QC: &hotstuff.QuorumCert{},
View: 1,
Command: []byte{4, 5, 6},
Proposer: 2,
},
AggQC: &hotstuff.AggQC{},
}
go get -u github.com/meling/proto2
MIT -- see LICENSE file