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

Define a framing protocol #3

Open
utaal opened this issue Aug 9, 2017 · 2 comments
Open

Define a framing protocol #3

utaal opened this issue Aug 9, 2017 · 2 comments

Comments

@utaal
Copy link
Member

utaal commented Aug 9, 2017

(from a chat with @frankmcsherry:)

This should allow writing to files and sockets, while accomodating multiple use cases (possibly with different framing structures).

Perhaps Abomonation should have read and write methods for readers and writers, and it does the framing for you and doesn't give the choice of forgetting.

Things to keep in mind:

  • If each abomonated object is prepended by a length marker: "the length is also handy in that it lets you zip through an array faster (moving from object to object, rather than deserializing each to determine the length).

A Framed struct:

A struct Framed<T: Abomonation> { len: usize, data: T } which then implements Abomonation, but in a magical special way where maybe (i) len is written as part of abomonation, or maybe (ii) len is computed by fake serialization (relatively cheap, without traversing all the data).
This has other advantages, like allocating enough memory to write T rather than repeatedly growing / copying the Vec

  • More complex headers may be folded into the abomonated T? For example, what should we do with the message headers in timely_communication?
@frankmcsherry
Copy link
Member

A quick comment before I forget: Rust makes no promises about field order, without various repr decorators. This makes the Framed struct less obviously wonderful, as opposed having a distinct usize that we manually force into the stream.

Anyhow, something to be careful about!

@frankmcsherry
Copy link
Member

Another thought, the size field has the potential to interfere with memcpy-ability of value types, if that is a concern. For example, if we want to stash a sequence of u64 data, a framing protocol would disrupt this substantially (and inflate the format).

The only point here is that this should probably be "optional" somehow, perhaps driven by the user, or perhaps by having types implement a "has dynamic size" trait or method or something (would be false for value types and their compositions, and become true as soon as you have dynamically sized memory).

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

2 participants