Struct zenoh_protocol::proto::Frame
source · pub struct Frame {
pub channel: Channel,
pub sn: ZInt,
pub payload: FramePayload,
}Expand description
Frame message
NOTE: 16 bits (2 bytes) may be prepended to the serialized message indicating the total length
in bytes of the message, resulting in the maximum length of a message being 65_535 bytes.
This is necessary in those stream-oriented transports (e.g., TCP) that do not preserve
the boundary of the serialized messages. The length is encoded as little-endian.
In any case, the length of a message must not exceed 65_535 bytes.
7 6 5 4 3 2 1 0
+-+-+-+-+-+-+-+-+
|E|F|R| FRAME |
+-+-+-+-+-------+
~ SN ~
+---------------+
~ FramePayload ~ -- if F==1 then the payload is a fragment of a single Zenoh Message, a list of complete Zenoh Messages otherwise.
+---------------+
- if R==1 then the FRAME is sent on the reliable channel, best-effort otherwise.
- if F==1 then the FRAME is a fragment.
- if E==1 then the FRAME is the last fragment. E==1 is valid iff F==1.
NOTE: Only one bit would be sufficient to signal fragmentation in a IP-like fashion as follows:
- if F==1 then this FRAME is a fragment and more fragment will follow;
- if F==0 then the message is the last fragment if SN-1 had F==1,
otherwise it's a non-fragmented message.
However, this would require to always perform a two-steps de-serialization: first
de-serialize the FRAME and then the Payload. This is due to the fact the F==0 is ambigous
w.r.t. detecting if the FRAME is a fragment or not before SN re-ordering has occured.
By using the F bit to only signal whether the FRAME is fragmented or not, it allows to
de-serialize the payload in one single pass when F==0 since no re-ordering needs to take
place at this stage. Then, the F bit is used to detect the last fragment during re-ordering.
Fields§
§channel: Channel§sn: ZInt§payload: FramePayloadImplementations§
source§impl Frame
impl Frame
sourcepub fn make_header(reliability: Reliability, is_fragment: Option<bool>) -> u8
pub fn make_header(reliability: Reliability, is_fragment: Option<bool>) -> u8
Examples found in repository?
src/proto/msg_writer.rs (line 326)
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
fn write_frame_header(
&mut self,
priority: Priority,
reliability: Reliability,
sn: ZInt,
is_fragment: Option<bool>,
attachment: Option<Attachment>,
) -> bool {
if let Some(attachment) = attachment {
zcheck!(self.write_deco_attachment(&attachment));
}
if priority != Priority::default() {
zcheck!(self.write_deco_priority(priority))
}
let header = Frame::make_header(reliability, is_fragment);
self.write_byte(header).is_some() && self.write_zint(sn)
}