简体   繁体   中英

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

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. Moreover, adding a minute to this increases the width to 6 bytes, and adding an hour increases it 5 bytes. 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.

So I figured this out by viewing the Java implementation of the xdevapi. The bytes are a protobuf coded stream.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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