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

capnp-conv: proc macro ergonomics for capnproto-rust #157

Open
wants to merge 51 commits into
base: master
Choose a base branch
from

Conversation

realcr
Copy link

@realcr realcr commented Jan 15, 2020

This PR adds a new crate called capnp-conv, allowing for automatic proc macro based code generation for serialization and deserialization.
Should solve issue #136

realcr added 30 commits June 28, 2019 17:02
@realcr realcr requested a review from dwrensha January 15, 2020 18:25
@dwrensha
Copy link
Member

dwrensha commented Jan 15, 2020

Thanks for the pull request!

I'm not going to have time to look at this immediately, partially because I'm focusing on sorting out our alignment story, but I hope to have a look before too long.

@zimond
Copy link

zimond commented Mar 2, 2020

@dwrensha is this happening anytime soon?

@dwrensha
Copy link
Member

dwrensha commented Mar 8, 2020

It looks like this only works with serialize_packed. Is there a way to generalize this so it would also work for the non-packed case?

let data = float_struct.to_capnp_bytes();
let float_struct2 = FloatStruct::from_capnp_bytes(&data).unwrap();

// Sloppily check that the floats are close enough (We can't compare them directly, as they
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to work for me if I do assert_eq!(float_struct.my_float32, float_struct2.my_float32).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing floats is what makes me wake up in fear in the middle of the night. I am still new to understanding how it works in Rust, if you feel comfortable with this comparison I'm cool with it too.

myFloat64 @1: Float64;
}

struct GenericStruct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gather that this is for testing a struct that generic on the Rust side. How does this library handle structs that are generic (i.e. have type parameters) on the capnp side? Like this one:

struct Map(Key, Value) {
entries @0 :List(Entry);
struct Entry {
key @0 :Key;
value @1 :Value;
}
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capnp-conv doesn't handle the case of generic structs on the capnp side. I admit I am not really sure what would be the expected behaviour. This will require some thinking.

innerU8 @0: UInt8;
}

struct TestUnion {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this library handle structs that have some union fields and some non-union fields? E.g.

struct Foo {
   a @0 :UInt64;
   b @1 :Text;
   union {
      c @2 :Data;
      d @3 :UInt32;
  }
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am almost sure capnp-conv doesn't support this. What would be the Rust equivalent of this construct?

@realcr
Copy link
Author

realcr commented Mar 9, 2020

@dwrensha : Thanks for the review!

  1. I am not familiar with the packed vs non-packed case. Where can I get more information about it?
  2. In case it was not obvious, you should feel free to make any changes to this piece of code (:

@kscz
Copy link

kscz commented May 22, 2020

1. I am not familiar with the packed vs non-packed case. Where can I get more information about it?

Hi @realcr - I know I wasn't who you asked, but since it appears no one is answering your question, I figured I would give it a shot!

One of the big things which makes Cap'n Proto unique compared to many other serialization formats which came before it, is that the in-memory representation is identical to the on-the-wire representation. This means that "serializing" can, for all intents and purposes, simply be a memory-copy into the output buffer! The downside is that this format means that details like padding bytes and unset optional fields end up being transmitted over the wire, which wastes bandwidth.

To mitigate this bandwidth issue, instead of having a "free" serialization step, you can use the "Packed" representation which basically tries to compress away as many zeros as possible.

For reading about either of these representations - https://capnproto.org/index.html talks about the "free" encoding step, and https://capnproto.org/encoding.html#packing talks about the "packed" representation.

@opeik
Copy link

opeik commented Jun 22, 2021

Hey there, could I be of any help on this issue? I'd appreciate some macro magic to reduce boilerplate.

@ajosecueto
Copy link

any news?

@lu-zero
Copy link

lu-zero commented Sep 26, 2023

what is blocking this?

@praveenperera
Copy link

Any updates?

@p--b
Copy link

p--b commented Mar 2, 2024

For those wanting to use this, NB that as an alternative, @aikalant has published https://github.com/aikalant/capnp_conv, which is available on crates.io as capnp_conv.

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

Successfully merging this pull request may close these issues.

9 participants