-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Multiple encoding methods
All information based on CYFS can choose one of the following three encoding methods. Both Protobuf and JSON have their standard encoding specifications. I won’t go into details here. We only introduce the binary encoding format.
-
Binary
Binary format encoding, usually used for standardized fixed encoding, the most space-saving, but not easy to expand.
When binary encoding is selected, the type designer needs to fill all fields into a
Bufferone by one in a certain order. -
Protobuf
Using
Protobufencoding, while taking into account certain space efficiency and scalability, this is the encoding method selected by most complex types.When using
Protobufencoding, the type designer only needs to assign each field of the object to the correspondingProtobuftype, and then use theProtobufmethod to encode and decode. Compatibility processing needs to refer to theProtobufspecification.** Note: The
Protobufspecification we chose isProto3, considering backward compatibility, theProtobufversion is unlikely to be upgraded. Of course, other versions can be selected for the type of new design, but different versions need to be carefully introduced. ** -
JSON
Encoded in
JSON, which is less space efficient but more readable.Because of its low space efficiency, the
JSONmethod is usually not selected to encode and decode information.JSONencoding usually appears in the scene of human-computer interaction.
** No matter which encoding method you choose, you must pay attention to the stability of the encoding when you use it for object encoding (for example: Set and Map should pay attention to the order of each element), otherwise the ObjectId obtained by calculating the same content multiple times may be different. **