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: FramePayload

Implementations§

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)
    }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.