64 : m_streamMsg{stream},
76 reinterpret_cast<const
pb_byte_t*>(stream.data()), stream.size())},
87 return m_streamMsg ? m_streamMsg : &m_streamLocal;
105 unsigned int flags = 0) {
131 : m_streamMsg{stream},
147 m_streamLocal.state = &out;
148 m_streamLocal.max_size = SIZE_MAX;
149 m_streamLocal.bytes_written = 0;
150 m_streamLocal.errmsg =
nullptr;
164 m_streamLocal.state = &out;
165 m_streamLocal.max_size = SIZE_MAX;
166 m_streamLocal.bytes_written = 0;
167 m_streamLocal.errmsg =
nullptr;
188 return m_streamMsg ? m_streamMsg : &m_streamLocal;
213 const typename Protobuf<std::remove_cvref_t<T>>::MessageStruct& msg) {
218 return pb_encode(&m_streamLocal, m_msgDesc, &msg);
259 } -> std::same_as<std::optional<typename std::remove_cvref_t<T>>>;
262 } -> std::same_as<bool>;
266 } -> std::same_as<const pb_msgdesc_t*>;
269 } -> std::same_as<std::string_view>;
272 } -> std::same_as<pb_filedesc_t>;
289 } -> std::same_as<bool>;
298 std::span<const uint8_t> descriptor)>
308template <ProtobufSerializable T>
317 std::optional<std::remove_cvref_t<T>>
Unpack(std::span<const uint8_t> data) {
334 auto unpacked =
Unpack(data);
338 *out = std::move(unpacked.value());
362 bool Pack(std::vector<uint8_t>& out,
const T& value) {
374 Protobuf<std::remove_cvref_t<T>>::MessageStruct::msg_descriptor());
388 std::span<const uint8_t> descriptor)>
391 Protobuf<std::remove_cvref_t<T>>::MessageStruct::msg_descriptor(),
typename std::remove_cv< remove_reference_t< T > >::type remove_cvref_t
Definition base.h:316
Class for wrapping a nanopb ostream.
Definition Protobuf.hpp:119
ProtoOutputStream(pb_ostream_t *stream)
Constructs a nanopb ostream from an existing ostream object Generally used internally for encoding me...
Definition Protobuf.hpp:130
pb_ostream_t * Stream() noexcept
Gets the backing nanopb stream object.
Definition Protobuf.hpp:187
ProtoOutputStream(detail::StdVectorType &out)
Constructs a nanopb ostream from a buffer.
Definition Protobuf.hpp:160
const pb_msgdesc_t * MsgDesc() const noexcept
Gets the nanopb message descriptor.
Definition Protobuf.hpp:204
ProtoOutputStream()
Constructs a empty nanopb stream.
Definition Protobuf.hpp:177
bool IsSubmessage() const noexcept
Gets if this stream points to a submessage, and will call pb_encode_submessage instead of pb_encode.
Definition Protobuf.hpp:197
ProtoOutputStream(detail::SmallVectorType &out)
Constructs a nanopb ostream from a buffer.
Definition Protobuf.hpp:143
bool Encode(const typename Protobuf< std::remove_cvref_t< T > >::MessageStruct &msg)
Decodes a protobuf.
Definition Protobuf.hpp:212
Ease of use wrapper to make nanopb streams more opaque to the user.
Definition Protobuf.hpp:309
bool UnpackInto(T *out, std::span< const uint8_t > data)
Unpacks from a byte array into an existing object.
Definition Protobuf.hpp:329
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.
Definition Protobuf.hpp:385
bool Pack(std::vector< uint8_t > &out, const T &value)
Packs object into a std::vector.
Definition Protobuf.hpp:362
std::optional< std::remove_cvref_t< T > > Unpack(std::span< const uint8_t > data)
Unpacks from a byte array.
Definition Protobuf.hpp:317
std::string GetTypeString() const
Gets the type string for the message.
Definition Protobuf.hpp:372
bool Pack(wpi::util::SmallVectorImpl< uint8_t > &out, const T &value)
Packs object into a SmallVector.
Definition Protobuf.hpp:350
Definition BooleanTopic.hpp:22
An efficient, type-erasing, non-owning reference to a callable.
Definition function_ref.hpp:31
Specifies that a type is capable of in-place protobuf deserialization.
Definition Protobuf.hpp:284
Specifies that a type is capable of protobuf serialization and deserialization.
Definition Protobuf.hpp:252
Converts a string literal into a format string that will be parsed at compile time and converted into...
Definition printf.h:50
Definition StringMap.hpp:773
std::vector< uint8_t > StdVectorType
Definition Protobuf.hpp:40
std::string GetTypeString(const pb_msgdesc_t *msg)
bool WriteFromSmallVector(pb_ostream_t *stream, const pb_byte_t *buf, size_t count)
void ForEachProtobufDescriptor(const pb_msgdesc_t *msg, function_ref< bool(std::string_view filename)> wants, function_ref< void(std::string_view filename, std::span< const uint8_t > descriptor)> fn)
bool WriteFromStdVector(pb_ostream_t *stream, const pb_byte_t *buf, size_t count)
wpi::util::SmallVectorImpl< uint8_t > SmallVectorType
Definition Protobuf.hpp:39
bool WriteSubmessage(pb_ostream_t *stream, const pb_msgdesc_t *desc, const void *msg)
Definition raw_os_ostream.hpp:19
struct pb_ostream_s pb_ostream_t
Definition pb.h:318
uint_least8_t pb_byte_t
Definition pb.h:228
struct pb_msgdesc_s pb_msgdesc_t
Definition pb.h:330
struct pb_istream_s pb_istream_t
Definition pb.h:317
pb_istream_t pb_istream_from_buffer(const pb_byte_t *buf, size_t msglen)
bool pb_decode_ex(pb_istream_t *stream, const pb_msgdesc_t *fields, void *dest_struct, unsigned int flags)
bool pb_encode(pb_ostream_t *stream, const pb_msgdesc_t *fields, const void *src_struct)
Protobuf serialization template.
Definition Protobuf.hpp:36