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
/*
* SPDX-FileCopyrightText: 2026 SynrgStudio
* SPDX-License-Identifier: Apache-2.0
*/
//! The name and comment a scene, a node or a mesh may carry.
use crate::bytes::{In, Out};
/// A name, and free text that came with it, such as an STL header.
///
/// Where it is optional, `None` (no metadata) is not the same as metadata
/// whose name and comment are both absent: the bytes differ.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Meta {
pub name: Option<String>,
pub comment: Option<String>,
}
pub(crate) fn write_meta(out: &mut Out, meta: Option<&Meta>) {
match meta {
None => out.u8(0),
Some(meta) => {
out.u8(1);
out.text(meta.name.as_deref());
out.text(meta.comment.as_deref());
}
}
}
pub(crate) fn read_meta(input: &mut In<'_>) -> Option<Option<Meta>> {
match input.u8()? {
0 => Some(None),
1 => Some(Some(Meta {
name: input.text()?,
comment: input.text()?,
})),
_ => None,
}
}