Carlos
Carlos

Reputation: 6021

Using protocol buffers to interface c# and c++

I've got a large solution written in c# that uses protobuf-net library for communication. I'm looking to write a c++ program to talk to the existing code, and I'm close to being able to see how to do it.

Here's the plan:

1) Since everything was started in c#, there's no .proto files. However, I can easily write some code that captures the .proto from the existing message classes (GetProto).

2) Some of the types are non-standard, ie they are defined in terms of other types: bcl.DateTime and bcl.Decimal, for example. Using this link I was able to find the definitions: Protobuf-net - serializing .NET GUID - how to read this in C++?

3) Once I have the proto definitions, I can just run the Google code to generate my classes, which will need some extra code to deal with non-standard stuff. Not a big deal.

My only issue at the moment is the format of dictionaries/maps. They look something like this:

repeated Pair_Decimal_Int32 MyDict = 1

What I need is to know is how this special type is defined. It is of course linked to generics (depends on the dictionary), so perhaps there's special code that generates it? I can't quite tell where in protobuf-net it deals with this, so I'm looking for some help.

Upvotes: 2

Views: 1319

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062502

Note that the GetProto in v2 is very newly implemented (as in: days ago) and may have rough edges (it is marked as such).

For datetimes, I would suggest thinking about exposing those as a simpler type for the purposes of interop - maybe a long (ticks into epoch). Dictionaries are simply repeated versions of key (field 1) / value (field 2). Decimal also doesn't have a nice representation in raw protobuf; if possible, use long (scaled by a fixed value) or double, IMO.

Upvotes: 1

Related Questions