Rerun C++ SDK
Loading...
Searching...
No Matches
arrow_serialization.hpp
1#pragma once
2
3#include <cstddef>
4#include <memory>
5
6#include "loggable.hpp"
7#include "result.hpp"
8
9// Implementation-only: do not include from public SDK headers.
10namespace arrow {
11 class Array;
12 class ArrayBuilder;
13 class DataType;
14} // namespace arrow
15
16namespace rerun::detail {
17 using ArrowFill = Error (*)(arrow::ArrayBuilder*, const void*, size_t);
18
19 // The datatype must create the builder expected by fill, and instances must point to
20 // count objects of the type expected by fill. The callback is invoked at most once.
21 // Null instances or zero count produce an empty array without invoking fill.
22 Result<std::shared_ptr<arrow::Array>> serialize_arrow(
23 const std::shared_ptr<arrow::DataType>& datatype, const void* instances, size_t count,
24 ArrowFill fill
25 );
26
27 /// Adapts a Loggable's typed fill method to the shared builder lifecycle.
28 /// Builder must match both Loggable<T>::arrow_data_type() and its fill method.
29 /// Builder must be complete when this template is instantiated.
30 template <typename Builder, typename T>
31 Result<std::shared_ptr<arrow::Array>> serialize_arrow(const T* instances, size_t count) {
32 return serialize_arrow(
33 Loggable<T>::arrow_data_type(),
34 instances,
35 count,
36 [](arrow::ArrayBuilder* builder, const void* elements, size_t num_elements) {
37 return Loggable<T>::fill_arrow_array_builder(
38 static_cast<Builder*>(builder),
39 static_cast<const T*>(elements),
40 num_elements
41 );
42 }
43 );
44 }
45
46 /// Checks that the array builder and input elements are non-null, even for an empty batch.
47 /// Returns UnexpectedNullArgument for a null pointer, checking the builder first, or Ok otherwise.
48 /// Does not dereference the pointers or check their types or available capacity.
49 Error check_arrow_builder_arguments(const arrow::ArrayBuilder* builder, const void* elements);
50} // namespace rerun::detail