关于 struct_pack struct_json 序列化的问题请教 #701
-
我在为一个很大的 codebase 支持一些结构体的序列化工作,关于 struct_pack struct_json 序列化的问题想请假一下:
|
Beta Was this translation helpful? Give feedback.
Answered by
poor-circle
Jun 30, 2024
Replies: 2 comments 4 replies
-
//serialize.hpp
std::string my_serialize(const Foo &foo); //serialize.cpp
std::string my_serialize(const Foo &foo) {
return struct_pack::serialize<std::string>(foo);
} 使用时调用my_serialize而非struct_pack::serialize,这样你只需要编译一次serialize.cpp即可。当然代价是多了一次无法内联的函数调用。 |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
Weaverzhu
-
@Weaverzhu |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使用时调用my_serialize而非struct_pack::serialize,这样你只需要编译一次serialize.cpp即可。当然代价是多了一次无法内联的函数调用。
3. struct_pack有相关机制,请见介绍。struct_json目前恐怕是不支持的。
4. 无。但我理解json格式天然就是向前向后兼容的。多余的字段应该会被自动忽略,缺失的字段应该会被设置为默认值。