WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
wpi::util::ProtobufSerializable Concept Reference

Specifies that a type is capable of protobuf serialization and deserialization. More...

#include <wpi/util/protobuf/Protobuf.hpp>

Concept definition

template<typename T>
const T& value) {
{
} -> std::same_as<std::optional<typename std::remove_cvref_t<T>>>;
{
} -> std::same_as<bool>;
typename Protobuf<typename std::remove_cvref_t<T>>::MessageStruct;
{
Protobuf<typename std::remove_cvref_t<T>>::MessageStruct::msg_descriptor()
} -> std::same_as<const pb_msgdesc_t*>;
{
Protobuf<typename std::remove_cvref_t<T>>::MessageStruct::msg_name()
} -> std::same_as<std::string_view>;
{
Protobuf<typename std::remove_cvref_t<T>>::MessageStruct::file_descriptor()
} -> std::same_as<pb_filedesc_t>;
}
Class for wrapping a nanopb istream.
Definition Protobuf.hpp:55
Class for wrapping a nanopb ostream.
Definition Protobuf.hpp:119
Specifies that a type is capable of protobuf serialization and deserialization.
Definition Protobuf.hpp:251
Protobuf serialization template.
Definition Protobuf.hpp:36

Detailed Description

Specifies that a type is capable of protobuf serialization and deserialization.

This is designed for serializing complex flexible data structures using code generated from a .proto file. Serialization consists of writing values into a nanopb Stream and deserialization consists of reading values from nanopb Stream.

Implementations must define a template specialization for wpi::util::Protobuf with T being the type that is being serialized/deserialized, with the following static members (as enforced by this concept):

  • using MessageStruct = nanopb_message_struct_here: typedef to the wpilib modified nanopb message struct
  • std::optional<T> Unpack(wpi::util::ProtoInputStream<T>&): function for deserialization
  • bool Pack(wpi::util::ProtoOutputStream<T>&, T&& value): function for serialization

As a suggestion, 2 extra type usings can be added to simplify the stream definitions, however these are not required.