msgpack-rust icon indicating copy to clipboard operation
msgpack-rust copied to clipboard

Adding Timestamp decode/encode

Open junderw opened this issue 1 year ago • 3 comments

This is a baseline just to have something to work off of, very WIP.

  1. ~~Should we perhaps just use DateTime from the chrono crate under a feature flag instead of creating a simple enum.~~ (I've decided against this, it's too much of a hassle.)
  2. ~~How should we go about including it in rmp-serde if at all?~~ (Made an initial implementation, but kind of hacky, awaiting feedback)
  3. Checking for invalid values (ie. nanos above 999_999_999) should probably be done better. I am not too familiar with this library and how I should be propagating such errors. (Especially with serde.)
  4. Also, please advise on any formatting requests. (I turned off rustfmt)

Let me know if this isn't something you're interested it.

junderw avatar Aug 18 '24 12:08 junderw

@junderw thank you for getting this started 🙏 I'm interested in using this with serde, but I don't understand either library well enough to know what code to add to rmp_serde so that I can use rmp::Timestamp in my structs. Would you be interested in collaborating on this?

jcuffe avatar Nov 24 '24 23:11 jcuffe

@jcuffe I added a hackey TimestampSerde wrapper. It's a simple wrapper only for serde serialize and deserialize.

The content is pub, so you can just take the content out after it's deserialized.

I added a test for each way, you can look at the test to see how it works.

junderw avatar Nov 27 '24 14:11 junderw

Excellent! Thank you @junderw 😁

jcuffe avatar Nov 27 '24 17:11 jcuffe