re_types/archetypes/
recording_info.rs

1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/rust/api.rs
2// Based on "crates/store/re_types/definitions/rerun/archetypes/recording_info.fbs".
3
4#![allow(unused_braces)]
5#![allow(unused_imports)]
6#![allow(unused_parens)]
7#![allow(clippy::allow_attributes)]
8#![allow(clippy::clone_on_copy)]
9#![allow(clippy::cloned_instead_of_copied)]
10#![allow(clippy::map_flatten)]
11#![allow(clippy::needless_question_mark)]
12#![allow(clippy::new_without_default)]
13#![allow(clippy::redundant_closure)]
14#![allow(clippy::too_many_arguments)]
15#![allow(clippy::too_many_lines)]
16#![allow(clippy::wildcard_imports)]
17
18use ::re_types_core::SerializationResult;
19use ::re_types_core::try_serialize_field;
20use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
21use ::re_types_core::{ComponentDescriptor, ComponentType};
22use ::re_types_core::{DeserializationError, DeserializationResult};
23
24/// **Archetype**: A list of properties associated with a recording.
25#[derive(Clone, Debug, Default)]
26pub struct RecordingInfo {
27    /// When the recording started.
28    ///
29    /// Should be an absolute time, i.e. relative to Unix Epoch.
30    pub start_time: Option<SerializedComponentBatch>,
31
32    /// A user-chosen name for the recording.
33    pub name: Option<SerializedComponentBatch>,
34}
35
36impl RecordingInfo {
37    /// Returns the [`ComponentDescriptor`] for [`Self::start_time`].
38    ///
39    /// The corresponding component is [`crate::components::Timestamp`].
40    #[inline]
41    pub fn descriptor_start_time() -> ComponentDescriptor {
42        ComponentDescriptor {
43            archetype: Some("rerun.archetypes.RecordingInfo".into()),
44            component: "RecordingInfo:start_time".into(),
45            component_type: Some("rerun.components.Timestamp".into()),
46        }
47    }
48
49    /// Returns the [`ComponentDescriptor`] for [`Self::name`].
50    ///
51    /// The corresponding component is [`crate::components::Name`].
52    #[inline]
53    pub fn descriptor_name() -> ComponentDescriptor {
54        ComponentDescriptor {
55            archetype: Some("rerun.archetypes.RecordingInfo".into()),
56            component: "RecordingInfo:name".into(),
57            component_type: Some("rerun.components.Name".into()),
58        }
59    }
60}
61
62static REQUIRED_COMPONENTS: std::sync::LazyLock<[ComponentDescriptor; 0usize]> =
63    std::sync::LazyLock::new(|| []);
64
65static RECOMMENDED_COMPONENTS: std::sync::LazyLock<[ComponentDescriptor; 0usize]> =
66    std::sync::LazyLock::new(|| []);
67
68static OPTIONAL_COMPONENTS: std::sync::LazyLock<[ComponentDescriptor; 2usize]> =
69    std::sync::LazyLock::new(|| {
70        [
71            RecordingInfo::descriptor_start_time(),
72            RecordingInfo::descriptor_name(),
73        ]
74    });
75
76static ALL_COMPONENTS: std::sync::LazyLock<[ComponentDescriptor; 2usize]> =
77    std::sync::LazyLock::new(|| {
78        [
79            RecordingInfo::descriptor_start_time(),
80            RecordingInfo::descriptor_name(),
81        ]
82    });
83
84impl RecordingInfo {
85    /// The total number of components in the archetype: 0 required, 0 recommended, 2 optional
86    pub const NUM_COMPONENTS: usize = 2usize;
87}
88
89impl ::re_types_core::Archetype for RecordingInfo {
90    #[inline]
91    fn name() -> ::re_types_core::ArchetypeName {
92        "rerun.archetypes.RecordingInfo".into()
93    }
94
95    #[inline]
96    fn display_name() -> &'static str {
97        "Recording info"
98    }
99
100    #[inline]
101    fn required_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
102        REQUIRED_COMPONENTS.as_slice().into()
103    }
104
105    #[inline]
106    fn recommended_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
107        RECOMMENDED_COMPONENTS.as_slice().into()
108    }
109
110    #[inline]
111    fn optional_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
112        OPTIONAL_COMPONENTS.as_slice().into()
113    }
114
115    #[inline]
116    fn all_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
117        ALL_COMPONENTS.as_slice().into()
118    }
119
120    #[inline]
121    fn from_arrow_components(
122        arrow_data: impl IntoIterator<Item = (ComponentDescriptor, arrow::array::ArrayRef)>,
123    ) -> DeserializationResult<Self> {
124        re_tracing::profile_function!();
125        use ::re_types_core::{Loggable as _, ResultExt as _};
126        let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect();
127        let start_time = arrays_by_descr
128            .get(&Self::descriptor_start_time())
129            .map(|array| {
130                SerializedComponentBatch::new(array.clone(), Self::descriptor_start_time())
131            });
132        let name = arrays_by_descr
133            .get(&Self::descriptor_name())
134            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_name()));
135        Ok(Self { start_time, name })
136    }
137}
138
139impl ::re_types_core::AsComponents for RecordingInfo {
140    #[inline]
141    fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch> {
142        use ::re_types_core::Archetype as _;
143        [self.start_time.clone(), self.name.clone()]
144            .into_iter()
145            .flatten()
146            .collect()
147    }
148}
149
150impl ::re_types_core::ArchetypeReflectionMarker for RecordingInfo {}
151
152impl RecordingInfo {
153    /// Create a new `RecordingInfo`.
154    #[inline]
155    pub fn new() -> Self {
156        Self {
157            start_time: None,
158            name: None,
159        }
160    }
161
162    /// Update only some specific fields of a `RecordingInfo`.
163    #[inline]
164    pub fn update_fields() -> Self {
165        Self::default()
166    }
167
168    /// Clear all the fields of a `RecordingInfo`.
169    #[inline]
170    pub fn clear_fields() -> Self {
171        use ::re_types_core::Loggable as _;
172        Self {
173            start_time: Some(SerializedComponentBatch::new(
174                crate::components::Timestamp::arrow_empty(),
175                Self::descriptor_start_time(),
176            )),
177            name: Some(SerializedComponentBatch::new(
178                crate::components::Name::arrow_empty(),
179                Self::descriptor_name(),
180            )),
181        }
182    }
183
184    /// Partitions the component data into multiple sub-batches.
185    ///
186    /// Specifically, this transforms the existing [`SerializedComponentBatch`]es data into [`SerializedComponentColumn`]s
187    /// instead, via [`SerializedComponentBatch::partitioned`].
188    ///
189    /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
190    ///
191    /// The specified `lengths` must sum to the total length of the component batch.
192    ///
193    /// [`SerializedComponentColumn`]: [::re_types_core::SerializedComponentColumn]
194    #[inline]
195    pub fn columns<I>(
196        self,
197        _lengths: I,
198    ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>>
199    where
200        I: IntoIterator<Item = usize> + Clone,
201    {
202        let columns = [
203            self.start_time
204                .map(|start_time| start_time.partitioned(_lengths.clone()))
205                .transpose()?,
206            self.name
207                .map(|name| name.partitioned(_lengths.clone()))
208                .transpose()?,
209        ];
210        Ok(columns.into_iter().flatten())
211    }
212
213    /// Helper to partition the component data into unit-length sub-batches.
214    ///
215    /// This is semantically similar to calling [`Self::columns`] with `std::iter::take(1).repeat(n)`,
216    /// where `n` is automatically guessed.
217    #[inline]
218    pub fn columns_of_unit_batches(
219        self,
220    ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>> {
221        let len_start_time = self.start_time.as_ref().map(|b| b.array.len());
222        let len_name = self.name.as_ref().map(|b| b.array.len());
223        let len = None.or(len_start_time).or(len_name).unwrap_or(0);
224        self.columns(std::iter::repeat_n(1, len))
225    }
226
227    /// When the recording started.
228    ///
229    /// Should be an absolute time, i.e. relative to Unix Epoch.
230    #[inline]
231    pub fn with_start_time(mut self, start_time: impl Into<crate::components::Timestamp>) -> Self {
232        self.start_time = try_serialize_field(Self::descriptor_start_time(), [start_time]);
233        self
234    }
235
236    /// This method makes it possible to pack multiple [`crate::components::Timestamp`] in a single component batch.
237    ///
238    /// This only makes sense when used in conjunction with [`Self::columns`]. [`Self::with_start_time`] should
239    /// be used when logging a single row's worth of data.
240    #[inline]
241    pub fn with_many_start_time(
242        mut self,
243        start_time: impl IntoIterator<Item = impl Into<crate::components::Timestamp>>,
244    ) -> Self {
245        self.start_time = try_serialize_field(Self::descriptor_start_time(), start_time);
246        self
247    }
248
249    /// A user-chosen name for the recording.
250    #[inline]
251    pub fn with_name(mut self, name: impl Into<crate::components::Name>) -> Self {
252        self.name = try_serialize_field(Self::descriptor_name(), [name]);
253        self
254    }
255
256    /// This method makes it possible to pack multiple [`crate::components::Name`] in a single component batch.
257    ///
258    /// This only makes sense when used in conjunction with [`Self::columns`]. [`Self::with_name`] should
259    /// be used when logging a single row's worth of data.
260    #[inline]
261    pub fn with_many_name(
262        mut self,
263        name: impl IntoIterator<Item = impl Into<crate::components::Name>>,
264    ) -> Self {
265        self.name = try_serialize_field(Self::descriptor_name(), name);
266        self
267    }
268}
269
270impl ::re_byte_size::SizeBytes for RecordingInfo {
271    #[inline]
272    fn heap_size_bytes(&self) -> u64 {
273        self.start_time.heap_size_bytes() + self.name.heap_size_bytes()
274    }
275}