bincode-org / bincode

A binary encoder / decoder implementation in Rust.
MIT License
2.6k stars 262 forks source link

Cannot deserialize VecDeque with structure of Decimals #699

Closed hedgar2017 closed 3 months ago

hedgar2017 commented 4 months ago

Just FYI, I'm getting DeserializedAnyNotSupported for a VecDeque of simple trading chart candlesticks.

pub struct Candle {
    /// The candle open time.
    pub time: u64,
    /// The candle open price.
    pub open: Decimal,
    /// The candle low price.
    pub low: Decimal,
    /// The candle high price.
    pub high: Decimal,
    /// The candle close price.
    pub close: Decimal,
    /// The vertical candle volume in secondary token units.
    pub volume: Decimal,
}

Basically, I cannot deserialize the same object I've just serialized.

VictorKoenders commented 4 months ago

Can you provide a complete example?

hedgar2017 commented 3 months ago

@VictorKoenders of course! The main function:

fn main() {
    let candle = rust_decimal::Decimal::new(1, 0);
    let serialized = bincode::serialize(&candle).unwrap();
    let deserialized: rust_decimal::Decimal = bincode::deserialize(serialized.as_slice()).unwrap();
    dbg!(&deserialized);
}

The dependencies:

rust_decimal = "1.34"
bincode = "1.3"

The panic message (of bincode::deserialize):

thread 'main' panicked at downloader/src/bug.rs:4:91:
called `Result::unwrap()` on an `Err` value: DeserializeAnyNotSupported
VictorKoenders commented 3 months ago

Looks like you need to enable a specific feature in rust_decimal: https://github.com/paupino/rust-decimal/blob/master/src/serde.rs#L707-L721

hedgar2017 commented 3 months ago

Looks like you need to enable a specific feature in rust_decimal: https://github.com/paupino/rust-decimal/blob/master/src/serde.rs#L707-L721

Thanks, will try.