-
Notifications
You must be signed in to change notification settings - Fork 14
Description
serde has a problem deserializing Chunk whose source is ChunkSource::Chunks. To be more specific, when deserializing one, it throws:
JsonSerdeError(Error("u128 is not supported", line: 16, column: 3))
Some interesting things are that
- It can serialize the struct, but cannot deserialize it.
- It can deserialize u128 in
Uid, but not the ones inChunkSource::Chunks. I suspect it's because of#[serde(tag = "type")], but I'm not sure yet.
I thought this pr is a fix for the problem, and I tested locally. It gives me another error message:
JsonSerdeError(Error("invalid type: map, expected u128", line: 16, column: 3))
It could either be 1) a bug in the PR or 2) the PR is not for this issue, but I'm not sure.
Below is a minimal code that can reproduce this error:
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
#[serde(tag = "type")]
pub enum ChunkSource {
File { source: String, index: usize },
Chunks { uids: Vec<Uid> },
}
#[derive(Debug, Deserialize, Serialize)]
pub struct Uid {
high: u128,
low: u128,
}
fn main() {
let uid = Uid { high: 290035462369354878339780249989510800979, low: 181325506523271356483045718667112222021 };
let u = ChunkSource::Chunks { uids: vec![uid] };
let us = serde_json::to_string_pretty(&u).unwrap();
println!("{:?}", serde_json::from_str::<ChunkSource>(&us).unwrap());
}In the local version (the one with the PR), it does not panic if high and low of Uid are less than or equal to u64::MAX. With crates.io version, it dies regardless the value of high and low.
Below is the json it generates:
{
"type": "Chunks",
"uids": [
{
"high": 290035462369354878339780249989510800979,
"low": 181325506523271356483045718667112222021
}
]
}