Skip to content

Instantly share code, notes, and snippets.

@psanzay
Created March 30, 2020 14:55
Show Gist options
  • Save psanzay/4cccaf8e811f267f583fad458e16d573 to your computer and use it in GitHub Desktop.
Save psanzay/4cccaf8e811f267f583fad458e16d573 to your computer and use it in GitHub Desktop.
serializing protocol buffer
person := &pb.Person{}
person.Name = "test"
.... other fields ...
out, err := proto.Marshal(person)
// writing to file
if err != nil {
log.Fatalln("Failed to encode person:", err)
}
if err := ioutil.WriteFile("phones", out, 0644); err != nil {
log.Fatalln("Failed to write person:", err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment