Need to send some data between managed c# and unmanaged c++. After some research
I tried to use Protobuf.NET.
I’m not sure if I understand functionality of ProtoBuf…
- Build a type definition in Proto. I need this type definition in both projects c++ and c#
- Use the command-line tool “protogen.exe” to get an .cs file and .cpp, .h from the type definition
- Copy the .cs files into my c# project and the .cpp, .h in my c++ solution.
Seems I’m to stupid to to solve this. Here are my problem and questions.
- Is it possible to define the type in c# to generate the files in for c++ ?
- Tried to use the command-line tool protogen.exe with the following files
test1.proto
using ProtoBuf; namespace ProtocolBuffers { [ProtoContract] class Person { [ProtoMember(1)] public int Id {get;set;} [ProtoMember(2)] public string Name { get; set; } } }
test2.proto
message Person {
required int32 id = 1;
required string name = 2;
optional string email = 3;
}
Nothing is working for me. Really tried everything. I put the proto files into the
commandline dir, tried every option to set the dir. How to build them easily ?
The second file is working with standard proto commandline tool for c++ but i need it for c# too. Really need your help.
Firstly, note that protobuf-net is just one available implementation for .NET; anyway…
“test1.proto” is not a .proto – it is C#; a .proto is not required for use with protobuf-net, but in your interop scenario it is a very good idea. There is VS2010 plugin for this, or alternatively the
protogentool that is in the protobuf-net zip:This should generate
test2.cswith the contents:Note that there are additional switches if you want, for example, it to attempt case normalization (so you get
Id,Name,Email, etc), or want it to include additional serializer support (BinaryFormatter,DataContractSerializer, etc)