What is ProtoBuf serialization
This article focuses on "what is ProtoBuf serialization", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what ProtoBuf serialization is.
Performance comparison
Tool name
It takes time to perform 100 reads and writes
1000 times
10000 times
Native serialization
3451ms
34635ms
331201ms
Protobuff serialization
2860ms
28286ms
295272ms
Conclusion
The performance of ProtoBuf is better than that of Java native serialization.
ProtoBuf serialization stores only the value of the field, and sets the value of the property in order, so to add the attribute, be sure to put it on the last one, and if you delete the attribute, you need to set the order of the property.
Cdn.nlark.com/lark/0/2018/png/128761/1545290719552-e4b15a8f-5884-45a0-9f7b-b4000b16f6ff.png ">
Java native serialization needs to implement the Serializable interface, set the serialVersionUID, including inherited parents, to prevent property change deserialization errors.
ProtoBuf serialization
If field does not set Tag annotations, fieldMapping is set from 1, in the order in which the attributes are defined
Set the value of each attribute serial number number
ProtoBuf deserialization
Set the value according to the number of the property
Therefore, if you need to add attributes, be sure to add them later. Generally, it is not recommended to delete attributes. If you delete attributes, you need to set Tag annotations to prevent attribute assignment errors. If Tag annotations are added to attributes, then all properties in this class must add Tag annotations, including inherited parent classes.
At this point, I believe you have a deeper understanding of "what is ProtoBuf serialization", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!