Use protobuf-net in C++/CLI

752 views
Skip to first unread message

Barzo

unread,
Oct 7, 2013, 4:17:16 AM10/7/13
to prot...@googlegroups.com
Hi,

I have built a C++ framework which use protobuf library.
Now I'm writing a C++/CLI wrapper to make it visible in .NET world.

Since I cannot made a wrapper for each message in my c++ .proto file, is there a way to use the protobuf-net generated c# file in a C++/CLI project?

Regards,
Daniele.

Marc Gravell

unread,
Oct 7, 2013, 5:18:52 AM10/7/13
to Barzo, Protocol Buffers
I don't do much... no: *any* C++/CLI - but I guess the conflict here is that the c++ generated classes are not going to be CLI-friendly. So you need to either use a c++ library and c++ classes, or a managed library and managed classes.

If your framework is unmanaged c++, then I *suspect* your best bet might be to accept managed types, and then map them manually to the unmanaged types, before feeding the unmanaged types to the unmanaged library. However, to your question about using the generated C# files in a C++/CLI project: yes, that will work - but you'll have to use a matching managed library - so if you use protobuf-net generated types, you'll have to use protobuf-net to serialize/deserialize. And likewise with protobuf-csharp-port generated types and the protobuf-csharp-port library.

I'm not sure if I added anything there, but...

Marc


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.



--
Regards,

Marc

Barzo

unread,
Oct 7, 2013, 5:45:10 AM10/7/13
to prot...@googlegroups.com, Barzo
Hi Marc,

thanks for your reply.
To be more clear...
In the native SDK I have a native Message<T> class which encapsulate messages from the protoc generated file.
Then, in the managed wrapper, I have a managed MessageNET<T> class which has to encapsulate messages from protogen generated file.
Of course the source .proto file is the same.


However, to your question about using the generated C# files in a C++/CLI project: yes, that will work

So I can compile it within the C++/CLI project?
In a meanwhile I have built the .cs generated file into a separate DLL assembly and I added it (linked) to my C++/CLI project.

 
but you'll have to use a matching managed library - so if you use protobuf-net generated types, you'll have to use protobuf-net to serialize/deserialize. And likewise with protobuf-csharp-port generated types and the protobuf-csharp-port library.

 Yes, of course!
Obviously this was understood :-)

PS. I did't know protobuf-csharp-port...what are the differences between protobuf.net?

Cheers,
Daniele.

Marc Gravell

unread,
Oct 7, 2013, 5:55:13 AM10/7/13
to Barzo, Protocol Buffers

On 7 October 2013 10:45, Barzo <dba...@gmail.com> wrote:
In a meanwhile I have built the .cs generated file into a separate DLL assembly and I added it (linked) to my C++/CLI project.

Indeed, compiling it as C# and referencing/linking was what I meant - i.e. using the C# *from* C++/CLI, rather than *in* C++/CLI

If you wanted native C++/CLI output, you'd need to write a new code-generator for C++/CLI and the desired library. Which isn't necessarily too difficult (in the case of protobuf-net, you should be able to use csharp.xslt as a starting point).

Re the difference between protobuf-csharp-port vs protobuf-net:

- protobuf-csharp-port tries to be idiomatic protobuf, supporting C#
- protobuf-net tries to be idiomatic C# (/.NET), supporting protobuf

Or in other words: the API for protobuf-csharp-port is very similar to the google implementations - and virtually identical to the protobuf java API - builder pattern, etc. Conversely, protobuf-net aims first and foremost to be a .NET serializer (mutable objects, primarily code-first (code-gen added as a secondary tool), etc), but just happening to dealing with protobuf data.

Marc

Barzo

unread,
Oct 7, 2013, 5:57:27 AM10/7/13
to prot...@googlegroups.com
Thanks a lot!
Daniele.
Reply all
Reply to author
Forward
0 new messages