Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. // Proto messages
  2. message TestMsg
  3. {
  4. bool param = 1;
  5. }
  6.  
  7. // TEST wrapper
  8. message TheInnocentNotification
  9. {
  10. bool is_everything_ok = 1;
  11. }
  12.  
  13. message TheMessageOfDoom
  14. {
  15. bool destroy_everything = 1;
  16. }
  17.  
  18.  
  19. // The code
  20. testMsg := &protoMsg.TestMsg{
  21. Param: true,
  22. }
  23.  
  24. testMsgBin, _ := testMsg.Marshal()
  25. fmt.Printf("<%s>\n", fmtBits(testMsgBin))
  26.  
  27. innocentMsg := &protoMsg.TheInnocentNotification{}
  28. proto.Unmarshal(testMsgBin, innocentMsg)
  29.  
  30. doomMsg := &protoMsg.TheMessageOfDoom{}
  31. proto.Unmarshal(testMsgBin, doomMsg)
  32.  
  33. fmt.Println("innocentMsg", innocentMsg.GetIsEverythingOk()) // returns true
  34. fmt.Println("doomMsg", doomMsg.GetDestroyEverything()) // returns true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement