1#![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#![allow(non_camel_case_types)]
16
17use ::re_types_core::try_serialize_field;
18use ::re_types_core::SerializationResult;
19use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
20use ::re_types_core::{ComponentDescriptor, ComponentType};
21use ::re_types_core::{DeserializationError, DeserializationResult};
22
23#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)]
27#[repr(u8)]
28pub enum ChannelDatatype {
29 #[default]
31 U8 = 6,
32
33 I8 = 7,
35
36 U16 = 8,
38
39 I16 = 9,
41
42 U32 = 10,
44
45 I32 = 11,
47
48 U64 = 12,
50
51 I64 = 13,
53
54 F16 = 33,
56
57 F32 = 34,
59
60 F64 = 35,
62}
63
64::re_types_core::macros::impl_into_cow!(ChannelDatatype);
65
66impl ::re_types_core::Loggable for ChannelDatatype {
67 #[inline]
68 fn arrow_datatype() -> arrow::datatypes::DataType {
69 #![allow(clippy::wildcard_imports)]
70 use arrow::datatypes::*;
71 DataType::UInt8
72 }
73
74 fn to_arrow_opt<'a>(
75 data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
76 ) -> SerializationResult<arrow::array::ArrayRef>
77 where
78 Self: Clone + 'a,
79 {
80 #![allow(clippy::wildcard_imports)]
81 #![allow(clippy::manual_is_variant_and)]
82 use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
83 use arrow::{array::*, buffer::*, datatypes::*};
84 Ok({
85 let (somes, data0): (Vec<_>, Vec<_>) = data
86 .into_iter()
87 .map(|datum| {
88 let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
89 let datum = datum.map(|datum| *datum as u8);
90 (datum.is_some(), datum)
91 })
92 .unzip();
93 let data0_validity: Option<arrow::buffer::NullBuffer> = {
94 let any_nones = somes.iter().any(|some| !*some);
95 any_nones.then(|| somes.into())
96 };
97 as_array_ref(PrimitiveArray::<UInt8Type>::new(
98 ScalarBuffer::from(
99 data0
100 .into_iter()
101 .map(|v| v.unwrap_or_default())
102 .collect::<Vec<_>>(),
103 ),
104 data0_validity,
105 ))
106 })
107 }
108
109 fn from_arrow_opt(
110 arrow_data: &dyn arrow::array::Array,
111 ) -> DeserializationResult<Vec<Option<Self>>>
112 where
113 Self: Sized,
114 {
115 #![allow(clippy::wildcard_imports)]
116 use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
117 use arrow::{array::*, buffer::*, datatypes::*};
118 Ok(arrow_data
119 .as_any()
120 .downcast_ref::<UInt8Array>()
121 .ok_or_else(|| {
122 let expected = Self::arrow_datatype();
123 let actual = arrow_data.data_type().clone();
124 DeserializationError::datatype_mismatch(expected, actual)
125 })
126 .with_context("rerun.datatypes.ChannelDatatype#enum")?
127 .into_iter()
128 .map(|typ| match typ {
129 Some(6) => Ok(Some(Self::U8)),
130 Some(7) => Ok(Some(Self::I8)),
131 Some(8) => Ok(Some(Self::U16)),
132 Some(9) => Ok(Some(Self::I16)),
133 Some(10) => Ok(Some(Self::U32)),
134 Some(11) => Ok(Some(Self::I32)),
135 Some(12) => Ok(Some(Self::U64)),
136 Some(13) => Ok(Some(Self::I64)),
137 Some(33) => Ok(Some(Self::F16)),
138 Some(34) => Ok(Some(Self::F32)),
139 Some(35) => Ok(Some(Self::F64)),
140 None => Ok(None),
141 Some(invalid) => Err(DeserializationError::missing_union_arm(
142 Self::arrow_datatype(),
143 "<invalid>",
144 invalid as _,
145 )),
146 })
147 .collect::<DeserializationResult<Vec<Option<_>>>>()
148 .with_context("rerun.datatypes.ChannelDatatype")?)
149 }
150}
151
152impl std::fmt::Display for ChannelDatatype {
153 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
154 match self {
155 Self::U8 => write!(f, "U8"),
156 Self::I8 => write!(f, "I8"),
157 Self::U16 => write!(f, "U16"),
158 Self::I16 => write!(f, "I16"),
159 Self::U32 => write!(f, "U32"),
160 Self::I32 => write!(f, "I32"),
161 Self::U64 => write!(f, "U64"),
162 Self::I64 => write!(f, "I64"),
163 Self::F16 => write!(f, "F16"),
164 Self::F32 => write!(f, "F32"),
165 Self::F64 => write!(f, "F64"),
166 }
167 }
168}
169
170impl ::re_types_core::reflection::Enum for ChannelDatatype {
171 #[inline]
172 fn variants() -> &'static [Self] {
173 &[
174 Self::U8,
175 Self::I8,
176 Self::U16,
177 Self::I16,
178 Self::U32,
179 Self::I32,
180 Self::U64,
181 Self::I64,
182 Self::F16,
183 Self::F32,
184 Self::F64,
185 ]
186 }
187
188 #[inline]
189 fn docstring_md(self) -> &'static str {
190 match self {
191 Self::U8 => "8-bit unsigned integer.",
192 Self::I8 => "8-bit signed integer.",
193 Self::U16 => "16-bit unsigned integer.",
194 Self::I16 => "16-bit signed integer.",
195 Self::U32 => "32-bit unsigned integer.",
196 Self::I32 => "32-bit signed integer.",
197 Self::U64 => "64-bit unsigned integer.",
198 Self::I64 => "64-bit signed integer.",
199 Self::F16 => "16-bit IEEE-754 floating point, also known as `half`.",
200 Self::F32 => "32-bit IEEE-754 floating point, also known as `float` or `single`.",
201 Self::F64 => "64-bit IEEE-754 floating point, also known as `double`.",
202 }
203 }
204}
205
206impl ::re_byte_size::SizeBytes for ChannelDatatype {
207 #[inline]
208 fn heap_size_bytes(&self) -> u64 {
209 0
210 }
211
212 #[inline]
213 fn is_pod() -> bool {
214 true
215 }
216}