Giter Site home page Giter Site logo

Comments (6)

VictorKoenders avatar VictorKoenders commented on June 2, 2024 1

Looks like they're using #[serde(untagged)]: https://github.com/informalsystems/tendermint-rs/blob/main/rpc/src/id.rs#L11

We do not get this information from serde, and this results in types that bincode cannot properly serialize and deserialize. A full list can be found here: https://docs.rs/bincode/2.0.0-rc.3/bincode/serde/index.html#known-issues

Unfortunately this is not something we can fix in bincode. More information here: #130 (comment)

from bincode.

VictorKoenders avatar VictorKoenders commented on June 2, 2024

This should only fail if there is a bug in bincode, or if your encode/decode logic is not correct. The best way to debug this is to make your encode/decode struct as small as possible to where it still generates an issue. You can also use at the spec to manually encode your type and see if that matches what bincode generates

from bincode.

penso avatar penso commented on June 2, 2024

I'll try to encode a subset of the external crate struct to see what generate the issue, but since I'm not doing any specific encoding/decoding I'd say it's a bug in bincode.

Would creating a repo with a minimal example of the fail help you?

from bincode.

VictorKoenders avatar VictorKoenders commented on June 2, 2024

If you've truly found a bug in bincode it would be great to see a minimal reproducible example, yes

from bincode.

penso avatar penso commented on June 2, 2024

@VictorKoenders here for you https://github.com/penso/bincode-fails (just use cargo run)

Made it as simple as possible:

use std::{fs::File, io::Read, str::from_utf8};

use anyhow::Context;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use tendermint_rpc::endpoint::{block, block_results};

#[derive(Serialize, Deserialize, Debug)]
pub struct BlockAndTransactions {
    pub block: block::Response,
    pub block_results: block_results::Response,
}

fn main() -> anyhow::Result<()> {
    let data: BlockAndTransactions = read_data()?;

    let config = bincode::config::standard();
    let encoded: Vec<u8> = bincode::serde::encode_to_vec(&data, config)?;
    // THIS IS THE LINE THAT FAILS
    let (_decoded, _): (BlockAndTransactions, _) =
        bincode::serde::decode_from_slice(&encoded, config)?;

    Ok(())
}

pub fn read_data<T: DeserializeOwned>() -> anyhow::Result<T> {
    let filename = "1206335.json.xz";

    let file = File::open(filename)?;
    let mut decompressor = lzma::LzmaReader::new_decompressor(file)?;

    let mut s = Vec::new();
    decompressor.read_to_end(&mut s)?;

    let string = from_utf8(&s)?;
    Ok(serde_json::from_str::<T>(string).with_context(|| "Can't decode json data")?)
}

from bincode.

penso avatar penso commented on June 2, 2024

Ah bummer, thanks for looking at this. Will try to get them to remove this tag then.

from bincode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.