Created
March 14, 2019 10:33
-
-
Save styoe/eec07a2569472d697f77584ab106e9e4 to your computer and use it in GitHub Desktop.
protobuf example
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
// Proto messages | |
message TestMsg | |
{ | |
bool param = 1; | |
} | |
// TEST wrapper | |
message TheInnocentNotification | |
{ | |
bool is_everything_ok = 1; | |
} | |
message TheMessageOfDoom | |
{ | |
bool destroy_everything = 1; | |
} | |
// The code | |
testMsg := &protoMsg.TestMsg{ | |
Param: true, | |
} | |
testMsgBin, _ := testMsg.Marshal() | |
fmt.Printf("<%s>\n", fmtBits(testMsgBin)) | |
innocentMsg := &protoMsg.TheInnocentNotification{} | |
proto.Unmarshal(testMsgBin, innocentMsg) | |
doomMsg := &protoMsg.TheMessageOfDoom{} | |
proto.Unmarshal(testMsgBin, doomMsg) | |
fmt.Println("innocentMsg", innocentMsg.GetIsEverythingOk()) // returns true | |
fmt.Println("doomMsg", doomMsg.GetDestroyEverything()) // returns true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment