-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How should the size of from_io
's "sliding buffer" be chosen?
#140
Comments
Hey @smoelius, You just need to make sure that the buffer is big enough for all the data that is borrowed. The test shown is actually pretty overkill to use a buffer of 2048, nothing is actually borrowed in For an example with borrowing, if instead we wanted to deserialize #[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
struct BorrwedU8S<'a> {
st: u16,
ei: u8,
sf: u64,
tt: u32,
borrowed: &'a u8,
} We would need a buffer of at least a length of 1 to store the Hopefully that clarifies your question. |
Thank you, @xgroleau. Your response is very helpful. But should this example then work? use postcard::{from_io, to_io};
use serde::de::DeserializeOwned;
fn main() {
fn sanity(_: &impl DeserializeOwned) {}
let data = String::from("hello");
sanity(&data);
let serialized: ::std::vec::Vec<u8> = vec![];
let ser = to_io(&data, serialized).unwrap();
{
let mut buff = [0; 0]; // <-- Changed 2048 to 0.
let x = ser.clone();
let deserialized: String = from_io((x.as_slice(), &mut buff)).unwrap().0;
assert_eq!(data, deserialized);
}
} I get:
I'm wondering if there may be a bug here: postcard/src/de/deserializer.rs Lines 387 to 392 in 6338601
|
You are right, but it seems strings and probably @jamesmunns could validate that if it is the actual desired behavior. If it is, then you need to make sure to have enough space for allocated items and we could probably document it to make sure the behavior is clear. |
I stumbled upon this problem too and it seems that the given buffer must be big enough to contain the entire input. Because it is stack-allocated it means that you can't process anything bigger than about 8MiB (this is the stack size limit on x86_64 Linux). |
My question concerns the second component of
from_io
'sval
argument`:postcard/src/de/mod.rs
Line 85 in 6338601
From what I can tell, it is a "sliding buffer":
postcard/src/de/mod.rs
Line 90 in 6338601
postcard/src/de/flavors.rs
Lines 330 to 335 in 6338601
In the
loopback
test, the buffer is 2048 bytes:postcard/tests/loopback.rs
Lines 191 to 193 in 6338601
Is this a good choice, generally?
Thank you.
cc: @xgroleau
The text was updated successfully, but these errors were encountered: