my original PROTOBUF message design principlesPublished 3 months ago (2013-09-04-15:58) Read (392) | Comments (5)
TenPeople to collect this article, I want to collect praise 0 C + + protobuf
directory [-] 1. An enum using PROTOBUF is set to the number of the message, which is the type of message. 2. A corresponding PROTOBUF message is defined for each messages that have a message body. For example, Login_request will have a corresponding loginrequest message. 3. A message is defined for each message class, for example, the command messages are all contained in the message command, all of the request messages are contained in a request messages, all of the answer messages are contained in the response message, indicating that the message is all contained in the indication message. 4. For answer messages, it is not always successful, so there are another 2 fields in the answer message. One that describes the success of the answer and a string message describing the failure. For messages with multiple replies, it is possible to include the identity of the last reply message. The sequence number of the answer (similar to the packet being split with the network packet, when the protocol is to be merged, you need to know where the fragment is in the package). So response looks like this: 5. Finally, I will define a big message, the command, Request, Response, indication all packaged together, so that after the communication are moving big message began to codec. The big news looks like this. 6. Send data and receive data. 6. Message processing (c + +) 7. Wireshark Grab Bag
Network traffic involves the definition of a message, whether using binary schemas, XML, JSON, and so on. Messages can be roughly divided into command messages, request messages, answer messages, and message types indicating messages 4. In general, each message also contains a serial number and a message number that can uniquely differentiate between type types, using strings, integers, or enumerations. 1. An enum using PROTOBUF is set to the number of the message, which is the type of message.
I will define a MSG enumeration for each system. Enumeration number containing all messages used by the system
| 03 |
Login_request = 0x00001001; |
| 04 |
Login_response = 0x00001002; |