Skip to content

Is no-copy message write possible with no alloc ?  #535

Open
@kaidokert

Description

@kaidokert

Hey, here's the basic test code i have to create a message in a slice:

pub fn create_serialized_message<const N: usize>(buffer: &mut [u8]) {
    let mut tmp_buffer = [0; N];
    let mut allocator = capnp::message::SingleSegmentAllocator::new(tmp_buffer.as_mut_slice());
    let mut message = capnp::message::Builder::new(&mut allocator);
    let foo_builder = message.init_root::<foo::foo::Builder>();
    let mut numbers = foo_builder.init_numbers(3);
    numbers.set(0, 1);
    numbers.set(1, 2);
    capnp::serialize::write_message(buffer, &message).expect("yay?");
}

The question is, is it possible to, even in theory, to write a message without having a copy in an intermediate buffer ? I couldn't figure it out.

By reading the code, it doesn't currently seem possible, as write_segment_table needs to write 8 bytes to the head of the buffer - after the message has been constructed. And write_segment_table is not public, so i can't manually partition the slice for writing the single-segment header and the message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions