data serialization ai_generated true

Timestamp deserialization fails — msgpack extension type mismatch across languages

ID: data/msgpack-timestamp-extension-incompatible

Also available as: JSON · Markdown
80%Fix Rate
85%Confidence
4Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
any active

Root Cause

MessagePack timestamp extension type -1 is not supported uniformly across implementations.

generic

Workarounds

  1. 92% success Serialize timestamps as Unix epoch integers
    int(datetime.now().timestamp()) -- universally supported

    Sources: https://github.com/msgpack/msgpack/blob/master/spec.md

  2. 82% success Use explicit extension type registration on both sides
    msgpack.packb(data, default=encode_datetime); msgpack.unpackb(raw, ext_hook=decode_datetime)

    Sources: https://msgpack-python.readthedocs.io/en/latest/api.html

Dead Ends

Common approaches that don't work:

  1. Assume all msgpack libraries support timestamp extension type 85% fail

    Older or minimal implementations may not support the timestamp extension

  2. Convert timestamps to strings before packing 65% fail

    String timestamps are larger and defeat msgpack binary efficiency