Comments (6)
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.
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.
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.
If you've truly found a bug in bincode it would be great to see a minimal reproducible example, yes
from bincode.
@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.
Ah bummer, thanks for looking at this. Will try to get them to remove this tag then.
from bincode.
Related Issues (20)
- Trying to implement Decode and Encode on an ArrayVec from tinyvec!
- Improved encoding and decoding speed of Vec<u8> HOT 3
- Modify an Existing Configuration HOT 3
- enum is encoded as Option, but cannot be decoded HOT 1
- Feature Request: Enums as number HOT 1
- Bincode 2 release HOT 8
- deserialize_in_place equivalent for bincode 2.0 HOT 1
- Panic/memory allocation of x bytes failed with 1.3.3 version of bincode HOT 3
- Why does deserializing slightly different structs from the same bytes work? HOT 2
- Saving a Configuration in a Generic Variable HOT 1
- `get_byte_buffer` equivalent in bincode 2? HOT 4
- Deserialize external tag to separate type variable HOT 1
- Arc/Rc handling clarification HOT 1
- Is there a way to patch 1.x? HOT 1
- Add codec support for chrone HOT 3
- Unclear why serialized_size() yields different results HOT 1
- Does bincode guarantee a 1:1 relationship between encodings and values? HOT 3
- bincode::de::Deserializer::with_reader() doesn't seem to work HOT 1
- Issue when decoding a simple Enum with no member values.
- make config::DefaultOptions::new `const` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bincode.