简体   繁体   English

解码mysql xdevapi时间戳

[英]decoding mysql xdevapi timestamp

I'm using the c xdevapi in mysql connector 8.0.11 and trying to read a timestamp in my program. 我在mysql连接器8.0.11中使用c xdevapi,并尝试在程序中读取时间戳。 These are fetched from the database as binary, and I cannot figure out how this is encoded. 它们是从数据库中以二进制形式获取的,我无法弄清楚它是如何编码的。 I had assumed that it would reflect the internal encoding as documented here: https://dev.mysql.com/doc/internals/en/date-and-time-data-type-representation.html 我假设它会反映此处记录的内部编码: https : //dev.mysql.com/doc/internals/en/date-and-time-data-type-representation.html

However, experimentation does not seem to confirm this. 但是,实验似乎无法证实这一点。 When I read a column which I have set to: 当我阅读已设置为的列时:

epoch (1970-1-1 00:00:00) 

I read in the binary value 01010FB2. 我读入二进制值01010FB2。 Moreover, adding a minute to this increases the width to 6 bytes, and adding an hour increases it 5 bytes. 而且,增加一分钟会增加宽度到6个字节,增加一个小时会增加5个字节。 None of this matches my expectations. 这些都不符合我的期望。

I cannot find reading timestamps in the xdevapi documentation, and I am really hoping someone is able to help me. 我在xdevapi文档中找不到时间戳记,我真的希望有人能够帮助我。

So I figured this out by viewing the Java implementation of the xdevapi. 因此,我通过查看xdevapi的Java实现了解了这一点。 The bytes are a protobuf coded stream. 字节是一个protobuf编码的流。

To parse a date time or timestamp structure you read from the coded stream in order of year, month, day, hour, minute, second, nanosecond by calling GetVarint32 until you have read the nanosecond or there is no more data in the coded stream. 若要解析日期时间或时间戳结构,请通过调用GetVarint32从年,月,日,小时,分钟,秒,纳秒的顺序从编码流中读取,直到您已读取纳秒或编码流中没有更多数据为止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM