27template <wpi::ProtobufSerializable T>
33template <wpi::ProtobufSerializable T>
54 m_msg{
std::move(msg)},
55 m_defaultValue{
std::move(defaultValue)} {}
62 m_msg{
std::move(rhs.m_msg)},
63 m_defaultValue{
std::move(rhs.m_defaultValue)} {}
67 m_msg = std::move(rhs.m_msg);
68 m_defaultValue = std::move(rhs.m_defaultValue);
104 if (view.
value.empty()) {
107 std::scoped_lock lock{m_mutex};
108 return m_msg.UnpackInto(out, view.
value);
132 if (!view.
value.empty()) {
133 std::scoped_lock lock{m_mutex};
134 if (
auto optval = m_msg.Unpack(view.
value)) {
138 return {0, 0, defaultValue};
154 std::vector<TimestampedValueType> rv;
155 rv.reserve(raw.size());
156 std::scoped_lock lock{m_mutex};
157 for (
auto&& r : raw) {
158 if (
auto optval = m_msg.Unpack(r.value)) {
159 rv.emplace_back(r.time, r.serverTime, *optval);
183template <wpi::ProtobufSerializable T>
209 m_msg{
std::move(rhs.m_msg)},
210 m_schemaPublished{rhs.m_schemaPublished} {}
214 m_msg = std::move(rhs.m_msg);
215 m_schemaPublished.store(
216 rhs.m_schemaPublished.load(std::memory_order_relaxed),
217 std::memory_order_relaxed);
227 void Set(
const T& value, int64_t time = 0) {
230 std::scoped_lock lock{m_mutex};
231 if (!m_schemaPublished.exchange(
true, std::memory_order_relaxed)) {
234 m_msg.Pack(buf, value);
249 std::scoped_lock lock{m_mutex};
250 if (!m_schemaPublished.exchange(
true, std::memory_order_relaxed)) {
253 m_msg.Pack(buf, value);
270 std::atomic_bool m_schemaPublished{
false};
278template <wpi::ProtobufSerializable T>
336template <wpi::ProtobufSerializable T>
385 std::move(defaultValue)};
430 const wpi::json& properties,
466 std::move(defaultValue)};
This file defines the SmallVector class.
NetworkTables protobuf-encoded value entry.
Definition: ProtobufTopic.h:280
NT_Entry GetHandle() const
Gets the native handle for the entry.
Definition: ProtobufTopic.h:316
void Unpublish()
Stops publishing the entry if it's published.
Definition: ProtobufTopic.h:330
TopicType GetTopic() const
Get the corresponding topic.
Definition: ProtobufTopic.h:323
ProtobufEntry(NT_Entry handle, wpi::ProtobufMessage< T > msg, T defaultValue)
Construct from an entry handle; recommended to use ProtobufTopic::GetEntry() instead.
Definition: ProtobufTopic.h:300
NetworkTables protobuf-encoded value publisher.
Definition: ProtobufTopic.h:184
T ValueType
Definition: ProtobufTopic.h:187
ProtobufPublisher(const ProtobufPublisher &)=delete
ProtobufPublisher()=default
void SetDefault(const T &value)
Publish a default value.
Definition: ProtobufTopic.h:246
ProtobufPublisher(NT_Publisher handle, wpi::ProtobufMessage< T > msg)
Construct from a publisher handle; recommended to use ProtobufTopic::Publish() instead.
Definition: ProtobufTopic.h:201
void Set(const T &value, int64_t time=0)
Publish a new value.
Definition: ProtobufTopic.h:227
TopicType GetTopic() const
Get the corresponding topic.
Definition: ProtobufTopic.h:263
ProtobufPublisher(ProtobufPublisher &&rhs)
Definition: ProtobufTopic.h:207
const T & ParamType
Definition: ProtobufTopic.h:188
ProtobufPublisher & operator=(ProtobufPublisher &&rhs)
Definition: ProtobufTopic.h:212
ProtobufPublisher & operator=(const ProtobufPublisher &)=delete
NetworkTables protobuf-encoded value subscriber.
Definition: ProtobufTopic.h:34
TimestampedValueType GetAtomic(const T &defaultValue) const
Get the last published value along with its timestamp.
Definition: ProtobufTopic.h:129
bool GetInto(T *out)
Get the last published value, replacing the contents in place of an existing object.
Definition: ProtobufTopic.h:101
ValueType Get(const T &defaultValue) const
Get the last published value.
Definition: ProtobufTopic.h:89
TimestampedValueType GetAtomic() const
Get the last published value along with its timestamp If no value has been published or the value can...
Definition: ProtobufTopic.h:119
std::vector< TimestampedValueType > ReadQueue()
Get an array of all valid value changes since the last call to ReadQueue.
Definition: ProtobufTopic.h:152
ProtobufSubscriber & operator=(const ProtobufSubscriber &)=delete
TopicType GetTopic() const
Get the corresponding topic.
Definition: ProtobufTopic.h:170
const T & ParamType
Definition: ProtobufTopic.h:38
ProtobufSubscriber & operator=(ProtobufSubscriber &&rhs)
Definition: ProtobufTopic.h:65
ProtobufSubscriber(const ProtobufSubscriber &)=delete
ProtobufSubscriber(ProtobufSubscriber &&rhs)
Definition: ProtobufTopic.h:60
ProtobufSubscriber(NT_Subscriber handle, wpi::ProtobufMessage< T > msg, T defaultValue)
Construct from a subscriber handle; recommended to use ProtobufTopic::Subscribe() instead.
Definition: ProtobufTopic.h:51
ProtobufSubscriber()=default
T ValueType
Definition: ProtobufTopic.h:37
ValueType Get() const
Get the last published value.
Definition: ProtobufTopic.h:79
NetworkTables protobuf-encoded value topic.
Definition: ProtobufTopic.h:337
EntryType GetEntry(T defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new entry for the topic.
Definition: ProtobufTopic.h:460
ProtobufTopic(Topic topic)
Construct from a generic topic.
Definition: ProtobufTopic.h:361
SubscriberType Subscribe(T defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new subscriber to the topic.
Definition: ProtobufTopic.h:379
PublisherType PublishEx(const wpi::json &properties, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic, with type string and initial properties.
Definition: ProtobufTopic.h:429
ProtobufTopic(NT_Topic handle)
Construct from a topic handle; recommended to use NetworkTableInstance::GetProtobufTopic() instead.
Definition: ProtobufTopic.h:354
T ValueType
Definition: ProtobufTopic.h:342
PublisherType Publish(const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic.
Definition: ProtobufTopic.h:404
const T & ParamType
Definition: ProtobufTopic.h:343
NetworkTables publisher.
Definition: Topic.h:364
Publisher & operator=(const Publisher &)=delete
NT_Publisher m_pubHandle
NetworkTables handle.
Definition: Topic.h:400
NetworkTables subscriber.
Definition: Topic.h:309
Subscriber & operator=(const Subscriber &)=delete
NT_Subscriber m_subHandle
Definition: Topic.h:360
NetworkTables Topic.
Definition: Topic.h:28
NT_Topic m_handle
Definition: Topic.h:305
NetworkTableInstance GetInstance() const
Gets the instance for the topic.
Owning wrapper (ala std::unique_ptr) for google::protobuf::Message* that does not require the protobu...
Definition: Protobuf.h:158
std::string GetTypeString() const
Gets the type string for the message.
Definition: Protobuf.h:238
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1202
bool SetDefaultRaw(NT_Handle pubentry, std::span< const uint8_t > defaultValue)
Publish a default value.
std::vector< TimestampedRaw > ReadQueueRaw(NT_Handle subentry)
Get an array of all value changes since the last call to ReadQueue.
bool SetRaw(NT_Handle pubentry, std::span< const uint8_t > value, int64_t time=0)
Publish a new value.
TimestampedRaw GetAtomicRaw(NT_Handle subentry, std::span< const uint8_t > defaultValue)
Get the last published value along with its timestamp.
NT_Handle NT_Topic
Definition: ntcore_c.h:40
NT_Handle NT_Subscriber
Definition: ntcore_c.h:41
NT_Handle NT_Publisher
Definition: ntcore_c.h:42
NT_Handle NT_Entry
Definition: ntcore_c.h:35
@ NT_RAW
Definition: ntcore_c.h:56
constexpr PubSubOptions kDefaultPubSubOptions
Default publish/subscribe options.
Definition: ntcore_cpp.h:390
NT_Entry GetEntry(NT_Inst inst, std::string_view name)
Get Entry Handle.
NT_Topic GetTopicFromHandle(NT_Handle pubsubentry)
Gets the topic handle from an entry/subscriber/publisher handle.
NT_Publisher PublishEx(NT_Topic topic, NT_Type type, std::string_view typeStr, const wpi::json &properties, const PubSubOptions &options=kDefaultPubSubOptions)
Creates a new publisher to a topic.
NT_Publisher Publish(NT_Topic topic, NT_Type type, std::string_view typeStr, const PubSubOptions &options=kDefaultPubSubOptions)
Creates a new publisher to a topic.
void Unpublish(NT_Handle pubentry)
Stops publisher.
NT_Subscriber Subscribe(NT_Topic topic, NT_Type type, std::string_view typeStr, const PubSubOptions &options=kDefaultPubSubOptions)
Creates a new subscriber to value changes on a topic.
NetworkTables (ntcore) namespace.
Definition: ntcore_cpp.h:36
NetworkTables publish/subscribe options.
Definition: ntcore_cpp.h:305
Timestamped value.
Definition: ntcore_cpp_types.h:30
int64_t time
Time in local time base.
Definition: ntcore_cpp_types.h:38
int64_t serverTime
Time in server time base.
Definition: ntcore_cpp_types.h:43
T value
Value.
Definition: ntcore_cpp_types.h:48
::std::mutex mutex
Definition: mutex.h:17