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