Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How protobuf-net serialize DateTime?

I'm working on a project consisting on Client/Server. Client is written in Python (will run on linux) and server in C#. I'm communicating through standard sockets and I'm using protobuf-net for protocol definition. However, I'm wondering how would protobuf-net handle DateTime serialization. Unix datetime differs from .net standard datetime, so how should I handle this situation?

Thanks

like image 344
Davita Avatar asked Jun 04 '14 11:06

Davita


People also ask

How is protobuf serialized?

The Protobuf serialization mechanism is given through the protoc application, this compiler will parse the . proto file and will generate as output, source files according to the configured language by its arguments, in this case, C++. You can also obtain more information about, reading the section compiler invocation.

What is serializing and Deserializing in protobuf?

Protobufs serialize data into binary formats which are then transmitted in bytes, the data looks very dense and smaller. It's faster to transmit over wire, serialize and deserialize them. But it is not intended to use them, if the underlying application is a web browser, and the data is fed directly to it.

Does protobuf compress data?

Messages are not compressed.

What is protobuf net in C#?

protobuf-net is a contract based serializer for . NET code, that happens to write data in the "protocol buffers" serialization format engineered by Google.


1 Answers

DateTime is spoofed via a multi-field message that is not trivial, but not impossible to understand. In hindsight, I wish I had done it a different way, but it is what it is. The definition is available in bcl.proto in the protobuf-net project.

However! If you are targering multiple platforms, I strongly recommend you simply use a long etc in your DTO model, representing some time granularity into some epoch (seconds or milliseconds since 1970, for example).

like image 166
Marc Gravell Avatar answered Sep 28 '22 01:09

Marc Gravell