Help with Zerocopy

There are several doc pages that have very similar ideas:


Whereas the first link shows the expression of a packet's header in terms of the custom U8, the second link use the explicit denotation of the number of bytes (e.g., a u16 is [u8; 2]). In terms of (the sender) writing data to it and copying data therefrom into an outbound stream, which one should I choose? Would this choice differ in the opposite direction wherein information is received and then examined by the receiver?

Goal: super fast byte read/write

Should this be coupled with BytesMut for reading and writing, or would this just be for directly writing to some struct we define (in this case, like a packet header).?

Thanks everyone

1 Like

In the outbound direction starting with the sender, this data will get copied into a codec stream which, by default, uses the BytesMut structure.

In the inbound direction ending with the receiver, a BytesMut structure will then get copied onto a Zerocopy trait'ed struct.

This is currently how I understand how I'll implement it, please correct me if this is wrong or misguided thinking!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.