mongodb / bson-rust

Encoding and decoding support for BSON in Rust
MIT License
405 stars 134 forks source link

Operating on BSON Decimal128 type #484

Closed jvliwanag closed 4 months ago

jvliwanag commented 4 months ago

Seeking guidance on how to operate on Decimal128 bson type such as value comparisons, additions, etc.

I noticed that bson-rust used decimal crate at one point but opted to make it internal. Is decimal byte compatible with Decimal128? Is it advisable to use from_raw_bytes to convert to Decimal?

abr-egn commented 4 months ago

The bson crate doesn't provide any manipulation for Decimal128 values beyond reading or printing strings. The binary representation is a standard IEEE 754-2008 value, so anything that uses that representation should work fine, including the decimal crate.

jvliwanag commented 4 months ago

Unfortunately found more details on RUST-960 that this won’t work. Haven’t found any crate that works yet. Looks like the only correct way right now is to convert to string and to reparse it on one of the rust decimal implementations. It won’t be performant though.