Skip to main content

bread_format/
meta.rs

1/*
2 * SPDX-FileCopyrightText: 2026 SynrgStudio
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6//! The name and comment a scene, a node or a mesh may carry.
7
8use crate::bytes::{In, Out};
9
10/// A name, and free text that came with it, such as an STL header.
11///
12/// Where it is optional, `None` (no metadata) is not the same as metadata
13/// whose name and comment are both absent: the bytes differ.
14#[derive(Clone, Debug, Default, PartialEq, Eq)]
15pub struct Meta {
16    pub name: Option<String>,
17    pub comment: Option<String>,
18}
19
20pub(crate) fn write_meta(out: &mut Out, meta: Option<&Meta>) {
21    match meta {
22        None => out.u8(0),
23        Some(meta) => {
24            out.u8(1);
25            out.text(meta.name.as_deref());
26            out.text(meta.comment.as_deref());
27        }
28    }
29}
30
31pub(crate) fn read_meta(input: &mut In<'_>) -> Option<Option<Meta>> {
32    match input.u8()? {
33        0 => Some(None),
34        1 => Some(Some(Meta {
35            name: input.text()?,
36            comment: input.text()?,
37        })),
38        _ => None,
39    }
40}