lilliput_core/decoder/
unit.rs

1use crate::{error::Result, header::UnitHeader, marker::Marker, value::UnitValue};
2
3use super::{Decoder, Read};
4
5impl<'r, R> Decoder<R>
6where
7    R: Read<'r>,
8{
9    // MARK: - Value
10
11    /// Decodes a unit value.
12    #[cfg_attr(feature = "tracing", tracing::instrument(skip_all))]
13    pub fn decode_unit(&mut self) -> Result<()> {
14        self.decode_unit_header()?;
15
16        Ok(())
17    }
18
19    /// Decodes a unit value, as a `UnitValue`.
20    #[cfg_attr(feature = "tracing", tracing::instrument(skip_all))]
21    pub fn decode_unit_value(&mut self) -> Result<UnitValue> {
22        self.decode_unit().map(From::from)
23    }
24
25    // MARK: - Header
26
27    /// Decodes a unit value's header.
28    #[cfg_attr(feature = "tracing", tracing::instrument(skip_all))]
29    pub fn decode_unit_header(&mut self) -> Result<UnitHeader> {
30        #[allow(unused_variables)]
31        let byte = self.pull_byte_expecting(Marker::Unit)?;
32
33        #[cfg(feature = "tracing")]
34        tracing::debug!(byte = crate::binary::fmt_byte(byte));
35
36        Ok(UnitHeader)
37    }
38
39    // MARK: - Skip
40
41    /// Skips the unit value for a given `header`.
42    #[cfg_attr(feature = "tracing", tracing::instrument(skip_all))]
43    pub fn skip_unit_value_of(&mut self, header: UnitHeader) -> Result<()> {
44        let _ = header;
45
46        Ok(())
47    }
48
49    // MARK: - Body
50
51    /// Decodes unit value for a given `header`, as a `UnitValue`.
52    #[cfg_attr(feature = "tracing", tracing::instrument(skip_all))]
53    pub fn decode_unit_value_of(&mut self, header: UnitHeader) -> Result<UnitValue> {
54        let _ = header;
55
56        Ok(UnitValue)
57    }
58}