WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
wpi::ProtobufMessage< T > Class Template Reference

Ease of use wrapper to make nanopb streams more opaque to the user. More...

#include <wpi/protobuf/Protobuf.h>

Public Member Functions

std::optional< std::remove_cvref_t< T > > Unpack (std::span< const uint8_t > data)
 Unpacks from a byte array.
 
bool UnpackInto (T *out, std::span< const uint8_t > data)
 Unpacks from a byte array into an existing object.
 
bool Pack (wpi::SmallVectorImpl< uint8_t > &out, const T &value)
 Packs object into a SmallVector.
 
bool Pack (std::vector< uint8_t > &out, const T &value)
 Packs object into a std::vector.
 
std::string GetTypeString () const
 Gets the type string for the message.
 
void ForEachProtobufDescriptor (function_ref< bool(std::string_view filename)> exists, function_ref< void(std::string_view filename, std::span< const uint8_t > descriptor)> fn)
 Loops over all protobuf descriptors including nested/referenced descriptors.
 

Detailed Description

template<ProtobufSerializable T>
class wpi::ProtobufMessage< T >

Ease of use wrapper to make nanopb streams more opaque to the user.

This class is stateless and thread safe.

Template Parameters
Tserialized object type

Member Function Documentation

◆ ForEachProtobufDescriptor()

template<ProtobufSerializable T>
void wpi::ProtobufMessage< T >::ForEachProtobufDescriptor ( function_ref< bool(std::string_view filename)> exists,
function_ref< void(std::string_view filename, std::span< const uint8_t > descriptor)> fn )
inline

Loops over all protobuf descriptors including nested/referenced descriptors.

Parameters
existsfunction that returns false if fn should be called for the given type string
fnfunction to call for each descriptor

◆ GetTypeString()

template<ProtobufSerializable T>
std::string wpi::ProtobufMessage< T >::GetTypeString ( ) const
inline

Gets the type string for the message.

Returns
type string

◆ Pack() [1/2]

template<ProtobufSerializable T>
bool wpi::ProtobufMessage< T >::Pack ( std::vector< uint8_t > & out,
const T & value )
inline

Packs object into a std::vector.

Parameters
[out]outoutput bytes
[in]valuevalue
Returns
true if successful

◆ Pack() [2/2]

template<ProtobufSerializable T>
bool wpi::ProtobufMessage< T >::Pack ( wpi::SmallVectorImpl< uint8_t > & out,
const T & value )
inline

Packs object into a SmallVector.

Parameters
[out]outoutput bytes
[in]valuevalue
Returns
true if successful

◆ Unpack()

template<ProtobufSerializable T>
std::optional< std::remove_cvref_t< T > > wpi::ProtobufMessage< T >::Unpack ( std::span< const uint8_t > data)
inline

Unpacks from a byte array.

Parameters
databyte array
Returns
Optional; empty if parsing failed

◆ UnpackInto()

template<ProtobufSerializable T>
bool wpi::ProtobufMessage< T >::UnpackInto ( T * out,
std::span< const uint8_t > data )
inline

Unpacks from a byte array into an existing object.

Parameters
[out]outoutput object
[in]databyte array
Returns
true if successful

The documentation for this class was generated from the following file: