简体   繁体   English

协议缓冲区,用于序列化C ++和反序列化为C#类

[英]Protocol Buffer to Serialize C++ and and Deserialize to C# class

Is it possible to Serialize a class in C++ and deserialize it to a similar class in C# using protocol buffer? 是否可以使用协议缓冲区将C ​​++中的类序列化并反序列化为C#中的类似类? I have tried Json serialization to overcome this serialization issue in different platforms but it has issues on some data types such as array list, etc. So any advice on using google's protocol buffer? 我已经尝试过Json序列化来克服在不同平台上的序列化问题,但是它在某些数据类型(例如数组列表等)上存在问题。那么关于使用Google协议缓冲区的任何建议吗?

Protocol Buffers will allow you to describe a data structure, and serialize/deserialize that to objects in C++, Java, C# and other platforms. 协议缓冲区将允许您描述数据结构,并将其序列化/反序列化为C ++,Java,C#和其他平台中的对象。 You don't (generally, anyway) get to serialize instances of your own classes - you serialize instances of the generated classes. 您(通常无论如何)都不会序列化自己的类的实例-序列化所生成类的实例。 (I know that protobuf-net allows you to decorate your own classes with attributes describing how to serialize them to protocol buffers, rather than having to use generated classes. I don't know if that has been done in C++.) (我知道protobuf-net允许您使用描述如何将它们序列化到协议缓冲区的属性来装饰自己的类,而不必使用生成的类。我不知道这是否在C ++中完成。)

It's not clear whether that really meets your requirements, but protobufs certainly allow for cross-platform data exchange. 尚不清楚这是否真的满足您的要求,但是protobufs当然可以进行跨平台的数据交换。 It does have limitations in terms of what data can be serialized - it's all reasonably primitive, and you build up more complex structures from the primitive ones. 它在可序列化哪些数据方面确实有局限性-都是合理的原始数据,您可以从原始数据构建更复杂的结构。 That can be frustrating if you've already got your data model in code, and then have to reimplement it in protocol buffers, but it does work... 如果您已经在代码中添加了数据模型,然后不得不在协议缓冲区中重新实现它,那可能会令人沮丧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM