-
Notifications
You must be signed in to change notification settings - Fork 222
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 to implement zero copy? #258
Comments
I'm also perplexed by this - I would expect P.S. in github-flavored markdown, you can enable language-specific syntax hightlighting with |
I think for this to work, |
I think you can pass a fake reader live longer than <'a> as the argument as a workaround, the easiest way is always passing a #[derive(Debug, Clone)]
struct Output<'a> {
pub data1: &'a [u8],
pub data2: &'a [u8],
}
impl<'a> Output<'a> {
pub fn set_data1(&mut self, value: &'a [u8]) {
self.data1 = value;
}
pub fn set_data2(&mut self, value: &'a [u8]) {
self.data2 = value;
}
pub fn decode<'b>(
&'a mut self,
input: &mut &'b [u8],
reader: &'b mut Option<Reader<SliceSegments<'b>>>,
) where
'b: 'a,
{
*reader = Some(
serialize::read_message_from_flat_slice(input, ReaderOptions::new())
.expect("fail to build reader"),
);
let data = reader
.as_ref()
.unwrap()
.get_root::<output::Reader<'b>>()
.expect("failed to get reader");
let d1 = data.get_data1().expect("failed to get d1");
let d2 = data.get_data2().expect("failed to get d2");
self.set_data1(d1);
self.set_data2(d2);
}
} To call the function, you can use let mut reader = None;
output.decode(&mut input, &mut reader); |
My question is: Is So what's the difference between Does Friendly ping @dwrensha |
Yes, capnp-rpc is currently hard-coded to use You might imagine that something like a shared-memory ring buffer would allow us to avoid copying those buffers, but it seems difficult to me to make that work. The problem is that user-defined objects in the RPC system may hold on to messages for arbitrary lengths of time, so we would not be able to implement a simple "sliding window" of active memory. |
Thanks for your detailed explanation :) |
@katetsu: To make it work, you will need to hold the outer message ( It's possible that there's a way to adjust capnproto-rust's handling of lifetimes to make possible what you are attempting, but I don't see an obvious easy way to do it. |
I am trying to figure out zero copying with capn proto. i have the following schema file:
and here is the decoding code where im trying to read from a stream of bytes and create my class from them without copying:
but im getting this error:
any idea for what im doing wrong?
The text was updated successfully, but these errors were encountered: