re_types/datatypes/
tensor_buffer.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/tensor_buffer.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/// **Datatype**: The underlying storage for [`archetypes::Tensor`][crate::archetypes::Tensor].
23///
24/// Tensor elements are stored in a contiguous buffer of a single type.
25#[derive(Clone, PartialEq)]
26pub enum TensorBuffer {
27    /// 8bit unsigned integer.
28    U8(::arrow::buffer::ScalarBuffer<u8>),
29
30    /// 16bit unsigned integer.
31    U16(::arrow::buffer::ScalarBuffer<u16>),
32
33    /// 32bit unsigned integer.
34    U32(::arrow::buffer::ScalarBuffer<u32>),
35
36    /// 64bit unsigned integer.
37    U64(::arrow::buffer::ScalarBuffer<u64>),
38
39    /// 8bit signed integer.
40    I8(::arrow::buffer::ScalarBuffer<i8>),
41
42    /// 16bit signed integer.
43    I16(::arrow::buffer::ScalarBuffer<i16>),
44
45    /// 32bit signed integer.
46    I32(::arrow::buffer::ScalarBuffer<i32>),
47
48    /// 64bit signed integer.
49    I64(::arrow::buffer::ScalarBuffer<i64>),
50
51    /// 16bit IEEE-754 floating point, also known as `half`.
52    F16(::arrow::buffer::ScalarBuffer<half::f16>),
53
54    /// 32bit IEEE-754 floating point, also known as `float` or `single`.
55    F32(::arrow::buffer::ScalarBuffer<f32>),
56
57    /// 64bit IEEE-754 floating point, also known as `double`.
58    F64(::arrow::buffer::ScalarBuffer<f64>),
59}
60
61::re_types_core::macros::impl_into_cow!(TensorBuffer);
62
63impl ::re_types_core::Loggable for TensorBuffer {
64    #[inline]
65    fn arrow_datatype() -> arrow::datatypes::DataType {
66        #![allow(clippy::wildcard_imports)]
67        use arrow::datatypes::*;
68        DataType::Union(
69            UnionFields::new(
70                vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
71                vec![
72                    Field::new("_null_markers", DataType::Null, true),
73                    Field::new(
74                        "U8",
75                        DataType::List(std::sync::Arc::new(Field::new(
76                            "item",
77                            DataType::UInt8,
78                            false,
79                        ))),
80                        false,
81                    ),
82                    Field::new(
83                        "U16",
84                        DataType::List(std::sync::Arc::new(Field::new(
85                            "item",
86                            DataType::UInt16,
87                            false,
88                        ))),
89                        false,
90                    ),
91                    Field::new(
92                        "U32",
93                        DataType::List(std::sync::Arc::new(Field::new(
94                            "item",
95                            DataType::UInt32,
96                            false,
97                        ))),
98                        false,
99                    ),
100                    Field::new(
101                        "U64",
102                        DataType::List(std::sync::Arc::new(Field::new(
103                            "item",
104                            DataType::UInt64,
105                            false,
106                        ))),
107                        false,
108                    ),
109                    Field::new(
110                        "I8",
111                        DataType::List(std::sync::Arc::new(Field::new(
112                            "item",
113                            DataType::Int8,
114                            false,
115                        ))),
116                        false,
117                    ),
118                    Field::new(
119                        "I16",
120                        DataType::List(std::sync::Arc::new(Field::new(
121                            "item",
122                            DataType::Int16,
123                            false,
124                        ))),
125                        false,
126                    ),
127                    Field::new(
128                        "I32",
129                        DataType::List(std::sync::Arc::new(Field::new(
130                            "item",
131                            DataType::Int32,
132                            false,
133                        ))),
134                        false,
135                    ),
136                    Field::new(
137                        "I64",
138                        DataType::List(std::sync::Arc::new(Field::new(
139                            "item",
140                            DataType::Int64,
141                            false,
142                        ))),
143                        false,
144                    ),
145                    Field::new(
146                        "F16",
147                        DataType::List(std::sync::Arc::new(Field::new(
148                            "item",
149                            DataType::Float16,
150                            false,
151                        ))),
152                        false,
153                    ),
154                    Field::new(
155                        "F32",
156                        DataType::List(std::sync::Arc::new(Field::new(
157                            "item",
158                            DataType::Float32,
159                            false,
160                        ))),
161                        false,
162                    ),
163                    Field::new(
164                        "F64",
165                        DataType::List(std::sync::Arc::new(Field::new(
166                            "item",
167                            DataType::Float64,
168                            false,
169                        ))),
170                        false,
171                    ),
172                ],
173            ),
174            UnionMode::Dense,
175        )
176    }
177
178    fn to_arrow_opt<'a>(
179        data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
180    ) -> SerializationResult<arrow::array::ArrayRef>
181    where
182        Self: Clone + 'a,
183    {
184        #![allow(clippy::wildcard_imports)]
185        #![allow(clippy::manual_is_variant_and)]
186        use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
187        use arrow::{array::*, buffer::*, datatypes::*};
188        Ok({
189            // Dense Arrow union
190            let data: Vec<_> = data
191                .into_iter()
192                .map(|datum| {
193                    let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
194                    datum
195                })
196                .collect();
197            let field_type_ids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
198            let fields = vec![
199                Field::new("_null_markers", DataType::Null, true),
200                Field::new(
201                    "U8",
202                    DataType::List(std::sync::Arc::new(Field::new(
203                        "item",
204                        DataType::UInt8,
205                        false,
206                    ))),
207                    false,
208                ),
209                Field::new(
210                    "U16",
211                    DataType::List(std::sync::Arc::new(Field::new(
212                        "item",
213                        DataType::UInt16,
214                        false,
215                    ))),
216                    false,
217                ),
218                Field::new(
219                    "U32",
220                    DataType::List(std::sync::Arc::new(Field::new(
221                        "item",
222                        DataType::UInt32,
223                        false,
224                    ))),
225                    false,
226                ),
227                Field::new(
228                    "U64",
229                    DataType::List(std::sync::Arc::new(Field::new(
230                        "item",
231                        DataType::UInt64,
232                        false,
233                    ))),
234                    false,
235                ),
236                Field::new(
237                    "I8",
238                    DataType::List(std::sync::Arc::new(Field::new(
239                        "item",
240                        DataType::Int8,
241                        false,
242                    ))),
243                    false,
244                ),
245                Field::new(
246                    "I16",
247                    DataType::List(std::sync::Arc::new(Field::new(
248                        "item",
249                        DataType::Int16,
250                        false,
251                    ))),
252                    false,
253                ),
254                Field::new(
255                    "I32",
256                    DataType::List(std::sync::Arc::new(Field::new(
257                        "item",
258                        DataType::Int32,
259                        false,
260                    ))),
261                    false,
262                ),
263                Field::new(
264                    "I64",
265                    DataType::List(std::sync::Arc::new(Field::new(
266                        "item",
267                        DataType::Int64,
268                        false,
269                    ))),
270                    false,
271                ),
272                Field::new(
273                    "F16",
274                    DataType::List(std::sync::Arc::new(Field::new(
275                        "item",
276                        DataType::Float16,
277                        false,
278                    ))),
279                    false,
280                ),
281                Field::new(
282                    "F32",
283                    DataType::List(std::sync::Arc::new(Field::new(
284                        "item",
285                        DataType::Float32,
286                        false,
287                    ))),
288                    false,
289                ),
290                Field::new(
291                    "F64",
292                    DataType::List(std::sync::Arc::new(Field::new(
293                        "item",
294                        DataType::Float64,
295                        false,
296                    ))),
297                    false,
298                ),
299            ];
300            let type_ids: Vec<i8> = data
301                .iter()
302                .map(|a| match a.as_deref() {
303                    None => 0,
304                    Some(Self::U8(_)) => 1i8,
305                    Some(Self::U16(_)) => 2i8,
306                    Some(Self::U32(_)) => 3i8,
307                    Some(Self::U64(_)) => 4i8,
308                    Some(Self::I8(_)) => 5i8,
309                    Some(Self::I16(_)) => 6i8,
310                    Some(Self::I32(_)) => 7i8,
311                    Some(Self::I64(_)) => 8i8,
312                    Some(Self::F16(_)) => 9i8,
313                    Some(Self::F32(_)) => 10i8,
314                    Some(Self::F64(_)) => 11i8,
315                })
316                .collect();
317            let offsets = {
318                let mut u8_offset = 0;
319                let mut u16_offset = 0;
320                let mut u32_offset = 0;
321                let mut u64_offset = 0;
322                let mut i8_offset = 0;
323                let mut i16_offset = 0;
324                let mut i32_offset = 0;
325                let mut i64_offset = 0;
326                let mut f16_offset = 0;
327                let mut f32_offset = 0;
328                let mut f64_offset = 0;
329                let mut nulls_offset = 0;
330                data.iter()
331                    .map(|v| match v.as_deref() {
332                        None => {
333                            let offset = nulls_offset;
334                            nulls_offset += 1;
335                            offset
336                        }
337                        Some(Self::U8(_)) => {
338                            let offset = u8_offset;
339                            u8_offset += 1;
340                            offset
341                        }
342                        Some(Self::U16(_)) => {
343                            let offset = u16_offset;
344                            u16_offset += 1;
345                            offset
346                        }
347                        Some(Self::U32(_)) => {
348                            let offset = u32_offset;
349                            u32_offset += 1;
350                            offset
351                        }
352                        Some(Self::U64(_)) => {
353                            let offset = u64_offset;
354                            u64_offset += 1;
355                            offset
356                        }
357                        Some(Self::I8(_)) => {
358                            let offset = i8_offset;
359                            i8_offset += 1;
360                            offset
361                        }
362                        Some(Self::I16(_)) => {
363                            let offset = i16_offset;
364                            i16_offset += 1;
365                            offset
366                        }
367                        Some(Self::I32(_)) => {
368                            let offset = i32_offset;
369                            i32_offset += 1;
370                            offset
371                        }
372                        Some(Self::I64(_)) => {
373                            let offset = i64_offset;
374                            i64_offset += 1;
375                            offset
376                        }
377                        Some(Self::F16(_)) => {
378                            let offset = f16_offset;
379                            f16_offset += 1;
380                            offset
381                        }
382                        Some(Self::F32(_)) => {
383                            let offset = f32_offset;
384                            f32_offset += 1;
385                            offset
386                        }
387                        Some(Self::F64(_)) => {
388                            let offset = f64_offset;
389                            f64_offset += 1;
390                            offset
391                        }
392                    })
393                    .collect()
394            };
395            let children = vec![
396                as_array_ref(NullArray::new(data.iter().filter(|v| v.is_none()).count())),
397                {
398                    let u8: Vec<_> = data
399                        .iter()
400                        .filter_map(|datum| match datum.as_deref() {
401                            Some(Self::U8(v)) => Some(v.clone()),
402                            _ => None,
403                        })
404                        .collect();
405                    let u8_validity: Option<arrow::buffer::NullBuffer> = None;
406                    {
407                        let offsets = arrow::buffer::OffsetBuffer::<i32>::from_lengths(
408                            u8.iter().map(|datum| datum.len()),
409                        );
410                        let u8_inner_data: ScalarBuffer<_> = u8
411                            .iter()
412                            .map(|b| b as &[_])
413                            .collect::<Vec<_>>()
414                            .concat()
415                            .into();
416                        let u8_inner_validity: Option<arrow::buffer::NullBuffer> = None;
417                        as_array_ref(ListArray::try_new(
418                            std::sync::Arc::new(Field::new("item", DataType::UInt8, false)),
419                            offsets,
420                            as_array_ref(PrimitiveArray::<UInt8Type>::new(
421                                u8_inner_data,
422                                u8_inner_validity,
423                            )),
424                            u8_validity,
425                        )?)
426                    }
427                },
428                {
429                    let u16: Vec<_> = data
430                        .iter()
431                        .filter_map(|datum| match datum.as_deref() {
432                            Some(Self::U16(v)) => Some(v.clone()),
433                            _ => None,
434                        })
435                        .collect();
436                    let u16_validity: Option<arrow::buffer::NullBuffer> = None;
437                    {
438                        let offsets = arrow::buffer::OffsetBuffer::<i32>::from_lengths(
439                            u16.iter().map(|datum| datum.len()),
440                        );
441                        let u16_inner_data: ScalarBuffer<_> = u16
442                            .iter()
443                            .map(|b| b as &[_])
444                            .collect::<Vec<_>>()
445                            .concat()
446                            .into();
447                        let u16_inner_validity: Option<arrow::buffer::NullBuffer> = None;
448                        as_array_ref(ListArray::try_new(
449                            std::sync::Arc::new(Field::new("item", DataType::UInt16, false)),
450                            offsets,
451                            as_array_ref(PrimitiveArray::<UInt16Type>::new(
452                                u16_inner_data,
453                                u16_inner_validity,
454                            )),
455                            u16_validity,
456                        )?)
457                    }
458                },
459                {
460                    let u32: Vec<_> = data
461                        .iter()
462                        .filter_map(|datum| match datum.as_deref() {
463                            Some(Self::U32(v)) => Some(v.clone()),
464                            _ => None,
465                        })
466                        .collect();
467                    let u32_validity: Option<arrow::buffer::NullBuffer> = None;
468                    {
469                        let offsets = arrow::buffer::OffsetBuffer::<i32>::from_lengths(
470                            u32.iter().map(|datum| datum.len()),
471                        );
472                        let u32_inner_data: ScalarBuffer<_> = u32
473                            .iter()
474                            .map(|b| b as &[_])
475                            .collect::<Vec<_>>()
476                            .concat()
477                            .into();
478                        let u32_inner_validity: Option<arrow::buffer::NullBuffer> = None;
479                        as_array_ref(ListArray::try_new(
480                            std::sync::Arc::new(Field::new("item", DataType::UInt32, false)),
481                            offsets,
482                            as_array_ref(PrimitiveArray::<UInt32Type>::new(
483                                u32_inner_data,
484                                u32_inner_validity,
485                            )),
486                            u32_validity,
487                        )?)
488                    }
489                },
490                {
491                    let u64: Vec<_> = data
492                        .iter()
493                        .filter_map(|datum| match datum.as_deref() {
494                            Some(Self::U64(v)) => Some(v.clone()),
495                            _ => None,
496                        })
497                        .collect();
498                    let u64_validity: Option<arrow::buffer::NullBuffer> = None;
499                    {
500                        let offsets = arrow::buffer::OffsetBuffer::<i32>::from_lengths(
501                            u64.iter().map(|datum| datum.len()),
502                        );
503                        let u64_inner_data: ScalarBuffer<_> = u64
504                            .iter()
505                            .map(|b| b as &[_])
506                            .collect::<Vec<_>>()
507                            .concat()
508                            .into();
509                        let u64_inner_validity: Option<arrow::buffer::NullBuffer> = None;
510                        as_array_ref(ListArray::try_new(
511                            std::sync::Arc::new(Field::new("item", DataType::UInt64, false)),
512                            offsets,
513                            as_array_ref(PrimitiveArray::<UInt64Type>::new(
514                                u64_inner_data,
515                                u64_inner_validity,
516                            )),
517                            u64_validity,
518                        )?)
519                    }
520                },
521                {
522                    let i8: Vec<_> = data
523                        .iter()
524                        .filter_map(|datum| match datum.as_deref() {
525                            Some(Self::I8(v)) => Some(v.clone()),
526                            _ => None,
527                        })
528                        .collect();
529                    let i8_validity: Option<arrow::buffer::NullBuffer> = None;
530                    {
531                        let offsets = arrow::buffer::OffsetBuffer::<i32>::from_lengths(
532                            i8.iter().map(|datum| datum.len()),
533                        );
534                        let i8_inner_data: ScalarBuffer<_> = i8
535                            .iter()
536                            .map(|b| b as &[_])
537                            .collect::<Vec<_>>()
538                            .concat()
539                            .into();
540                        let i8_inner_validity: Option<arrow::buffer::NullBuffer> = None;
541                        as_array_ref(ListArray::try_new(
542                            std::sync::Arc::new(Field::new("item", DataType::Int8, false)),
543                            offsets,
544                            as_array_ref(PrimitiveArray::<Int8Type>::new(
545                                i8_inner_data,
546                                i8_inner_validity,
547                            )),
548                            i8_validity,
549                        )?)
550                    }
551                },
552                {
553                    let i16: Vec<_> = data
554                        .iter()
555                        .filter_map(|datum| match datum.as_deref() {
556                            Some(Self::I16(v)) => Some(v.clone()),
557                            _ => None,
558                        })
559                        .collect();
560                    let i16_validity: Option<arrow::buffer::NullBuffer> = None;
561                    {
562                        let offsets = arrow::buffer::OffsetBuffer::<i32>::from_lengths(
563                            i16.iter().map(|datum| datum.len()),
564                        );
565                        let i16_inner_data: ScalarBuffer<_> = i16
566                            .iter()
567                            .map(|b| b as &[_])
568                            .collect::<Vec<_>>()
569                            .concat()
570                            .into();
571                        let i16_inner_validity: Option<arrow::buffer::NullBuffer> = None;
572                        as_array_ref(ListArray::try_new(
573                            std::sync::Arc::new(Field::new("item", DataType::Int16, false)),
574                            offsets,
575                            as_array_ref(PrimitiveArray::<Int16Type>::new(
576                                i16_inner_data,
577                                i16_inner_validity,
578                            )),
579                            i16_validity,
580                        )?)
581                    }
582                },
583                {
584                    let i32: Vec<_> = data
585                        .iter()
586                        .filter_map(|datum| match datum.as_deref() {
587                            Some(Self::I32(v)) => Some(v.clone()),
588                            _ => None,
589                        })
590                        .collect();
591                    let i32_validity: Option<arrow::buffer::NullBuffer> = None;
592                    {
593                        let offsets = arrow::buffer::OffsetBuffer::<i32>::from_lengths(
594                            i32.iter().map(|datum| datum.len()),
595                        );
596                        let i32_inner_data: ScalarBuffer<_> = i32
597                            .iter()
598                            .map(|b| b as &[_])
599                            .collect::<Vec<_>>()
600                            .concat()
601                            .into();
602                        let i32_inner_validity: Option<arrow::buffer::NullBuffer> = None;
603                        as_array_ref(ListArray::try_new(
604                            std::sync::Arc::new(Field::new("item", DataType::Int32, false)),
605                            offsets,
606                            as_array_ref(PrimitiveArray::<Int32Type>::new(
607                                i32_inner_data,
608                                i32_inner_validity,
609                            )),
610                            i32_validity,
611                        )?)
612                    }
613                },
614                {
615                    let i64: Vec<_> = data
616                        .iter()
617                        .filter_map(|datum| match datum.as_deref() {
618                            Some(Self::I64(v)) => Some(v.clone()),
619                            _ => None,
620                        })
621                        .collect();
622                    let i64_validity: Option<arrow::buffer::NullBuffer> = None;
623                    {
624                        let offsets = arrow::buffer::OffsetBuffer::<i32>::from_lengths(
625                            i64.iter().map(|datum| datum.len()),
626                        );
627                        let i64_inner_data: ScalarBuffer<_> = i64
628                            .iter()
629                            .map(|b| b as &[_])
630                            .collect::<Vec<_>>()
631                            .concat()
632                            .into();
633                        let i64_inner_validity: Option<arrow::buffer::NullBuffer> = None;
634                        as_array_ref(ListArray::try_new(
635                            std::sync::Arc::new(Field::new("item", DataType::Int64, false)),
636                            offsets,
637                            as_array_ref(PrimitiveArray::<Int64Type>::new(
638                                i64_inner_data,
639                                i64_inner_validity,
640                            )),
641                            i64_validity,
642                        )?)
643                    }
644                },
645                {
646                    let f16: Vec<_> = data
647                        .iter()
648                        .filter_map(|datum| match datum.as_deref() {
649                            Some(Self::F16(v)) => Some(v.clone()),
650                            _ => None,
651                        })
652                        .collect();
653                    let f16_validity: Option<arrow::buffer::NullBuffer> = None;
654                    {
655                        let offsets = arrow::buffer::OffsetBuffer::<i32>::from_lengths(
656                            f16.iter().map(|datum| datum.len()),
657                        );
658                        let f16_inner_data: ScalarBuffer<_> = f16
659                            .iter()
660                            .map(|b| b as &[_])
661                            .collect::<Vec<_>>()
662                            .concat()
663                            .into();
664                        let f16_inner_validity: Option<arrow::buffer::NullBuffer> = None;
665                        as_array_ref(ListArray::try_new(
666                            std::sync::Arc::new(Field::new("item", DataType::Float16, false)),
667                            offsets,
668                            as_array_ref(PrimitiveArray::<Float16Type>::new(
669                                f16_inner_data,
670                                f16_inner_validity,
671                            )),
672                            f16_validity,
673                        )?)
674                    }
675                },
676                {
677                    let f32: Vec<_> = data
678                        .iter()
679                        .filter_map(|datum| match datum.as_deref() {
680                            Some(Self::F32(v)) => Some(v.clone()),
681                            _ => None,
682                        })
683                        .collect();
684                    let f32_validity: Option<arrow::buffer::NullBuffer> = None;
685                    {
686                        let offsets = arrow::buffer::OffsetBuffer::<i32>::from_lengths(
687                            f32.iter().map(|datum| datum.len()),
688                        );
689                        let f32_inner_data: ScalarBuffer<_> = f32
690                            .iter()
691                            .map(|b| b as &[_])
692                            .collect::<Vec<_>>()
693                            .concat()
694                            .into();
695                        let f32_inner_validity: Option<arrow::buffer::NullBuffer> = None;
696                        as_array_ref(ListArray::try_new(
697                            std::sync::Arc::new(Field::new("item", DataType::Float32, false)),
698                            offsets,
699                            as_array_ref(PrimitiveArray::<Float32Type>::new(
700                                f32_inner_data,
701                                f32_inner_validity,
702                            )),
703                            f32_validity,
704                        )?)
705                    }
706                },
707                {
708                    let f64: Vec<_> = data
709                        .iter()
710                        .filter_map(|datum| match datum.as_deref() {
711                            Some(Self::F64(v)) => Some(v.clone()),
712                            _ => None,
713                        })
714                        .collect();
715                    let f64_validity: Option<arrow::buffer::NullBuffer> = None;
716                    {
717                        let offsets = arrow::buffer::OffsetBuffer::<i32>::from_lengths(
718                            f64.iter().map(|datum| datum.len()),
719                        );
720                        let f64_inner_data: ScalarBuffer<_> = f64
721                            .iter()
722                            .map(|b| b as &[_])
723                            .collect::<Vec<_>>()
724                            .concat()
725                            .into();
726                        let f64_inner_validity: Option<arrow::buffer::NullBuffer> = None;
727                        as_array_ref(ListArray::try_new(
728                            std::sync::Arc::new(Field::new("item", DataType::Float64, false)),
729                            offsets,
730                            as_array_ref(PrimitiveArray::<Float64Type>::new(
731                                f64_inner_data,
732                                f64_inner_validity,
733                            )),
734                            f64_validity,
735                        )?)
736                    }
737                },
738            ];
739            debug_assert_eq!(field_type_ids.len(), fields.len());
740            debug_assert_eq!(fields.len(), children.len());
741            as_array_ref(UnionArray::try_new(
742                UnionFields::new(field_type_ids, fields),
743                ScalarBuffer::from(type_ids),
744                Some(offsets),
745                children,
746            )?)
747        })
748    }
749
750    fn from_arrow_opt(
751        arrow_data: &dyn arrow::array::Array,
752    ) -> DeserializationResult<Vec<Option<Self>>>
753    where
754        Self: Sized,
755    {
756        #![allow(clippy::wildcard_imports)]
757        use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
758        use arrow::{array::*, buffer::*, datatypes::*};
759        Ok({
760            let arrow_data = arrow_data
761                .as_any()
762                .downcast_ref::<arrow::array::UnionArray>()
763                .ok_or_else(|| {
764                    let expected = Self::arrow_datatype();
765                    let actual = arrow_data.data_type().clone();
766                    DeserializationError::datatype_mismatch(expected, actual)
767                })
768                .with_context("rerun.datatypes.TensorBuffer")?;
769            if arrow_data.is_empty() {
770                Vec::new()
771            } else {
772                let arrow_data_type_ids = arrow_data.type_ids();
773                let arrow_data_offsets = arrow_data
774                    .offsets()
775                    .ok_or_else(|| {
776                        let expected = Self::arrow_datatype();
777                        let actual = arrow_data.data_type().clone();
778                        DeserializationError::datatype_mismatch(expected, actual)
779                    })
780                    .with_context("rerun.datatypes.TensorBuffer")?;
781                if arrow_data_type_ids.len() != arrow_data_offsets.len() {
782                    return Err(DeserializationError::offset_slice_oob(
783                        (0, arrow_data_type_ids.len()),
784                        arrow_data_offsets.len(),
785                    ))
786                    .with_context("rerun.datatypes.TensorBuffer");
787                }
788                let u8 = {
789                    let arrow_data = arrow_data.child(1).as_ref();
790                    {
791                        let arrow_data = arrow_data
792                            .as_any()
793                            .downcast_ref::<arrow::array::ListArray>()
794                            .ok_or_else(|| {
795                                let expected = DataType::List(std::sync::Arc::new(Field::new(
796                                    "item",
797                                    DataType::UInt8,
798                                    false,
799                                )));
800                                let actual = arrow_data.data_type().clone();
801                                DeserializationError::datatype_mismatch(expected, actual)
802                            })
803                            .with_context("rerun.datatypes.TensorBuffer#U8")?;
804                        if arrow_data.is_empty() {
805                            Vec::new()
806                        } else {
807                            let arrow_data_inner = {
808                                let arrow_data_inner = &**arrow_data.values();
809                                arrow_data_inner
810                                    .as_any()
811                                    .downcast_ref::<UInt8Array>()
812                                    .ok_or_else(|| {
813                                        let expected = DataType::UInt8;
814                                        let actual = arrow_data_inner.data_type().clone();
815                                        DeserializationError::datatype_mismatch(expected, actual)
816                                    })
817                                    .with_context("rerun.datatypes.TensorBuffer#U8")?
818                                    .values()
819                            };
820                            let offsets = arrow_data.offsets();
821                            ZipValidity::new_with_validity(offsets.windows(2), arrow_data.nulls())
822                                .map(|elem| {
823                                    elem.map(|window| {
824                                        let start = window[0] as usize;
825                                        let end = window[1] as usize;
826                                        if arrow_data_inner.len() < end {
827                                            return Err(DeserializationError::offset_slice_oob(
828                                                (start, end),
829                                                arrow_data_inner.len(),
830                                            ));
831                                        }
832
833                                        #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
834                                        let data =
835                                            arrow_data_inner.clone().slice(start, end - start);
836                                        Ok(data)
837                                    })
838                                    .transpose()
839                                })
840                                .collect::<DeserializationResult<Vec<Option<_>>>>()?
841                        }
842                        .into_iter()
843                    }
844                    .collect::<Vec<_>>()
845                };
846                let u16 = {
847                    let arrow_data = arrow_data.child(2).as_ref();
848                    {
849                        let arrow_data = arrow_data
850                            .as_any()
851                            .downcast_ref::<arrow::array::ListArray>()
852                            .ok_or_else(|| {
853                                let expected = DataType::List(std::sync::Arc::new(Field::new(
854                                    "item",
855                                    DataType::UInt16,
856                                    false,
857                                )));
858                                let actual = arrow_data.data_type().clone();
859                                DeserializationError::datatype_mismatch(expected, actual)
860                            })
861                            .with_context("rerun.datatypes.TensorBuffer#U16")?;
862                        if arrow_data.is_empty() {
863                            Vec::new()
864                        } else {
865                            let arrow_data_inner = {
866                                let arrow_data_inner = &**arrow_data.values();
867                                arrow_data_inner
868                                    .as_any()
869                                    .downcast_ref::<UInt16Array>()
870                                    .ok_or_else(|| {
871                                        let expected = DataType::UInt16;
872                                        let actual = arrow_data_inner.data_type().clone();
873                                        DeserializationError::datatype_mismatch(expected, actual)
874                                    })
875                                    .with_context("rerun.datatypes.TensorBuffer#U16")?
876                                    .values()
877                            };
878                            let offsets = arrow_data.offsets();
879                            ZipValidity::new_with_validity(offsets.windows(2), arrow_data.nulls())
880                                .map(|elem| {
881                                    elem.map(|window| {
882                                        let start = window[0] as usize;
883                                        let end = window[1] as usize;
884                                        if arrow_data_inner.len() < end {
885                                            return Err(DeserializationError::offset_slice_oob(
886                                                (start, end),
887                                                arrow_data_inner.len(),
888                                            ));
889                                        }
890
891                                        #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
892                                        let data =
893                                            arrow_data_inner.clone().slice(start, end - start);
894                                        Ok(data)
895                                    })
896                                    .transpose()
897                                })
898                                .collect::<DeserializationResult<Vec<Option<_>>>>()?
899                        }
900                        .into_iter()
901                    }
902                    .collect::<Vec<_>>()
903                };
904                let u32 = {
905                    let arrow_data = arrow_data.child(3).as_ref();
906                    {
907                        let arrow_data = arrow_data
908                            .as_any()
909                            .downcast_ref::<arrow::array::ListArray>()
910                            .ok_or_else(|| {
911                                let expected = DataType::List(std::sync::Arc::new(Field::new(
912                                    "item",
913                                    DataType::UInt32,
914                                    false,
915                                )));
916                                let actual = arrow_data.data_type().clone();
917                                DeserializationError::datatype_mismatch(expected, actual)
918                            })
919                            .with_context("rerun.datatypes.TensorBuffer#U32")?;
920                        if arrow_data.is_empty() {
921                            Vec::new()
922                        } else {
923                            let arrow_data_inner = {
924                                let arrow_data_inner = &**arrow_data.values();
925                                arrow_data_inner
926                                    .as_any()
927                                    .downcast_ref::<UInt32Array>()
928                                    .ok_or_else(|| {
929                                        let expected = DataType::UInt32;
930                                        let actual = arrow_data_inner.data_type().clone();
931                                        DeserializationError::datatype_mismatch(expected, actual)
932                                    })
933                                    .with_context("rerun.datatypes.TensorBuffer#U32")?
934                                    .values()
935                            };
936                            let offsets = arrow_data.offsets();
937                            ZipValidity::new_with_validity(offsets.windows(2), arrow_data.nulls())
938                                .map(|elem| {
939                                    elem.map(|window| {
940                                        let start = window[0] as usize;
941                                        let end = window[1] as usize;
942                                        if arrow_data_inner.len() < end {
943                                            return Err(DeserializationError::offset_slice_oob(
944                                                (start, end),
945                                                arrow_data_inner.len(),
946                                            ));
947                                        }
948
949                                        #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
950                                        let data =
951                                            arrow_data_inner.clone().slice(start, end - start);
952                                        Ok(data)
953                                    })
954                                    .transpose()
955                                })
956                                .collect::<DeserializationResult<Vec<Option<_>>>>()?
957                        }
958                        .into_iter()
959                    }
960                    .collect::<Vec<_>>()
961                };
962                let u64 = {
963                    let arrow_data = arrow_data.child(4).as_ref();
964                    {
965                        let arrow_data = arrow_data
966                            .as_any()
967                            .downcast_ref::<arrow::array::ListArray>()
968                            .ok_or_else(|| {
969                                let expected = DataType::List(std::sync::Arc::new(Field::new(
970                                    "item",
971                                    DataType::UInt64,
972                                    false,
973                                )));
974                                let actual = arrow_data.data_type().clone();
975                                DeserializationError::datatype_mismatch(expected, actual)
976                            })
977                            .with_context("rerun.datatypes.TensorBuffer#U64")?;
978                        if arrow_data.is_empty() {
979                            Vec::new()
980                        } else {
981                            let arrow_data_inner = {
982                                let arrow_data_inner = &**arrow_data.values();
983                                arrow_data_inner
984                                    .as_any()
985                                    .downcast_ref::<UInt64Array>()
986                                    .ok_or_else(|| {
987                                        let expected = DataType::UInt64;
988                                        let actual = arrow_data_inner.data_type().clone();
989                                        DeserializationError::datatype_mismatch(expected, actual)
990                                    })
991                                    .with_context("rerun.datatypes.TensorBuffer#U64")?
992                                    .values()
993                            };
994                            let offsets = arrow_data.offsets();
995                            ZipValidity::new_with_validity(offsets.windows(2), arrow_data.nulls())
996                                .map(|elem| {
997                                    elem.map(|window| {
998                                        let start = window[0] as usize;
999                                        let end = window[1] as usize;
1000                                        if arrow_data_inner.len() < end {
1001                                            return Err(DeserializationError::offset_slice_oob(
1002                                                (start, end),
1003                                                arrow_data_inner.len(),
1004                                            ));
1005                                        }
1006
1007                                        #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1008                                        let data =
1009                                            arrow_data_inner.clone().slice(start, end - start);
1010                                        Ok(data)
1011                                    })
1012                                    .transpose()
1013                                })
1014                                .collect::<DeserializationResult<Vec<Option<_>>>>()?
1015                        }
1016                        .into_iter()
1017                    }
1018                    .collect::<Vec<_>>()
1019                };
1020                let i8 = {
1021                    let arrow_data = arrow_data.child(5).as_ref();
1022                    {
1023                        let arrow_data = arrow_data
1024                            .as_any()
1025                            .downcast_ref::<arrow::array::ListArray>()
1026                            .ok_or_else(|| {
1027                                let expected = DataType::List(std::sync::Arc::new(Field::new(
1028                                    "item",
1029                                    DataType::Int8,
1030                                    false,
1031                                )));
1032                                let actual = arrow_data.data_type().clone();
1033                                DeserializationError::datatype_mismatch(expected, actual)
1034                            })
1035                            .with_context("rerun.datatypes.TensorBuffer#I8")?;
1036                        if arrow_data.is_empty() {
1037                            Vec::new()
1038                        } else {
1039                            let arrow_data_inner = {
1040                                let arrow_data_inner = &**arrow_data.values();
1041                                arrow_data_inner
1042                                    .as_any()
1043                                    .downcast_ref::<Int8Array>()
1044                                    .ok_or_else(|| {
1045                                        let expected = DataType::Int8;
1046                                        let actual = arrow_data_inner.data_type().clone();
1047                                        DeserializationError::datatype_mismatch(expected, actual)
1048                                    })
1049                                    .with_context("rerun.datatypes.TensorBuffer#I8")?
1050                                    .values()
1051                            };
1052                            let offsets = arrow_data.offsets();
1053                            ZipValidity::new_with_validity(offsets.windows(2), arrow_data.nulls())
1054                                .map(|elem| {
1055                                    elem.map(|window| {
1056                                        let start = window[0] as usize;
1057                                        let end = window[1] as usize;
1058                                        if arrow_data_inner.len() < end {
1059                                            return Err(DeserializationError::offset_slice_oob(
1060                                                (start, end),
1061                                                arrow_data_inner.len(),
1062                                            ));
1063                                        }
1064
1065                                        #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1066                                        let data =
1067                                            arrow_data_inner.clone().slice(start, end - start);
1068                                        Ok(data)
1069                                    })
1070                                    .transpose()
1071                                })
1072                                .collect::<DeserializationResult<Vec<Option<_>>>>()?
1073                        }
1074                        .into_iter()
1075                    }
1076                    .collect::<Vec<_>>()
1077                };
1078                let i16 = {
1079                    let arrow_data = arrow_data.child(6).as_ref();
1080                    {
1081                        let arrow_data = arrow_data
1082                            .as_any()
1083                            .downcast_ref::<arrow::array::ListArray>()
1084                            .ok_or_else(|| {
1085                                let expected = DataType::List(std::sync::Arc::new(Field::new(
1086                                    "item",
1087                                    DataType::Int16,
1088                                    false,
1089                                )));
1090                                let actual = arrow_data.data_type().clone();
1091                                DeserializationError::datatype_mismatch(expected, actual)
1092                            })
1093                            .with_context("rerun.datatypes.TensorBuffer#I16")?;
1094                        if arrow_data.is_empty() {
1095                            Vec::new()
1096                        } else {
1097                            let arrow_data_inner = {
1098                                let arrow_data_inner = &**arrow_data.values();
1099                                arrow_data_inner
1100                                    .as_any()
1101                                    .downcast_ref::<Int16Array>()
1102                                    .ok_or_else(|| {
1103                                        let expected = DataType::Int16;
1104                                        let actual = arrow_data_inner.data_type().clone();
1105                                        DeserializationError::datatype_mismatch(expected, actual)
1106                                    })
1107                                    .with_context("rerun.datatypes.TensorBuffer#I16")?
1108                                    .values()
1109                            };
1110                            let offsets = arrow_data.offsets();
1111                            ZipValidity::new_with_validity(offsets.windows(2), arrow_data.nulls())
1112                                .map(|elem| {
1113                                    elem.map(|window| {
1114                                        let start = window[0] as usize;
1115                                        let end = window[1] as usize;
1116                                        if arrow_data_inner.len() < end {
1117                                            return Err(DeserializationError::offset_slice_oob(
1118                                                (start, end),
1119                                                arrow_data_inner.len(),
1120                                            ));
1121                                        }
1122
1123                                        #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1124                                        let data =
1125                                            arrow_data_inner.clone().slice(start, end - start);
1126                                        Ok(data)
1127                                    })
1128                                    .transpose()
1129                                })
1130                                .collect::<DeserializationResult<Vec<Option<_>>>>()?
1131                        }
1132                        .into_iter()
1133                    }
1134                    .collect::<Vec<_>>()
1135                };
1136                let i32 = {
1137                    let arrow_data = arrow_data.child(7).as_ref();
1138                    {
1139                        let arrow_data = arrow_data
1140                            .as_any()
1141                            .downcast_ref::<arrow::array::ListArray>()
1142                            .ok_or_else(|| {
1143                                let expected = DataType::List(std::sync::Arc::new(Field::new(
1144                                    "item",
1145                                    DataType::Int32,
1146                                    false,
1147                                )));
1148                                let actual = arrow_data.data_type().clone();
1149                                DeserializationError::datatype_mismatch(expected, actual)
1150                            })
1151                            .with_context("rerun.datatypes.TensorBuffer#I32")?;
1152                        if arrow_data.is_empty() {
1153                            Vec::new()
1154                        } else {
1155                            let arrow_data_inner = {
1156                                let arrow_data_inner = &**arrow_data.values();
1157                                arrow_data_inner
1158                                    .as_any()
1159                                    .downcast_ref::<Int32Array>()
1160                                    .ok_or_else(|| {
1161                                        let expected = DataType::Int32;
1162                                        let actual = arrow_data_inner.data_type().clone();
1163                                        DeserializationError::datatype_mismatch(expected, actual)
1164                                    })
1165                                    .with_context("rerun.datatypes.TensorBuffer#I32")?
1166                                    .values()
1167                            };
1168                            let offsets = arrow_data.offsets();
1169                            ZipValidity::new_with_validity(offsets.windows(2), arrow_data.nulls())
1170                                .map(|elem| {
1171                                    elem.map(|window| {
1172                                        let start = window[0] as usize;
1173                                        let end = window[1] as usize;
1174                                        if arrow_data_inner.len() < end {
1175                                            return Err(DeserializationError::offset_slice_oob(
1176                                                (start, end),
1177                                                arrow_data_inner.len(),
1178                                            ));
1179                                        }
1180
1181                                        #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1182                                        let data =
1183                                            arrow_data_inner.clone().slice(start, end - start);
1184                                        Ok(data)
1185                                    })
1186                                    .transpose()
1187                                })
1188                                .collect::<DeserializationResult<Vec<Option<_>>>>()?
1189                        }
1190                        .into_iter()
1191                    }
1192                    .collect::<Vec<_>>()
1193                };
1194                let i64 = {
1195                    let arrow_data = arrow_data.child(8).as_ref();
1196                    {
1197                        let arrow_data = arrow_data
1198                            .as_any()
1199                            .downcast_ref::<arrow::array::ListArray>()
1200                            .ok_or_else(|| {
1201                                let expected = DataType::List(std::sync::Arc::new(Field::new(
1202                                    "item",
1203                                    DataType::Int64,
1204                                    false,
1205                                )));
1206                                let actual = arrow_data.data_type().clone();
1207                                DeserializationError::datatype_mismatch(expected, actual)
1208                            })
1209                            .with_context("rerun.datatypes.TensorBuffer#I64")?;
1210                        if arrow_data.is_empty() {
1211                            Vec::new()
1212                        } else {
1213                            let arrow_data_inner = {
1214                                let arrow_data_inner = &**arrow_data.values();
1215                                arrow_data_inner
1216                                    .as_any()
1217                                    .downcast_ref::<Int64Array>()
1218                                    .ok_or_else(|| {
1219                                        let expected = DataType::Int64;
1220                                        let actual = arrow_data_inner.data_type().clone();
1221                                        DeserializationError::datatype_mismatch(expected, actual)
1222                                    })
1223                                    .with_context("rerun.datatypes.TensorBuffer#I64")?
1224                                    .values()
1225                            };
1226                            let offsets = arrow_data.offsets();
1227                            ZipValidity::new_with_validity(offsets.windows(2), arrow_data.nulls())
1228                                .map(|elem| {
1229                                    elem.map(|window| {
1230                                        let start = window[0] as usize;
1231                                        let end = window[1] as usize;
1232                                        if arrow_data_inner.len() < end {
1233                                            return Err(DeserializationError::offset_slice_oob(
1234                                                (start, end),
1235                                                arrow_data_inner.len(),
1236                                            ));
1237                                        }
1238
1239                                        #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1240                                        let data =
1241                                            arrow_data_inner.clone().slice(start, end - start);
1242                                        Ok(data)
1243                                    })
1244                                    .transpose()
1245                                })
1246                                .collect::<DeserializationResult<Vec<Option<_>>>>()?
1247                        }
1248                        .into_iter()
1249                    }
1250                    .collect::<Vec<_>>()
1251                };
1252                let f16 = {
1253                    let arrow_data = arrow_data.child(9).as_ref();
1254                    {
1255                        let arrow_data = arrow_data
1256                            .as_any()
1257                            .downcast_ref::<arrow::array::ListArray>()
1258                            .ok_or_else(|| {
1259                                let expected = DataType::List(std::sync::Arc::new(Field::new(
1260                                    "item",
1261                                    DataType::Float16,
1262                                    false,
1263                                )));
1264                                let actual = arrow_data.data_type().clone();
1265                                DeserializationError::datatype_mismatch(expected, actual)
1266                            })
1267                            .with_context("rerun.datatypes.TensorBuffer#F16")?;
1268                        if arrow_data.is_empty() {
1269                            Vec::new()
1270                        } else {
1271                            let arrow_data_inner = {
1272                                let arrow_data_inner = &**arrow_data.values();
1273                                arrow_data_inner
1274                                    .as_any()
1275                                    .downcast_ref::<Float16Array>()
1276                                    .ok_or_else(|| {
1277                                        let expected = DataType::Float16;
1278                                        let actual = arrow_data_inner.data_type().clone();
1279                                        DeserializationError::datatype_mismatch(expected, actual)
1280                                    })
1281                                    .with_context("rerun.datatypes.TensorBuffer#F16")?
1282                                    .values()
1283                            };
1284                            let offsets = arrow_data.offsets();
1285                            ZipValidity::new_with_validity(offsets.windows(2), arrow_data.nulls())
1286                                .map(|elem| {
1287                                    elem.map(|window| {
1288                                        let start = window[0] as usize;
1289                                        let end = window[1] as usize;
1290                                        if arrow_data_inner.len() < end {
1291                                            return Err(DeserializationError::offset_slice_oob(
1292                                                (start, end),
1293                                                arrow_data_inner.len(),
1294                                            ));
1295                                        }
1296
1297                                        #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1298                                        let data =
1299                                            arrow_data_inner.clone().slice(start, end - start);
1300                                        Ok(data)
1301                                    })
1302                                    .transpose()
1303                                })
1304                                .collect::<DeserializationResult<Vec<Option<_>>>>()?
1305                        }
1306                        .into_iter()
1307                    }
1308                    .collect::<Vec<_>>()
1309                };
1310                let f32 = {
1311                    let arrow_data = arrow_data.child(10).as_ref();
1312                    {
1313                        let arrow_data = arrow_data
1314                            .as_any()
1315                            .downcast_ref::<arrow::array::ListArray>()
1316                            .ok_or_else(|| {
1317                                let expected = DataType::List(std::sync::Arc::new(Field::new(
1318                                    "item",
1319                                    DataType::Float32,
1320                                    false,
1321                                )));
1322                                let actual = arrow_data.data_type().clone();
1323                                DeserializationError::datatype_mismatch(expected, actual)
1324                            })
1325                            .with_context("rerun.datatypes.TensorBuffer#F32")?;
1326                        if arrow_data.is_empty() {
1327                            Vec::new()
1328                        } else {
1329                            let arrow_data_inner = {
1330                                let arrow_data_inner = &**arrow_data.values();
1331                                arrow_data_inner
1332                                    .as_any()
1333                                    .downcast_ref::<Float32Array>()
1334                                    .ok_or_else(|| {
1335                                        let expected = DataType::Float32;
1336                                        let actual = arrow_data_inner.data_type().clone();
1337                                        DeserializationError::datatype_mismatch(expected, actual)
1338                                    })
1339                                    .with_context("rerun.datatypes.TensorBuffer#F32")?
1340                                    .values()
1341                            };
1342                            let offsets = arrow_data.offsets();
1343                            ZipValidity::new_with_validity(offsets.windows(2), arrow_data.nulls())
1344                                .map(|elem| {
1345                                    elem.map(|window| {
1346                                        let start = window[0] as usize;
1347                                        let end = window[1] as usize;
1348                                        if arrow_data_inner.len() < end {
1349                                            return Err(DeserializationError::offset_slice_oob(
1350                                                (start, end),
1351                                                arrow_data_inner.len(),
1352                                            ));
1353                                        }
1354
1355                                        #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1356                                        let data =
1357                                            arrow_data_inner.clone().slice(start, end - start);
1358                                        Ok(data)
1359                                    })
1360                                    .transpose()
1361                                })
1362                                .collect::<DeserializationResult<Vec<Option<_>>>>()?
1363                        }
1364                        .into_iter()
1365                    }
1366                    .collect::<Vec<_>>()
1367                };
1368                let f64 = {
1369                    let arrow_data = arrow_data.child(11).as_ref();
1370                    {
1371                        let arrow_data = arrow_data
1372                            .as_any()
1373                            .downcast_ref::<arrow::array::ListArray>()
1374                            .ok_or_else(|| {
1375                                let expected = DataType::List(std::sync::Arc::new(Field::new(
1376                                    "item",
1377                                    DataType::Float64,
1378                                    false,
1379                                )));
1380                                let actual = arrow_data.data_type().clone();
1381                                DeserializationError::datatype_mismatch(expected, actual)
1382                            })
1383                            .with_context("rerun.datatypes.TensorBuffer#F64")?;
1384                        if arrow_data.is_empty() {
1385                            Vec::new()
1386                        } else {
1387                            let arrow_data_inner = {
1388                                let arrow_data_inner = &**arrow_data.values();
1389                                arrow_data_inner
1390                                    .as_any()
1391                                    .downcast_ref::<Float64Array>()
1392                                    .ok_or_else(|| {
1393                                        let expected = DataType::Float64;
1394                                        let actual = arrow_data_inner.data_type().clone();
1395                                        DeserializationError::datatype_mismatch(expected, actual)
1396                                    })
1397                                    .with_context("rerun.datatypes.TensorBuffer#F64")?
1398                                    .values()
1399                            };
1400                            let offsets = arrow_data.offsets();
1401                            ZipValidity::new_with_validity(offsets.windows(2), arrow_data.nulls())
1402                                .map(|elem| {
1403                                    elem.map(|window| {
1404                                        let start = window[0] as usize;
1405                                        let end = window[1] as usize;
1406                                        if arrow_data_inner.len() < end {
1407                                            return Err(DeserializationError::offset_slice_oob(
1408                                                (start, end),
1409                                                arrow_data_inner.len(),
1410                                            ));
1411                                        }
1412
1413                                        #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1414                                        let data =
1415                                            arrow_data_inner.clone().slice(start, end - start);
1416                                        Ok(data)
1417                                    })
1418                                    .transpose()
1419                                })
1420                                .collect::<DeserializationResult<Vec<Option<_>>>>()?
1421                        }
1422                        .into_iter()
1423                    }
1424                    .collect::<Vec<_>>()
1425                };
1426                arrow_data_type_ids
1427                    .iter()
1428                    .enumerate()
1429                    .map(|(i, typ)| {
1430                        let offset = arrow_data_offsets[i];
1431                        if *typ == 0 {
1432                            Ok(None)
1433                        } else {
1434                            Ok(Some(match typ {
1435                                1i8 => Self::U8({
1436                                    if offset as usize >= u8.len() {
1437                                        return Err(DeserializationError::offset_oob(
1438                                            offset as _,
1439                                            u8.len(),
1440                                        ))
1441                                        .with_context("rerun.datatypes.TensorBuffer#U8");
1442                                    }
1443
1444                                    #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1445                                    unsafe { u8.get_unchecked(offset as usize) }
1446                                        .clone()
1447                                        .ok_or_else(DeserializationError::missing_data)
1448                                        .with_context("rerun.datatypes.TensorBuffer#U8")?
1449                                }),
1450                                2i8 => Self::U16({
1451                                    if offset as usize >= u16.len() {
1452                                        return Err(DeserializationError::offset_oob(
1453                                            offset as _,
1454                                            u16.len(),
1455                                        ))
1456                                        .with_context("rerun.datatypes.TensorBuffer#U16");
1457                                    }
1458
1459                                    #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1460                                    unsafe { u16.get_unchecked(offset as usize) }
1461                                        .clone()
1462                                        .ok_or_else(DeserializationError::missing_data)
1463                                        .with_context("rerun.datatypes.TensorBuffer#U16")?
1464                                }),
1465                                3i8 => Self::U32({
1466                                    if offset as usize >= u32.len() {
1467                                        return Err(DeserializationError::offset_oob(
1468                                            offset as _,
1469                                            u32.len(),
1470                                        ))
1471                                        .with_context("rerun.datatypes.TensorBuffer#U32");
1472                                    }
1473
1474                                    #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1475                                    unsafe { u32.get_unchecked(offset as usize) }
1476                                        .clone()
1477                                        .ok_or_else(DeserializationError::missing_data)
1478                                        .with_context("rerun.datatypes.TensorBuffer#U32")?
1479                                }),
1480                                4i8 => Self::U64({
1481                                    if offset as usize >= u64.len() {
1482                                        return Err(DeserializationError::offset_oob(
1483                                            offset as _,
1484                                            u64.len(),
1485                                        ))
1486                                        .with_context("rerun.datatypes.TensorBuffer#U64");
1487                                    }
1488
1489                                    #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1490                                    unsafe { u64.get_unchecked(offset as usize) }
1491                                        .clone()
1492                                        .ok_or_else(DeserializationError::missing_data)
1493                                        .with_context("rerun.datatypes.TensorBuffer#U64")?
1494                                }),
1495                                5i8 => Self::I8({
1496                                    if offset as usize >= i8.len() {
1497                                        return Err(DeserializationError::offset_oob(
1498                                            offset as _,
1499                                            i8.len(),
1500                                        ))
1501                                        .with_context("rerun.datatypes.TensorBuffer#I8");
1502                                    }
1503
1504                                    #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1505                                    unsafe { i8.get_unchecked(offset as usize) }
1506                                        .clone()
1507                                        .ok_or_else(DeserializationError::missing_data)
1508                                        .with_context("rerun.datatypes.TensorBuffer#I8")?
1509                                }),
1510                                6i8 => Self::I16({
1511                                    if offset as usize >= i16.len() {
1512                                        return Err(DeserializationError::offset_oob(
1513                                            offset as _,
1514                                            i16.len(),
1515                                        ))
1516                                        .with_context("rerun.datatypes.TensorBuffer#I16");
1517                                    }
1518
1519                                    #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1520                                    unsafe { i16.get_unchecked(offset as usize) }
1521                                        .clone()
1522                                        .ok_or_else(DeserializationError::missing_data)
1523                                        .with_context("rerun.datatypes.TensorBuffer#I16")?
1524                                }),
1525                                7i8 => Self::I32({
1526                                    if offset as usize >= i32.len() {
1527                                        return Err(DeserializationError::offset_oob(
1528                                            offset as _,
1529                                            i32.len(),
1530                                        ))
1531                                        .with_context("rerun.datatypes.TensorBuffer#I32");
1532                                    }
1533
1534                                    #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1535                                    unsafe { i32.get_unchecked(offset as usize) }
1536                                        .clone()
1537                                        .ok_or_else(DeserializationError::missing_data)
1538                                        .with_context("rerun.datatypes.TensorBuffer#I32")?
1539                                }),
1540                                8i8 => Self::I64({
1541                                    if offset as usize >= i64.len() {
1542                                        return Err(DeserializationError::offset_oob(
1543                                            offset as _,
1544                                            i64.len(),
1545                                        ))
1546                                        .with_context("rerun.datatypes.TensorBuffer#I64");
1547                                    }
1548
1549                                    #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1550                                    unsafe { i64.get_unchecked(offset as usize) }
1551                                        .clone()
1552                                        .ok_or_else(DeserializationError::missing_data)
1553                                        .with_context("rerun.datatypes.TensorBuffer#I64")?
1554                                }),
1555                                9i8 => Self::F16({
1556                                    if offset as usize >= f16.len() {
1557                                        return Err(DeserializationError::offset_oob(
1558                                            offset as _,
1559                                            f16.len(),
1560                                        ))
1561                                        .with_context("rerun.datatypes.TensorBuffer#F16");
1562                                    }
1563
1564                                    #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1565                                    unsafe { f16.get_unchecked(offset as usize) }
1566                                        .clone()
1567                                        .ok_or_else(DeserializationError::missing_data)
1568                                        .with_context("rerun.datatypes.TensorBuffer#F16")?
1569                                }),
1570                                10i8 => Self::F32({
1571                                    if offset as usize >= f32.len() {
1572                                        return Err(DeserializationError::offset_oob(
1573                                            offset as _,
1574                                            f32.len(),
1575                                        ))
1576                                        .with_context("rerun.datatypes.TensorBuffer#F32");
1577                                    }
1578
1579                                    #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1580                                    unsafe { f32.get_unchecked(offset as usize) }
1581                                        .clone()
1582                                        .ok_or_else(DeserializationError::missing_data)
1583                                        .with_context("rerun.datatypes.TensorBuffer#F32")?
1584                                }),
1585                                11i8 => Self::F64({
1586                                    if offset as usize >= f64.len() {
1587                                        return Err(DeserializationError::offset_oob(
1588                                            offset as _,
1589                                            f64.len(),
1590                                        ))
1591                                        .with_context("rerun.datatypes.TensorBuffer#F64");
1592                                    }
1593
1594                                    #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
1595                                    unsafe { f64.get_unchecked(offset as usize) }
1596                                        .clone()
1597                                        .ok_or_else(DeserializationError::missing_data)
1598                                        .with_context("rerun.datatypes.TensorBuffer#F64")?
1599                                }),
1600                                _ => {
1601                                    return Err(DeserializationError::missing_union_arm(
1602                                        Self::arrow_datatype(),
1603                                        "<invalid>",
1604                                        *typ as _,
1605                                    ));
1606                                }
1607                            }))
1608                        }
1609                    })
1610                    .collect::<DeserializationResult<Vec<_>>>()
1611                    .with_context("rerun.datatypes.TensorBuffer")?
1612            }
1613        })
1614    }
1615}
1616
1617impl ::re_byte_size::SizeBytes for TensorBuffer {
1618    #[inline]
1619    fn heap_size_bytes(&self) -> u64 {
1620        #![allow(clippy::match_same_arms)]
1621        match self {
1622            Self::U8(v) => v.heap_size_bytes(),
1623            Self::U16(v) => v.heap_size_bytes(),
1624            Self::U32(v) => v.heap_size_bytes(),
1625            Self::U64(v) => v.heap_size_bytes(),
1626            Self::I8(v) => v.heap_size_bytes(),
1627            Self::I16(v) => v.heap_size_bytes(),
1628            Self::I32(v) => v.heap_size_bytes(),
1629            Self::I64(v) => v.heap_size_bytes(),
1630            Self::F16(v) => v.heap_size_bytes(),
1631            Self::F32(v) => v.heap_size_bytes(),
1632            Self::F64(v) => v.heap_size_bytes(),
1633        }
1634    }
1635
1636    #[inline]
1637    fn is_pod() -> bool {
1638        <::arrow::buffer::ScalarBuffer<u8>>::is_pod()
1639            && <::arrow::buffer::ScalarBuffer<u16>>::is_pod()
1640            && <::arrow::buffer::ScalarBuffer<u32>>::is_pod()
1641            && <::arrow::buffer::ScalarBuffer<u64>>::is_pod()
1642            && <::arrow::buffer::ScalarBuffer<i8>>::is_pod()
1643            && <::arrow::buffer::ScalarBuffer<i16>>::is_pod()
1644            && <::arrow::buffer::ScalarBuffer<i32>>::is_pod()
1645            && <::arrow::buffer::ScalarBuffer<i64>>::is_pod()
1646            && <::arrow::buffer::ScalarBuffer<half::f16>>::is_pod()
1647            && <::arrow::buffer::ScalarBuffer<f32>>::is_pod()
1648            && <::arrow::buffer::ScalarBuffer<f64>>::is_pod()
1649    }
1650}