C++ Protobuf implementation in C# -


I created the protoobb file in the C ++ mentioned below. I want to use the same in ProtoBuff-Net. It works fine with normal Protobuf classes, but I can not work it using the extension in "main message" Can someone give me some code examples?

Here's my C ++ Proto files are:

  file - message-title. Proto: Message message header {Required int 32 ID = 1; } File - The main message. Proto: Import "Messageheader.proto"; Message main message {essential message header header = 1; Extensions 100 to 199; } File - MessageBool.proto: Import "Messageheader.proto"; Import "Main Message. Proto"; Message MessageBool {Essential bool succeeded = 1; Alternate String Notification = 2; Expansion of MainMessage {Optional MessageBool Bool = 100; }} File - Message Login. Proto: Import "Messageheader.proto"; Import "Main Message. Proto"; Message message log {required string user name = 1; Required string password = 2; Expand MainMessage {Optional message login = 101; }}  

The C # program will be a client and a C + + programmer server, so the implementation of protobuf should work together.

EDIT: I tried to send a main message that has a message login from the C # client to the C ++ server. The server can digitize the type of successes, because the header ID can be read correctly. But the contained message login is just empty.

You have asked for your current effort and here it is:

[Removed old and incorrect source code. Now I have created CC files, which are similar to CPP)

So what do I have to do, so that the C # protobuf message is equal to C ++ people?

EDIT2: Those settings have worked, but I still can not read the extension login message Current view for serializing a message:

  // Create main message message = new main message {header = new message header} {id = 1,},}; MessageLogin login = new message login {user name = username, password = password}; Extensible.Append Value & lt; MesseSlogin & gt; (Message, 101, login); String str = ProtoZmq.Serialize (message); // Other files: public static string serialize (object protobum message) {string str = ""; (Using memorystream stream = new memorystream ()) {Serializer.Serialize (stream, protoom message); Str = encoding. ASCII.GetString (stream.GetBuffer ()); // str = convert ToBase64String (stream.GetBuffer ()); } Return str; }  

And how do I deserialize it in C ++:

  zmq :: message_t request; // Wait for the next request from client socket .recv (& request, 0); Std :: string rpl = std :: string (static_cast & lt; char * & gt; (request.data ()), request.size () - 1); Main message message; Message.ParseFromString (rpl.data ()); MessageLogin login = message.GetExtension (MessageLogin :: Login); Std :: string user = login.username (); Std :: string pw = login.password (); Std :: cout & lt; & Lt; message header (). ID () & lt; & Lt; Std :: endl; Std :: cout & lt; & Lt; Users & lt; & Lt; Std :: endl; Std :: cout & lt; & Lt; PW & lt; & Lt; Std :: endl;  

The C ++ server always tells me that there is no extension for the message and therefore users and PWs are empty.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -