Skip to content
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

feature request: allow direct writing into WriterBackend #236

Open
dignifiedquire opened this issue Dec 4, 2022 · 0 comments
Open

feature request: allow direct writing into WriterBackend #236

dignifiedquire opened this issue Dec 4, 2022 · 0 comments

Comments

@dignifiedquire
Copy link

dignifiedquire commented Dec 4, 2022

I have the following situation, a field in my protobuf (when stored in rust) needs encoding to bytes before it can get stored in the protobuf. I would like to avoid the temporary allocation of storing it in a Vec, and directly write it into the WriterBackend.

// Current Code
fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> quick_protobuf::Result<()> {
    let bytes: Vec<u8> = self.foo.to_bytes();
    w.write_with_tag(10, |w| w.write_bytes(&bytes))?;
    // ..
    Ok(())
}
// Code I would like to write
fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> quick_protobuf::Result<()> {
    w.write_with_tag(10, |w| {
        let len = self.foo.encoded_len();
        w.write_varint(len as u64)?;
        self.foo.write(w)?;
        Ok(())
    })?;
    // ..
    Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant