Accurately serializing and deserializing a SysTime in binary format

Ecstatic Coder ecstatic.coder at gmail.com
Tue Jul 21 11:44:50 UTC 2020


On Tuesday, 21 July 2020 at 11:01:20 UTC, drug wrote:
> On 7/20/20 10:04 PM, Ecstatic Coder wrote:
>> I'm currently implementing a small open source backup tool 
>> (dub), and therefore I need to accurately store the file 
>> modification SysTime in binary format, so that I can later 
>> load this SysTime from the snapshot file to compare it with 
>> the current file modification SysTime.
>> 
>> Having unfortunately not understood how to do this from the 
>> SysTime documentation, in despair, I've tried to directly 
>> serialize the 16 bytes of the SysTime value. This worked fine 
>> until I call the ".toISOString()" on the deserialized SysTime, 
>> which inevitably crashes the executable ;)
>
> That is probably a bug. I serialize SysTime as long by means 
> msgpack for exchanging between C++ client and D server and it 
> works pretty nice.
>
>> 
>> Anyway, that's not really want I intended to do, as in 
>> practice a "ulong" already has enough  resolution for that 
>> purpose.
>> 
>> So sorry for my ignorance, but I would definitely need some 
>> help on how to :
>> - convert a file modification SysTime to a serializable 
>> number, for instance the number of hectonanoseconds since 
>> 1/1/1970 in UTC;
>> - convert that number back into a SysTime that I can compare 
>> to the modification SysTime of the same file.
>> 
>> Eric

Ah thanks for telling me :)

The loaded byte array in the union type was indeed the same as 
the saved one, so I immediately thought it was crashing because 
of some hidden pointer for timezone or something which was then 
pointing to garbage at reloading, causing the crash of the 
".toISOString" call.




More information about the Digitalmars-d-learn mailing list