dxfscan 0.1.0

Binary DXF parser with typed entity data and lookup indices
Documentation
// SPDX-License-Identifier: ISC
/// A parsed DXF group value, borrowing string/chunk data from the input slice.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum GroupValue<'a> {
    /// Null-terminated string (bytes up to but not including the null).
    String(&'a [u8]),
    /// Boolean (1 byte, nonzero = true).
    Bool(bool),
    /// 16-bit signed integer (2 bytes LE).
    Int16(i16),
    /// 32-bit signed integer (4 bytes LE).
    Int32(i32),
    /// 64-bit signed integer (8 bytes LE).
    Int64(i64),
    /// IEEE 754 double (8 bytes LE).
    Double(f64),
    /// Length-prefixed binary chunk (raw bytes after the length byte).
    BinaryChunk(&'a [u8]),
}

impl<'a> GroupValue<'a> {
    /// Returns the string bytes if this is a `String` variant.
    pub fn as_str_bytes(&self) -> Option<&'a [u8]> {
        match self {
            GroupValue::String(s) => Some(s),
            _ => None,
        }
    }

    /// Returns the f64 if this is a `Double` variant.
    pub fn as_f64(&self) -> Option<f64> {
        match self {
            GroupValue::Double(v) => Some(*v),
            _ => None,
        }
    }

    /// Returns the i16 if this is an `Int16` variant.
    pub fn as_i16(&self) -> Option<i16> {
        match self {
            GroupValue::Int16(v) => Some(*v),
            _ => None,
        }
    }

    /// Returns the i32 if this is an `Int32` variant.
    pub fn as_i32(&self) -> Option<i32> {
        match self {
            GroupValue::Int32(v) => Some(*v),
            _ => None,
        }
    }

    /// Returns the i64 if this is an `Int64` variant.
    pub fn as_i64(&self) -> Option<i64> {
        match self {
            GroupValue::Int64(v) => Some(*v),
            _ => None,
        }
    }

    /// Returns the bool if this is a `Bool` variant.
    pub fn as_bool(&self) -> Option<bool> {
        match self {
            GroupValue::Bool(v) => Some(*v),
            _ => None,
        }
    }

    /// Returns the binary chunk bytes if this is a `BinaryChunk` variant.
    pub fn as_binary_chunk(&self) -> Option<&'a [u8]> {
        match self {
            GroupValue::BinaryChunk(b) => Some(b),
            _ => None,
        }
    }
}