用于 Protobuf 的日期和时间类型 [英] Date and time type for use with Protobuf

查看:43
本文介绍了用于 Protobuf 的日期和时间类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用协议缓冲区在 Linux 和基于 Windows 的系统之间进行数据交换.

I'm considering to use Protocol Buffers for data exchange between a Linux and a Windows based system.

发送日期/时间(时间戳)值的推荐格式是什么?序列化时字段应该很小.

Whats the recommended format for sending date/time (timestamp) values? The field should be small when serialized.

推荐答案

虽然你没有说你使用的是哪种语言或你需要什么样的精度,我还是建议使用 Unix 时间 编码为 int64.在大多数语言和平台中都相当容易处理(请参阅 此处 对于 Windows 示例),Protobufs 将使用 varint-encoding 在不过多限制可表示范围的情况下保持较小的尺寸.

Although you aren't saying which languages you are using or what kind of precision you need, I would suggest using Unix time encoded into a int64. It is fairly easy to handle in most languages and platforms (see here for a Windows example), and Protobufs will use a varint-encoding keeping the size small without limiting the representable range too much.

这篇关于用于 Protobuf 的日期和时间类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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