re_types/datatypes/
channel_datatype.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/datatypes/channel_datatype.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#![allow(non_camel_case_types)]
18
19use ::re_types_core::SerializationResult;
20use ::re_types_core::try_serialize_field;
21use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
22use ::re_types_core::{ComponentDescriptor, ComponentType};
23use ::re_types_core::{DeserializationError, DeserializationResult};
24
25/// **Datatype**: The innermost datatype of an image.
26///
27/// How individual color channel components are encoded.
28#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)]
29#[repr(u8)]
30pub enum ChannelDatatype {
31    /// 8-bit unsigned integer.
32    #[default]
33    U8 = 6,
34
35    /// 8-bit signed integer.
36    I8 = 7,
37
38    /// 16-bit unsigned integer.
39    U16 = 8,
40
41    /// 16-bit signed integer.
42    I16 = 9,
43
44    /// 32-bit unsigned integer.
45    U32 = 10,
46
47    /// 32-bit signed integer.
48    I32 = 11,
49
50    /// 64-bit unsigned integer.
51    U64 = 12,
52
53    /// 64-bit signed integer.
54    I64 = 13,
55
56    /// 16-bit IEEE-754 floating point, also known as `half`.
57    F16 = 33,
58
59    /// 32-bit IEEE-754 floating point, also known as `float` or `single`.
60    F32 = 34,
61
62    /// 64-bit IEEE-754 floating point, also known as `double`.
63    F64 = 35,
64}
65
66::re_types_core::macros::impl_into_cow!(ChannelDatatype);
67
68impl ::re_types_core::Loggable for ChannelDatatype {
69    #[inline]
70    fn arrow_datatype() -> arrow::datatypes::DataType {
71        use arrow::datatypes::*;
72        DataType::UInt8
73    }
74
75    fn to_arrow_opt<'a>(
76        data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
77    ) -> SerializationResult<arrow::array::ArrayRef>
78    where
79        Self: Clone + 'a,
80    {
81        #![allow(clippy::manual_is_variant_and)]
82        use ::re_types_core::{Loggable as _, ResultExt as _, arrow_helpers::as_array_ref};
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        use ::re_types_core::{Loggable as _, ResultExt as _, arrow_zip_validity::ZipValidity};
116        use arrow::{array::*, buffer::*, datatypes::*};
117        Ok(arrow_data
118            .as_any()
119            .downcast_ref::<UInt8Array>()
120            .ok_or_else(|| {
121                let expected = Self::arrow_datatype();
122                let actual = arrow_data.data_type().clone();
123                DeserializationError::datatype_mismatch(expected, actual)
124            })
125            .with_context("rerun.datatypes.ChannelDatatype#enum")?
126            .into_iter()
127            .map(|typ| match typ {
128                Some(6) => Ok(Some(Self::U8)),
129                Some(7) => Ok(Some(Self::I8)),
130                Some(8) => Ok(Some(Self::U16)),
131                Some(9) => Ok(Some(Self::I16)),
132                Some(10) => Ok(Some(Self::U32)),
133                Some(11) => Ok(Some(Self::I32)),
134                Some(12) => Ok(Some(Self::U64)),
135                Some(13) => Ok(Some(Self::I64)),
136                Some(33) => Ok(Some(Self::F16)),
137                Some(34) => Ok(Some(Self::F32)),
138                Some(35) => Ok(Some(Self::F64)),
139                None => Ok(None),
140                Some(invalid) => Err(DeserializationError::missing_union_arm(
141                    Self::arrow_datatype(),
142                    "<invalid>",
143                    invalid as _,
144                )),
145            })
146            .collect::<DeserializationResult<Vec<Option<_>>>>()
147            .with_context("rerun.datatypes.ChannelDatatype")?)
148    }
149}
150
151impl std::fmt::Display for ChannelDatatype {
152    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
153        match self {
154            Self::U8 => write!(f, "U8"),
155            Self::I8 => write!(f, "I8"),
156            Self::U16 => write!(f, "U16"),
157            Self::I16 => write!(f, "I16"),
158            Self::U32 => write!(f, "U32"),
159            Self::I32 => write!(f, "I32"),
160            Self::U64 => write!(f, "U64"),
161            Self::I64 => write!(f, "I64"),
162            Self::F16 => write!(f, "F16"),
163            Self::F32 => write!(f, "F32"),
164            Self::F64 => write!(f, "F64"),
165        }
166    }
167}
168
169impl ::re_types_core::reflection::Enum for ChannelDatatype {
170    #[inline]
171    fn variants() -> &'static [Self] {
172        &[
173            Self::U8,
174            Self::I8,
175            Self::U16,
176            Self::I16,
177            Self::U32,
178            Self::I32,
179            Self::U64,
180            Self::I64,
181            Self::F16,
182            Self::F32,
183            Self::F64,
184        ]
185    }
186
187    #[inline]
188    fn docstring_md(self) -> &'static str {
189        match self {
190            Self::U8 => "8-bit unsigned integer.",
191            Self::I8 => "8-bit signed integer.",
192            Self::U16 => "16-bit unsigned integer.",
193            Self::I16 => "16-bit signed integer.",
194            Self::U32 => "32-bit unsigned integer.",
195            Self::I32 => "32-bit signed integer.",
196            Self::U64 => "64-bit unsigned integer.",
197            Self::I64 => "64-bit signed integer.",
198            Self::F16 => "16-bit IEEE-754 floating point, also known as `half`.",
199            Self::F32 => "32-bit IEEE-754 floating point, also known as `float` or `single`.",
200            Self::F64 => "64-bit IEEE-754 floating point, also known as `double`.",
201        }
202    }
203}
204
205impl ::re_byte_size::SizeBytes for ChannelDatatype {
206    #[inline]
207    fn heap_size_bytes(&self) -> u64 {
208        0
209    }
210
211    #[inline]
212    fn is_pod() -> bool {
213        true
214    }
215}