当前位置:网站首页>A tour of grpc:03 - proto serialization / deserialization
A tour of grpc:03 - proto serialization / deserialization
2022-07-07 17:15:00 【InfoQ】
In the last one , We installed and configured protoc, Write some simple message, And use protoc Automatically generated code . In this paper , We will try proto Serialization function of , And try to serialize and deserialize between different languages .
proto go serialize
1. newly build sample package , To facilitate testing , We write a that can generate random data random.go

2. stay sample Write under the package generator.go It is convenient for us to generate subsequent test data

3. newly build serializer , To write Binary serialization file.go

4. stay serializer Write under the package json.go Appoint json Serialization rules

5. stay serializer Write a unit test under the package file_test.go

6. modify Makefile Add a command to run the test

7. make test Run it , Can be observed temp Under the folder are generated laptop.bin and laptop.json

Can be observed ,JSON Serialized result size It's about Binary serialization size 5 times .
proto Java serialize
1. To write sample.Generator Class is used to generate Test data 【 It's equivalent to integrating random.go and generator.go】

2. To write serializer.Serializer Class is used to implement serialization

3. Next, we write a unit test SerializerTest Test class .


You can also see , here JSON The size of serialization is about the size of binary serialization 5 Double span
Language serialization test
We might as well go further , Try to make golang The result of binary serialization , use Java Deserialize back
1. We are going to Java The serialized result is deleted , then golang The binary serialization result of ⻉ To Java Project root
2. Above SerializerTest Unit testing , Let's add another

3. Run unit tests , You can see golang The serialized result was successfully deserialized , contrast golang and Java Of JSON serialize result , Proved proto Cross language serialization capability .




边栏推荐
- LeetCode 1049. Weight of the last stone II daily question
- Sator launched Web3 game "satorspace" and launched hoobi
- 【视频/音频数据处理】上海道宁为您带来Elecard下载、试用、教程
- SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
- Mrs offline data analysis: process OBS data through Flink job
- 一文读懂数仓中的pg_stat
- LeetCode 1774. The dessert cost closest to the target price is one question per day
- First in China! Todesk integrates RTC technology into remote desktop, with clearer image quality and smoother operation
- LeetCode 1043. Separate the array to get the maximum and daily questions
- LeetCode 1186. 删除一次得到子数组最大和 每日一题
猜你喜欢
随机推荐
Localstorage and sessionstorage
skimage学习(3)——Gamma 和 log对比度调整、直方图均衡、为灰度图像着色
【Seaborn】组合图表:PairPlot和JointPlot
LeetCode 1043. Separate the array to get the maximum and daily questions
【饭谈】如何设计好一款测试平台?
LeetCode 1186. 删除一次得到子数组最大和 每日一题
Rpcms method of obtaining articles under the specified classification
mysql实现两个字段合并成一个字段查询
Blue Bridge Cup final XOR conversion 100 points
Flash build API service
mysql使用笔记一
【Seaborn】组合图表、多子图的实现
最新Android高级面试题汇总,Android面试题及答案
LeetCode 1774. 最接近目标价格的甜点成本 每日一题
LeetCode 1477. 找两个和为目标值且不重叠的子数组 每日一题
QML beginner
从DevOps到MLOps:IT工具怎样向AI工具进化?
Test case management tool recommendation
【图像传感器】相关双采样CDS
LeetCode 1049. Weight of the last stone II daily question








