namespace mrpt::obs::internal

Overview

Internal helpers to store numeric arrays in schema (JSON) archives as base64 blobs, much smaller and faster than one JSON number per element.

Each array is written as {"dtype": "<f4", "base64": "..."}, where dtype uses NumPy notation for the little-endian element type, so in Python: np.frombuffer(base64.b64decode(d["base64"]), dtype=d["dtype"]).

namespace internal {

// global functions

template <typename T>
constexpr const char* schemaDType();

template <typename VECTOR>
void writeBase64Array(mrpt::serialization::CSchemeArchiveBase entry, const VECTOR& v);

template <typename VECTOR>
void readBase64Array(mrpt::serialization::CSchemeArchiveBase entry, VECTOR& v);

template <typename MATRIX>
void writeBase64Matrix(mrpt::serialization::CSchemeArchiveBase entry, const MATRIX& m);

template <typename MATRIX>
void readBase64Matrix(mrpt::serialization::CSchemeArchiveBase entry, MATRIX& m);

} // namespace internal

Global Functions

template <typename VECTOR>
void writeBase64Array(mrpt::serialization::CSchemeArchiveBase entry, const VECTOR& v)

Writes v into entry as {“dtype”, “base64”} (little-endian elements).

template <typename VECTOR>
void readBase64Array(mrpt::serialization::CSchemeArchiveBase entry, VECTOR& v)

Reads what writeBase64Array() wrote into v, resizing it.

Throws if the dtype does not match or the data is not a whole number of elements.

template <typename MATRIX>
void writeBase64Matrix(mrpt::serialization::CSchemeArchiveBase entry, const MATRIX& m)

Writes matrix m as {“rows”, “cols”, “dtype”, “base64”}, with the elements in row-major order (in NumPy: .reshape(rows, cols)).

template <typename MATRIX>
void readBase64Matrix(mrpt::serialization::CSchemeArchiveBase entry, MATRIX& m)

Reads what writeBase64Matrix() wrote into m, resizing it.

Throws if the data does not hold exactly rows*cols elements.