Skip to content

1.1 Multiple encoding methods: Type Encoding Format #36

@streetycat

Description

@streetycat

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.

  1. 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 Buffer one by one in a certain order.

  2. Protobuf

    Using Protobuf encoding, while taking into account certain space efficiency and scalability, this is the encoding method selected by most complex types.

    When using Protobuf encoding, the type designer only needs to assign each field of the object to the corresponding Protobuf type, and then use the Protobuf method to encode and decode. Compatibility processing needs to refer to the Protobuf specification.

    ** Note: The Protobuf specification we chose is Proto3, considering backward compatibility, the Protobuf version 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. **

  3. JSON

    Encoded in JSON, which is less space efficient but more readable.

    Because of its low space efficiency, the JSON method is usually not selected to encode and decode information. JSON encoding 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. **

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions