1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// 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,
}
}
}