http文本消息体比较

在传输 HTTP 消息中,最常用的是JSON,但JSON易读却占用空间大,大消息体 & 小带宽情况下无疑会增加响应时长;简单的解决方案可以是:
  1. 开启gzip
  2. 序列化
两种方案[1]比较结果
格式 大小(bytes
JSON 000434409
MsgPack 000333941
GZip+MsgPack 000189057
GZip+JSON 000177976
LZ4+MsgPack 000239656
LZ4+JSON 000264572

常用消息体

  1. application/json|xml
  2. text/plain|css|html|javascript|xml|csv

序列化

MessagePack

MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it's faster and smaller. Small integers are encoded into a single byte, and typical short strings require only one extra byte in addition to the strings themselves.

ProtoBuffer

可以理解成格式写入在 .proto 文件中,Client/Server端都需要该文件,通信的时候只需要传数据即可。 灵活性 - -

Date:
Words:
296
Time to read:
1 min