WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
StructProto.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <fmt/format.h>
8
12
13template <int Rows, int Cols, int Options, int MaxRows, int MaxCols>
14 requires(Cols != 1)
17 static constexpr ct_string kTypeName =
19 "_"_ct_string, wpi::util::NumToCtString<Cols>());
20 static constexpr std::string_view GetTypeName() { return kTypeName; }
21 static constexpr size_t GetSize() { return Rows * Cols * 8; }
22 static constexpr ct_string kSchema =
23 wpi::util::Concat("double data["_ct_string,
25 static constexpr std::string_view GetSchema() { return kSchema; }
26
28 std::span<const uint8_t> data) {
29 constexpr size_t kDataOff = 0;
33 for (int i = 0; i < Rows * Cols; i++) {
34 mat(i) = mat_data[i];
35 }
36 return mat;
37 }
38
39 static void Pack(
40 std::span<uint8_t> data,
42 constexpr size_t kDataOff = 0;
44 for (int i = 0; i < Rows * Cols; i++) {
45 mat_data[i] = value(i);
46 }
48 }
49};
50
This class is a wrapper around std::array that does compile time size checking.
Definition array.hpp:26
Specifies that a type is capable of raw struct serialization and deserialization.
Definition Struct.hpp:69
Eigen::Matrix< double, Rows, Cols, Options, MaxRows, MaxCols > Matrixd
Definition EigenCore.hpp:21
constexpr empty_array_t empty_array
Definition array.hpp:16
void PackStructArray(std::span< uint8_t > data, const wpi::util::array< T, N > &arr)
Pack a serialized struct array starting at a given offset within the data.
Definition Struct.hpp:234
constexpr auto NumToCtString()
Converts any integral to a ct_string at compile-time.
Definition ct_string.hpp:202
constexpr auto Concat(ct_string< Char, Traits, N1 > const &s1, ct_string< Char, Traits, N > const &... s)
Concatenates multiple fixed_strings into a larger fixed_string at compile time.
Definition ct_string.hpp:168
wpi::util::array< T, N > UnpackStructArray(std::span< const uint8_t > data)
Unpack a serialized struct array starting at a given offset within the data.
Definition Struct.hpp:172
static void Pack(std::span< uint8_t > data, const wpi::math::Matrixd< Rows, Cols, Options, MaxRows, MaxCols > &value)
Definition StructProto.hpp:39
static constexpr std::string_view GetSchema()
Definition StructProto.hpp:25
static constexpr size_t GetSize()
Definition StructProto.hpp:21
static constexpr ct_string kTypeName
Definition StructProto.hpp:17
static constexpr std::string_view GetTypeName()
Definition StructProto.hpp:20
static constexpr ct_string kSchema
Definition StructProto.hpp:22
static wpi::math::Matrixd< Rows, Cols, Options, MaxRows, MaxCols > Unpack(std::span< const uint8_t > data)
Definition StructProto.hpp:27
Struct serialization template.
Definition Struct.hpp:39
Fixed length string (array of character) for compile time use.
Definition ct_string.hpp:29