What would be the best way to serialise the struct timeval
type obtained via the gettimeofday(2)
call? I would like to stick to some standard, so htobe64(3) and friends will not do. The time_t
type could possibly be a 64-bit integer and there is no clear way how to serialise those object.
Asked
Active
Viewed 155 times
0

Daniel Lovasko
- 471
- 2
- 10
-
Isn't the idea of serialisation that endianess isn't relevant anymore? Then look at json or xml or somthing. With those techniques it should be relatively easy. There are many libraries for both. – hetepeperfan Jun 08 '17 at 21:15
-
[ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations), specifically the "`YYYYMMDD` T `hhmmss` Z" format (UTC time). If you do need the microsecond accuracy, then "`YYYYMMDD` T `hhmmss.uuuuuu` Z". You can do this by calling `gmtime()` and then formatting it with `strftime()`. – Nominal Animal Jun 08 '17 at 21:21
-
Perhaps one part of my question which was not explicit was that the serialisation should be in raw binary. Is that achievable without using a designated format, such as JSON or ISO8601? – Daniel Lovasko Jun 08 '17 at 21:27
-
Why `htobe64` don't fit your needs? Anyway, you may read https://stackoverflow.com/questions/13957254/c-c-safest-way-to-send-time-t-over-socket – Jean-Baptiste Yunès Jun 10 '17 at 14:23