protobuf-net 如何序列化 DateTime? [英] How protobuf-net serialize DateTime?

查看:48
本文介绍了protobuf-net 如何序列化 DateTime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个由客户端/服务器组成的项目.客户端用 Python 编写(将在 linux 上运行),服务器用 C# 编写.我正在通过标准套接字进行通信,并且正在使用 protobuf-net 进行协议定义.但是,我想知道 protobuf-net 如何处理 DateTime 序列化.Unix 日期时间与 .net 标准日期时间不同,那么我应该如何处理这种情况?

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?

谢谢

推荐答案

DateTime 是通过多字段消息来欺骗的,该消息并非微不足道,但并非无法理解.事后看来,我希望我以不同的方式做到了,但事实就是如此.该定义在 protobuf-net 项目中的 bcl.proto 中可用.

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.

但是!如果您针对多个平台,我强烈建议您在 DTO 模型中简单地使用 long 等,将某个时间粒度表示为某个时期(例如,自 1970 年以来的秒或毫秒).

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).

这篇关于protobuf-net 如何序列化 DateTime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆