Giter VIP home page Giter VIP logo

Comments (10)

dwrensha avatar dwrensha commented on August 22, 2024

You can get the bytes by calling message.get_segments_for_output(), which will give you a single-segment OutputSegments.

Currently there is no way to use the packed encoding in no-alloc mode. I think we could add support for that and for plain serialize_packed::write_message() by putting the multi-segment support behind a #[cfg] attribute.

from capnproto-rust.

kolegs avatar kolegs commented on August 22, 2024

Thanks for help.
Is adding support for packed encoding in no-alloc mode something I could help with?

from capnproto-rust.

dwrensha avatar dwrensha commented on August 22, 2024

The big obstacle I see is on the reading side of things. Currently serialize_packed::read_message() allocates a vector on the heap:

let owned_space = crate::Word::allocate_zeroed_vec(self.total_words);

It's unclear to me how we should make that work in the no-alloc case. I suppose we need to add a way to make that allocation configurable, but I don't see an obvious nice way to do it.

from capnproto-rust.

kolegs avatar kolegs commented on August 22, 2024

Usually in the situations like that the user should decide of the size of the buffer used to serialize/deserialize data.
I used in the past this library for the c++/protobuf: https://embeddedproto.com/ and this is written in an elegant way. But using the same approach would require a lot of work here. And of course this library is only targeting embedded development.

from capnproto-rust.

dwrensha avatar dwrensha commented on August 22, 2024

We could add a serialize::read_message_into_buffer_segments() function which is like serialize::read_message(), but additionally takes a &mut [u8] to use as the backing storage, and returns a message::Reader<BufferSegments<&[u8]>> (instead of a message::Reader<OwnedSegments>).

from capnproto-rust.

kolegs avatar kolegs commented on August 22, 2024

I can try to play a little bit with it in the upcoming days if you want, but be aware I am not very familiar with the code and CapN proto library 😄

Off topic question:
I'm testing the library a little bit and I added AnyPointer and List(Uint16) to one struct. But when I call init_ method to initialize the field the struct itself is borrowed so I cannot make another call to initialize another field. Is this a limitation? Of is there another way?

from capnproto-rust.

dwrensha avatar dwrensha commented on August 22, 2024

But when I call init_ method to initialize the field the struct itself is borrowed so I cannot make another call to initialize another field.

You cannot have a mutable reference to both child fields at the same time, but you can initialize them sequentially using the reborrow() method: https://dwrensha.github.io/capnproto-rust/2014/12/27/custom-mutable-references.html

from capnproto-rust.

dwrensha avatar dwrensha commented on August 22, 2024

#451 adds no-alloc serialize_packed::write_message() and serialize_packed::read_message_no_alloc().

from capnproto-rust.

dwrensha avatar dwrensha commented on August 22, 2024

Fixed in #451, and released in capnp-v0.18.5.

from capnproto-rust.

kolegs avatar kolegs commented on August 22, 2024

Wow, nicely done 🎉 I will test it for sure

from capnproto-rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.