re_types/datatypes/
video_timestamp.rs1#![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#[derive(Clone, Debug, Default, Copy, PartialEq, Eq, PartialOrd, Ord)]
27pub struct VideoTimestamp(
28 pub i64,
30);
31
32::re_types_core::macros::impl_into_cow!(VideoTimestamp);
33
34impl ::re_types_core::Loggable for VideoTimestamp {
35 #[inline]
36 fn arrow_datatype() -> arrow::datatypes::DataType {
37 #![allow(clippy::wildcard_imports)]
38 use arrow::datatypes::*;
39 DataType::Int64
40 }
41
42 fn to_arrow_opt<'a>(
43 data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
44 ) -> SerializationResult<arrow::array::ArrayRef>
45 where
46 Self: Clone + 'a,
47 {
48 #![allow(clippy::wildcard_imports)]
49 #![allow(clippy::manual_is_variant_and)]
50 use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
51 use arrow::{array::*, buffer::*, datatypes::*};
52 Ok({
53 let (somes, data0): (Vec<_>, Vec<_>) = data
54 .into_iter()
55 .map(|datum| {
56 let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
57 let datum = datum.map(|datum| datum.into_owned().0);
58 (datum.is_some(), datum)
59 })
60 .unzip();
61 let data0_validity: Option<arrow::buffer::NullBuffer> = {
62 let any_nones = somes.iter().any(|some| !*some);
63 any_nones.then(|| somes.into())
64 };
65 as_array_ref(PrimitiveArray::<Int64Type>::new(
66 ScalarBuffer::from(
67 data0
68 .into_iter()
69 .map(|v| v.unwrap_or_default())
70 .collect::<Vec<_>>(),
71 ),
72 data0_validity,
73 ))
74 })
75 }
76
77 fn from_arrow_opt(
78 arrow_data: &dyn arrow::array::Array,
79 ) -> DeserializationResult<Vec<Option<Self>>>
80 where
81 Self: Sized,
82 {
83 #![allow(clippy::wildcard_imports)]
84 use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
85 use arrow::{array::*, buffer::*, datatypes::*};
86 Ok(arrow_data
87 .as_any()
88 .downcast_ref::<Int64Array>()
89 .ok_or_else(|| {
90 let expected = Self::arrow_datatype();
91 let actual = arrow_data.data_type().clone();
92 DeserializationError::datatype_mismatch(expected, actual)
93 })
94 .with_context("rerun.datatypes.VideoTimestamp#timestamp_ns")?
95 .into_iter()
96 .map(|v| v.ok_or_else(DeserializationError::missing_data))
97 .map(|res| res.map(|v| Some(Self(v))))
98 .collect::<DeserializationResult<Vec<Option<_>>>>()
99 .with_context("rerun.datatypes.VideoTimestamp#timestamp_ns")
100 .with_context("rerun.datatypes.VideoTimestamp")?)
101 }
102
103 #[inline]
104 fn from_arrow(arrow_data: &dyn arrow::array::Array) -> DeserializationResult<Vec<Self>>
105 where
106 Self: Sized,
107 {
108 #![allow(clippy::wildcard_imports)]
109 use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
110 use arrow::{array::*, buffer::*, datatypes::*};
111 if let Some(nulls) = arrow_data.nulls() {
112 if nulls.null_count() != 0 {
113 return Err(DeserializationError::missing_data());
114 }
115 }
116 Ok({
117 let slice = arrow_data
118 .as_any()
119 .downcast_ref::<Int64Array>()
120 .ok_or_else(|| {
121 let expected = DataType::Int64;
122 let actual = arrow_data.data_type().clone();
123 DeserializationError::datatype_mismatch(expected, actual)
124 })
125 .with_context("rerun.datatypes.VideoTimestamp#timestamp_ns")?
126 .values()
127 .as_ref();
128 {
129 slice.iter().copied().map(Self).collect::<Vec<_>>()
130 }
131 })
132 }
133}
134
135impl From<i64> for VideoTimestamp {
136 #[inline]
137 fn from(timestamp_ns: i64) -> Self {
138 Self(timestamp_ns)
139 }
140}
141
142impl From<VideoTimestamp> for i64 {
143 #[inline]
144 fn from(value: VideoTimestamp) -> Self {
145 value.0
146 }
147}
148
149impl ::re_byte_size::SizeBytes for VideoTimestamp {
150 #[inline]
151 fn heap_size_bytes(&self) -> u64 {
152 self.0.heap_size_bytes()
153 }
154
155 #[inline]
156 fn is_pod() -> bool {
157 <i64>::is_pod()
158 }
159}