Guest User

Untitled

a guest
Nov 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. syntax = "proto3";
  2. package apple;
  3.  
  4. message Message {
  5. repeated int32 id = 1;
  6. string name = 2;
  7. wife mywife = 3;
  8.  
  9. enum phonetype
  10. {
  11. INVALID = 0;
  12. MOBILE = 1;
  13. HOME = 2;
  14. }
  15. phonetype type = 4;
  16. }
  17.  
  18. message wife
  19. {
  20. string her_name = 1;
  21. int32 age = 2;
  22. enum sex
  23. {
  24. INVALID = 0;
  25. FEMALE =1;
  26. MALE=2;
  27. }
  28. sex orient = 3;
  29. }
  30.  
  31. using namespace google::protobuf;
  32. using namespace std;
  33.  
  34. int main(int argc, char const *argv[]) {
  35. apple::Message msg;
  36. msg.add_id(77);
  37. msg.set_name("xyz");
  38. auto w_msg = make_shared<apple::wife>();
  39. w_msg->set_her_name("abc");
  40. w_msg->set_age(88);
  41. w_msg->set_orient(apple::wife::MALE);
  42. msg.set_allocated_mywife(w_msg.get());
  43. cout << w_msg->her_name();
  44. return 0;
  45. }
Add Comment
Please, Sign In to add comment