Skip to main content

matter_codec/
value.rs

1//! Matter TLV element values.
2//!
3//! Phase 3 of `matter-codec` adds container variants. The full TLV value
4//! space is now represented.
5
6use crate::tag::Tag;
7
8/// A decoded Matter TLV value, collapsed across wire widths.
9///
10/// Integer widths and float widths are erased from the public type — the
11/// encoder chooses the minimal wire width per the spec, and the decoder
12/// produces the same Rust type regardless of the width the bytes used. If
13/// you need exact-byte round-trip for non-minimal inputs, that capability
14/// will land as a low-level `RawElement` API in a later release.
15#[derive(Debug, Clone, PartialEq)]
16#[non_exhaustive]
17pub enum Value {
18    /// A boolean.
19    Bool(bool),
20
21    /// An unsigned integer, encoded on the wire in 1, 2, 4, or 8 bytes
22    /// (minimal width).
23    Uint(u64),
24
25    /// A signed integer, encoded on the wire in 1, 2, 4, or 8 bytes
26    /// (minimal width).
27    Int(i64),
28
29    /// A 4-byte IEEE 754 single-precision float.
30    Float(f32),
31
32    /// An 8-byte IEEE 754 double-precision float.
33    Double(f64),
34
35    /// A UTF-8 string. The wire format is a 1/2/4/8-byte little-endian
36    /// length field (writer picks the minimal width) followed by the
37    /// raw UTF-8 bytes. The reader rejects invalid UTF-8 with
38    /// [`crate::Error::InvalidUtf8`].
39    Utf8(String),
40
41    /// An octet string. The wire format is a 1/2/4/8-byte little-endian
42    /// length field (writer picks the minimal width) followed by the
43    /// raw bytes.
44    Bytes(Vec<u8>),
45
46    /// A structure. Each member carries its own tag; members are
47    /// typically context-tagged but the spec permits any non-anonymous
48    /// form.
49    Structure(Vec<(Tag, Value)>),
50
51    /// An array. Elements share a single type; the spec requires every
52    /// element to carry an anonymous tag, which the reader enforces and
53    /// the writer always emits.
54    Array(Vec<Value>),
55
56    /// A list. Members may carry any tag form (including anonymous), and
57    /// member types are not required to be uniform.
58    List(Vec<(Tag, Value)>),
59
60    /// The TLV null value (element type `0x14`).
61    Null,
62}