WPILibC++ 2024.1.1-beta-4
wpi::ProtobufSerializable Concept Reference

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

#include <wpi/protobuf/Protobuf.h>

Concept definition

template<typename T>
concept wpi::ProtobufSerializable = requires(
google::protobuf::Arena* arena, const google::protobuf::Message& inmsg,
google::protobuf::Message* outmsg, const T& value) {
typename Protobuf<typename std::remove_cvref_t<T>>;
{
Protobuf<typename std::remove_cvref_t<T>>::New(arena)
} -> std::same_as<google::protobuf::Message*>;
{
Protobuf<typename std::remove_cvref_t<T>>::Unpack(inmsg)
} -> std::same_as<typename std::remove_cvref_t<T>>;
Protobuf<typename std::remove_cvref_t<T>>::Pack(outmsg, value);
}
Specifies that a type is capable of protobuf serialization and deserialization.
Definition: Protobuf.h:65
static frc::DCMotor Unpack(std::span< const uint8_t > data)
static google::protobuf::Message * New(google::protobuf::Arena *arena)
static void Pack(std::span< uint8_t > data, const frc::DCMotor &value)

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 mutable protobuf Message and deserialization consists of reading values from an immutable protobuf Message.

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

  • google::protobuf::Message* New(google::protobuf::Arena*): create a protobuf message
  • T Unpack(const google::protobuf::Message&): function for deserialization
  • void Pack(google::protobuf::Message*, T&& value): function for serialization

To avoid pulling in the protobuf headers, these functions use google::protobuf::Message instead of a more specific type; implementations will need to static_cast to the correct type as created by New().

Additionally: In a static block, call StructRegistry.registerClass() to register the class