C ++基本序列化而不使用额外的库(C++ basic serialization without using extra libraries)

有人可以给我一个很好的提示,如何在不使用标准库以外的额外库的情况下执行序列化?

Someone can give me a good hint about how to perform serialization without using extra libraries other than the standard ones ?

最满意答案

我会质疑你是否有充分的理由不使用库。 有很多数据表明你自己编写的代码最容易在你面前爆炸,其原因在于它背后的测试代码最少。

如果你有充分的理由而且还需要序列化,那么你必须自己编写。 基本上,您正在考虑重载通常的ostream和istream运算符,以便它们支持您需要的类型。

再次,你冒着重新发明方形轮的风险。 请记住,最好的库(如boost)本身是使用标准C ++编写的,而bost上的许可要求并不要求您发布源代码或任何此类内容。 换句话说,即使您使用IP,您的IP也是安全的。

I would question whether you have a good reason for not using libraries. There is a lot of data that shows that the code you write yourself is most likely to blow up in your face down the line and the reason for that is because its the code with the least testing behind it.

If you do have a good reason and you still need to serialize, then you have to write your own. Basically, you're looking at overloading the usual ostream and istream operators so that they support the types you need.

Again, you run the risk of Re-inventing the square wheel. Keep in mind that the best libraries (like boost) are themselves written using standard C++ and the licensing requirements on bost do not require you to release your source or any such thing. In other words, your IP is safe even after you use them.

更多推荐