-
Notifications
You must be signed in to change notification settings - Fork 223
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
base: master
Are you sure you want to change the base?
Conversation
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. |
@dwrensha is this happening anytime soon? |
It looks like this only works with |
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 |
There was a problem hiding this comment.
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)
.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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:
capnproto-rust/capnpc/test/test.capnp
Lines 738 to 744 in 4393eb5
struct Map(Key, Value) { | |
entries @0 :List(Entry); | |
struct Entry { | |
key @0 :Key; | |
value @1 :Value; | |
} | |
} |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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;
}
}
There was a problem hiding this comment.
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?
@dwrensha : Thanks for the review!
|
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. |
Hey there, could I be of any help on this issue? I'd appreciate some macro magic to reduce boilerplate. |
any news? |
what is blocking this? |
Any updates? |
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 |
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