In the previous article, " Main Process Promotion Strategy (4): TCP, Message Subcontracting and Protocol Design ", I talked about some topics of protocol design. Here, I will add the comparison between HTTP protocol and binary protocol.
The HTTP protocol is a text protocol and a Name-Based protocol, in terms of these two aspects.
Text Protocol vs Binary Protocol
Features of the text protocol:
easy for people
Easy to read, understand, debug, construct
The analysis is complex and redundant
Character escaping needs to be considered
Features of the binary protocol:
easy to machine
Name-Based vs Position-Based
Features of Name-Based Protocol:
Protocol fields are identified by Name
The protocol field is position independent
The protocol field can be defaulted
It is convenient to add a new protocol field
Parsing is complex
Character escaping needs to be considered
Features of Position-Based Protocol:
Each protocol field has a specific location
Adding protocol fields requires protocol version management ( protobuf is good)
More efficient parsing