package main import ( "fmt" "github.com/golang/protobuf/proto" ) type Person struct { Name string Age int32 } func main() { p := &Person{ Name: "John", Age: 30, } buffer := proto.NewBuffer(nil) buffer.Marshal(p) encoded := buffer.Bytes() fmt.Println(encoded) }
package main import ( "fmt" "github.com/golang/protobuf/proto" ) type Person struct { Name string Age int32 } func main() { encoded := []byte{10, 4, 74, 111, 104, 110, 16, 30} p := &Person{} buffer := proto.NewBuffer(encoded) buffer.Unmarshal(p) fmt.Println(p.Name, p.Age) }In this example, we decode a Person struct from a byte slice using a Buffer. The decoded values are then printed to the console.