Skip to content

Instantly share code, notes, and snippets.

@deckarep
Created July 2, 2020 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deckarep/fcecd24e1a2d44781c7950705092461e to your computer and use it in GitHub Desktop.
Save deckarep/fcecd24e1a2d44781c7950705092461e to your computer and use it in GitHub Desktop.
Protobuf Talk: Populating and serializing a dog into bytes
package main
// to run: go run *.go
import (
fmt "fmt"
"log"
proto "github.com/gogo/protobuf/proto"
)
func main() {
d := &Dog{
OwnerId: proto.Int32(434434),
Breed: proto.String("Corgi"),
HeightIn: proto.Float32(56.6),
Color: proto.String("Brown"),
}
b, err := proto.Marshal(d)
if err != nil {
log.Fatal(err)
}
fmt.Println(b)
fmt.Println(len(b))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment