ormsgpack
ormsgpack copied to clipboard
Add support for `decimal.Decimal`
ormsgpack version: 1.2.3
Current behavior
>>> import decimal
>>> ormsgpack.packb(decimal.Decimal("12.345"))
Traceback (most recent call last):
File "...", in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-119-58a3aa663d1a>", line 1, in <module>
ormsgpack.packb(decimal.Decimal("12.345"))
TypeError: Type is not msgpack serializable: decimal.Decimal
Desired behavior
Decimals seem to be primarily stored as strings. It should be lossless and reasonably fast to cast decimal.Decimal
to str
during serialization, and back during deserialization.
hey @scnerd, thanks for the suggestion. I don't have time to add more features currently, but if someone wants to send a PR it'd be great!
Decimals seem to be primarily stored as strings. It should be lossless and reasonably fast to cast decimal.Decimal to str during serialization, and back during deserialization.
Arbitrary types can be serialized using the default
callable, see https://github.com/aviramha/ormsgpack#default (the example uses decimal
).