【发布时间】:2014-08-22 17:48:17
【问题描述】:
我正在将 Google Proto Buffers 合并到我的项目中,并且非常好 protoc.exe for windows 如何为序列化/反序列化生成头文件和源文件。我需要 protobuf.net 代码生成器。因此,例如,如果我是一个 Person 类,我首先需要在 .proto 文件中定义它。然后当我在它上面运行 protoc.exe 时,它会给我 .h 和 .c 文件。但随后手动,我必须为 Person 类执行以下操作:
[ProtoContract]
class Person {
[ProtoMember(1)]
public int Id {get;set;}
[ProtoMember(2)]
public string Name {get;set:}
[ProtoMember(3)]
public Address Address {get;set;}
}
[ProtoContract]
class Address {
[ProtoMember(1)]
public string Line1 {get;set;}
[ProtoMember(2)]
public string Line2 {get;set;}
}
我希望一切都自动化。因此,从技术上讲,我想为类 Person 提供 .proto 文件并获得上述输出作为回报。我不想做手工工作。我可以自己编写那个工具。但如果已经有一种被广泛使用的工具,我宁愿使用那个工具,而不是重新发明轮子。
【问题讨论】:
标签: c# .net protocol-buffers protobuf-net