WPILibC++ 2024.3.2
wpi::ProtobufMessage< T > Class Template Reference

Owning wrapper (ala std::unique_ptr) for google::protobuf::Message* that does not require the protobuf headers be included. More...

#include <wpi/protobuf/Protobuf.h>

Public Member Functions

 ProtobufMessage (google::protobuf::Arena *arena=nullptr)
 
 ~ProtobufMessage ()
 
 ProtobufMessage (const ProtobufMessage &)=delete
 
ProtobufMessageoperator= (const ProtobufMessage &)=delete
 
 ProtobufMessage (ProtobufMessage &&rhs)
 
ProtobufMessageoperator= (ProtobufMessage &&rhs)
 
google::protobuf::Message * GetMessage ()
 Gets the stored message object. More...
 
const google::protobuf::Message * GetMessage () const
 
std::optional< T > Unpack (std::span< const uint8_t > data)
 Unpacks from a byte array. More...
 
bool UnpackInto (T *out, std::span< const uint8_t > data)
 Unpacks from a byte array into an existing object. More...
 
bool Pack (wpi::SmallVectorImpl< uint8_t > &out, const T &value)
 Packs object into a SmallVector. More...
 
bool Pack (std::vector< uint8_t > &out, const T &value)
 Packs object into a std::vector. More...
 
std::string GetTypeString () const
 Gets the type string for the message. More...
 
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. More...
 

Detailed Description

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

Owning wrapper (ala std::unique_ptr) for google::protobuf::Message* that does not require the protobuf headers be included.

Note this object is not thread safe; users of this object are required to provide any necessary thread safety.

Template Parameters
Tserialized object type

Constructor & Destructor Documentation

◆ ProtobufMessage() [1/3]

template<ProtobufSerializable T>
wpi::ProtobufMessage< T >::ProtobufMessage ( google::protobuf::Arena *  arena = nullptr)
inlineexplicit

◆ ~ProtobufMessage()

template<ProtobufSerializable T>
wpi::ProtobufMessage< T >::~ProtobufMessage ( )
inline

◆ ProtobufMessage() [2/3]

template<ProtobufSerializable T>
wpi::ProtobufMessage< T >::ProtobufMessage ( const ProtobufMessage< T > &  )
delete

◆ ProtobufMessage() [3/3]

template<ProtobufSerializable T>
wpi::ProtobufMessage< T >::ProtobufMessage ( ProtobufMessage< T > &&  rhs)
inline

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

◆ GetMessage() [1/2]

template<ProtobufSerializable T>
google::protobuf::Message * wpi::ProtobufMessage< T >::GetMessage ( )
inline

Gets the stored message object.

Returns
google::protobuf::Message*

◆ GetMessage() [2/2]

template<ProtobufSerializable T>
const google::protobuf::Message * wpi::ProtobufMessage< T >::GetMessage ( ) const
inline

◆ GetTypeString()

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

Gets the type string for the message.

Returns
type string

◆ operator=() [1/2]

template<ProtobufSerializable T>
ProtobufMessage & wpi::ProtobufMessage< T >::operator= ( const ProtobufMessage< T > &  )
delete

◆ operator=() [2/2]

template<ProtobufSerializable T>
ProtobufMessage & wpi::ProtobufMessage< T >::operator= ( ProtobufMessage< T > &&  rhs)
inline

◆ 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< 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: