This code (playground):
#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename = "b")]
struct BytesVal {
pub b: bytes::Bytes,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[serde(untagged)]
enum Bad {
Bytes(BytesVal),
}
fn main() {
let v: Bad = ron::from_str(r#"(b: "dGVzdA==")"#).unwrap();
dbg!(&v);
let s = ron::to_string(&v).unwrap();
dbg!(&s);
let v: Bad = ron::from_str(&s).unwrap();
dbg!(&v);
println!("---");
let v: Bad = serde_json::from_str(r#"{"b": "dGVzdA=="}"#).unwrap();
dbg!(&v);
let s = serde_json::to_string(&v).unwrap();
dbg!(&s);
let v: Bad = serde_json::from_str(&s).unwrap();
dbg!(&v);
}
has the following output:
[src/main.rs:23] &v = Bytes(
BytesVal {
b: b"dGVzdA==",
},
)
[src/main.rs:25] &s = "(b:\"ZEdWemRBPT0=\")"
[src/main.rs:27] &v = Bytes(
BytesVal {
b: b"ZEdWemRBPT0=",
},
)
---
[src/main.rs:30] &v = Bytes(
BytesVal {
b: b"dGVzdA==",
},
)
[src/main.rs:32] &s = "{\"b\":[100,71,86,122,100,65,61,61]}"
[src/main.rs:34] &v = Bytes(
BytesVal {
b: b"dGVzdA==",
},
)
It fully survives the roundtrip with serde_json, but adds extra level of Base64 with RON.
This code (playground):
has the following output:
It fully survives the roundtrip with
serde_json, but adds extra level of Base64 with RON.