My PROTOBUF message design principles

Source: Internet
Author: User
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

1

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


01 Enum MSG
02 {
03 Login_request = 0x00001001;
04 Login_response = 0x00001002;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.