#[non_exhaustive]pub enum Segment {
Block(Vec<Field>),
Value {
name: String,
doc: Option<String>,
stated: Option<Stated>,
kind: Kind,
},
Repeat {
name: String,
doc: Option<String>,
stated: Option<Stated>,
element: Kind,
count: Count,
at: Option<String>,
collection: Collection,
},
Placed {
name: String,
doc: Option<String>,
stated: Option<Stated>,
kind: Kind,
at: String,
absent: Option<Absence>,
},
Switch {
name: String,
doc: Option<String>,
stated: Option<Stated>,
on: Discriminant,
choice: String,
window: Option<Len>,
},
Opt {
when: Presence,
field: Field,
},
Checksum {
name: String,
doc: Option<String>,
stated: Option<Stated>,
repr: Scalar,
algorithm: String,
over: Coverage,
},
}Expand description
One part of a message.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Block(Vec<Field>)
Fixed-width fields.
Value
A Kind::Var, Kind::Msg or Kind::Text value, whose size is read from the wire.
Fields
Repeat
A collection of elements.
Fields
collection: CollectionThe Rust type.
Placed
One record at a byte offset read from an earlier field.
The offset counts from the start of the body, which inside a Kind::Msg is that message.
Fields
kind: KindThe record: a Kind::Nested or a Kind::Msg.
Switch
A field whose arm an earlier value selects.
The arms and their values are in a ChoiceDef. Nothing can follow
a switch that has no window and whose choice is
open-ended.
Fields
on: DiscriminantWhat selects the arm.
window: Option<Len>A fixed size for the switch, independent of the arm.
None takes the arm’s size. Len::Bytes makes a union, checked by
arms_fit. Len::Field reads the size from an
earlier field, and encode writes it. With a window, fields can follow the switch.
Opt
An optional field.
Encode sets the masked bits and leaves the rest of the flags field alone. Other fields cannot refer to an optional field.
Checksum
A checksum over bytes of the same body.
Encode computes it once the covered bytes are written. Decode verifies it and returns an error on mismatch.
Implementations§
Source§impl Segment
impl Segment
Sourcepub fn value(name: &str, kind: Kind) -> Self
pub fn value(name: &str, kind: Kind) -> Self
A Segment::Value with no documentation or #[at].
Sourcepub fn repeat(
name: &str,
element: Kind,
count: Count,
at: Option<&str>,
collection: Collection,
) -> Self
pub fn repeat( name: &str, element: Kind, count: Count, at: Option<&str>, collection: Collection, ) -> Self
at names the offset field, or is None to read the elements in place.
Sourcepub fn placed(name: &str, kind: Kind, at: &str, absent: Option<Absence>) -> Self
pub fn placed(name: &str, kind: Kind, at: &str, absent: Option<Absence>) -> Self
A Segment::Placed at the offset in field at. Optional when absent is set.
Sourcepub fn switch(
name: &str,
on: Discriminant,
choice: &str,
window: Option<Len>,
) -> Self
pub fn switch( name: &str, on: Discriminant, choice: &str, window: Option<Len>, ) -> Self
A Segment::Switch on on, with arms from the choice type choice.
Sourcepub fn opt(when: Presence, field: Field) -> Self
pub fn opt(when: Presence, field: Field) -> Self
A Segment::Opt.
Sourcepub fn with_stated(self, at: Stated) -> Self
pub fn with_stated(self, at: Stated) -> Self
Sets the #[at] position. Does nothing on a Block.
Sourcepub fn places(&self) -> Vec<&str>
pub fn places(&self) -> Vec<&str>
The names of the fields this segment always writes, in wire order.
Optional fields are not included.
Sourcepub fn placed_optionally(&self) -> Option<&str>
pub fn placed_optionally(&self) -> Option<&str>
The name of the field, if it is optional.
Sourcepub fn fixed_bits(&self) -> Option<u64>
pub fn fixed_bits(&self) -> Option<u64>
The size in bits, or None if it depends on the wire.