WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
wpi::nt::ProtobufSubscriber< T > Class Template Reference

NetworkTables protobuf-encoded value subscriber. More...

#include <wpi/nt/ProtobufTopic.hpp>

Inheritance diagram for wpi::nt::ProtobufSubscriber< T >:
wpi::nt::Subscriber wpi::nt::ProtobufEntry< T >

Public Types

using TopicType = ProtobufTopic<T>
using ValueType = T
using ParamType = const T&
using TimestampedValueType = Timestamped<T>

Public Member Functions

 ProtobufSubscriber ()=default
 ProtobufSubscriber (NT_Subscriber handle, wpi::util::ProtobufMessage< T > msg, T defaultValue)
 Construct from a subscriber handle; recommended to use ProtobufTopic::Subscribe() instead.
 ProtobufSubscriber (const ProtobufSubscriber &)=delete
ProtobufSubscriberoperator= (const ProtobufSubscriber &)=delete
 ProtobufSubscriber (ProtobufSubscriber &&rhs)
ProtobufSubscriberoperator= (ProtobufSubscriber &&rhs)
ValueType Get () const
 Get the last published value.
ValueType Get (const T &defaultValue) const
 Get the last published value.
bool GetInto (T *out)
 Get the last published value, replacing the contents in place of an existing object.
TimestampedValueType GetAtomic () const
 Get the last published value along with its timestamp If no value has been published or the value cannot be unpacked, returns the stored default value and a timestamp of 0.
TimestampedValueType GetAtomic (const T &defaultValue) const
 Get the last published value along with its timestamp.
std::vector< TimestampedValueTypeReadQueue ()
 Get an array of all valid value changes since the last call to ReadQueue.
TopicType GetTopic () const
 Get the corresponding topic.
Public Member Functions inherited from wpi::nt::Subscriber
virtual ~Subscriber ()
 Subscriber (const Subscriber &)=delete
Subscriberoperator= (const Subscriber &)=delete
 Subscriber (Subscriber &&rhs)
Subscriberoperator= (Subscriber &&rhs)
 operator bool () const
 Determines if the native handle is valid.
NT_Subscriber GetHandle () const
 Gets the native handle for the subscriber.
bool Exists () const
 Determines if the topic is currently being published.
int64_t GetLastChange () const
 Gets the last time the value was changed.
Topic GetTopic () const
 Gets the subscribed-to topic.

Additional Inherited Members

Protected Member Functions inherited from wpi::nt::Subscriber
 Subscriber ()=default
 Subscriber (NT_Subscriber handle)
Protected Attributes inherited from wpi::nt::Subscriber
NT_Subscriber m_subHandle {0}

Detailed Description

template<wpi::util::ProtobufSerializable T>
class wpi::nt::ProtobufSubscriber< T >

NetworkTables protobuf-encoded value subscriber.

Member Typedef Documentation

◆ ParamType

using wpi::nt::ProtobufSubscriber< T >::ParamType = const T&

◆ TimestampedValueType

using wpi::nt::ProtobufSubscriber< T >::TimestampedValueType = Timestamped<T>

◆ TopicType

◆ ValueType

using wpi::nt::ProtobufSubscriber< T >::ValueType = T

Constructor & Destructor Documentation

◆ ProtobufSubscriber() [1/4]

wpi::nt::ProtobufSubscriber< T >::ProtobufSubscriber ( )
default

◆ ProtobufSubscriber() [2/4]

wpi::nt::ProtobufSubscriber< T >::ProtobufSubscriber ( NT_Subscriber handle,
wpi::util::ProtobufMessage< T > msg,
T defaultValue )
inline

Construct from a subscriber handle; recommended to use ProtobufTopic::Subscribe() instead.

Parameters
handleNative handle
msgProtobuf message
defaultValueDefault value

◆ ProtobufSubscriber() [3/4]

wpi::nt::ProtobufSubscriber< T >::ProtobufSubscriber ( const ProtobufSubscriber< T > & )
delete

◆ ProtobufSubscriber() [4/4]

wpi::nt::ProtobufSubscriber< T >::ProtobufSubscriber ( ProtobufSubscriber< T > && rhs)
inline

Member Function Documentation

◆ Get() [1/2]

Get the last published value.

If no value has been published or the value cannot be unpacked, returns the stored default value.

Returns
value

◆ Get() [2/2]

ValueType wpi::nt::ProtobufSubscriber< T >::Get ( const T & defaultValue) const
inline

Get the last published value.

If no value has been published or the value cannot be unpacked, returns the passed defaultValue.

Parameters
defaultValuedefault value to return if no value has been published
Returns
value

◆ GetAtomic() [1/2]

Get the last published value along with its timestamp If no value has been published or the value cannot be unpacked, returns the stored default value and a timestamp of 0.

Returns
timestamped value

◆ GetAtomic() [2/2]

TimestampedValueType wpi::nt::ProtobufSubscriber< T >::GetAtomic ( const T & defaultValue) const
inline

Get the last published value along with its timestamp.

If no value has been published or the value cannot be unpacked, returns the passed defaultValue and a timestamp of 0.

Parameters
defaultValuedefault value to return if no value has been published
Returns
timestamped value

◆ GetInto()

bool wpi::nt::ProtobufSubscriber< T >::GetInto ( T * out)
inline

Get the last published value, replacing the contents in place of an existing object.

If no value has been published or the value cannot be unpacked, does not replace the contents and returns false.

Parameters
[out]outobject to replace contents of
Returns
true if successful

◆ GetTopic()

TopicType wpi::nt::ProtobufSubscriber< T >::GetTopic ( ) const
inline

Get the corresponding topic.

Returns
Topic

◆ operator=() [1/2]

◆ operator=() [2/2]

◆ ReadQueue()

std::vector< TimestampedValueType > wpi::nt::ProtobufSubscriber< T >::ReadQueue ( )
inline

Get an array of all valid value changes since the last call to ReadQueue.

Also provides a timestamp for each value. Values that cannot be unpacked are dropped.

Note
The "poll storage" subscribe option can be used to set the queue depth.
Returns
Array of timestamped values; empty array if no valid new changes have been published since the previous call.

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