7

I'm building a C# server and python client app with socket communication. The server sends serialized list of objects to client, but I've got no idea (and couldn't find either) how to deserialize a list in python. Any help would be appreciated.

4
  • Have you tried using pickle? Commented Jun 16, 2014 at 19:56
  • 1
    What have you tried? Are you actually using protoobuf on the server side? Did you try the tutorial? Commented Jun 16, 2014 at 20:01
  • 1
    Yes I'm using protobuf. I can deserialize a single object without problem, but I have not idea how to do it with lists. That's why I couldn't try anything because I don't know. @DarinDouglass I'm new to python, but I guess pickle won't talk with .net. That's why I'm using protobuf Commented Jun 16, 2014 at 20:27
  • 2
    P.S. Yes I've seen the official tutorial, but it doesn't mention deserializing a list Commented Jun 16, 2014 at 20:28

2 Answers 2

19

Allright, I found solution if anyone is interested. The trick is to create a new message type and add original one as repeated. Here's how

message TransactionPackets {
    repeated TransactionPacket packet = 1;
}

message TransactionPacket {
    required int32 trans_id = 1;
    required string user_id = 2;
    required int64 date = 3;
}

Now I can simply deserialize a list of objects by calling TransactionPackets.ParseFromString()

Sign up to request clarification or add additional context in comments.

Comments

2

Check this:

"The Protocol Buffer wire format is not self-delimiting, so protocol buffer parsers cannot determine where a message ends on their own. The easiest way to solve this problem is to write the size of each message before you write the message itself. When you read the messages back in, you read the size, then read the bytes into a separate buffer, then parse from that buffer."

https://developers.google.com/protocol-buffers/docs/techniques

1 Comment

I'm using protobuf-net. I'm not aware how it serializes the data and/or where it puts the size of each message :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.