Skip to content

Instantly share code, notes, and snippets.

@songx23
Created July 6, 2022 05:29
Show Gist options
  • Save songx23/ceb155b8476e9e635dac4c0409b6ffc2 to your computer and use it in GitHub Desktop.
Save songx23/ceb155b8476e9e635dac4c0409b6ffc2 to your computer and use it in GitHub Desktop.
Conversion between Go structure and binary data using Protobuf
// Convert from Go structure to binary data
b := protobuf.Book{
Name: "1984",
Author: "George Orwell",
Genre: "Dystopian",
Rating: 10,
}
binBook, err := proto.Marshal(&b)
// Convert from binary data to Go structure
var nativeBook protobuf.Book
err := proto.Unmarshal(rawData, &nativeBook)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment