Created
July 6, 2022 05:29
-
-
Save songx23/ceb155b8476e9e635dac4c0409b6ffc2 to your computer and use it in GitHub Desktop.
Conversion between Go structure and binary data using Protobuf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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