proto2

package module
v0.0.0-...-811a46b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2023 License: MIT Imports: 7 Imported by: 0

README

Protobuf to Go struct literal conversion

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.

Example

// 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{},
}

Install

go get -u github.com/meling/proto2

License

MIT -- see LICENSE file

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoStruct

func GoStruct(m proto.Message) string

GoStruct returns a Go struct literal for the given proto.Message.

Types

This section is empty.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL