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;
150 m_streamLocal.
errmsg =
nullptr;
164 m_streamLocal.
state = &out;
167 m_streamLocal.
errmsg =
nullptr;
187 return m_streamMsg ? m_streamMsg : &m_streamLocal;
212 const typename Protobuf<std::remove_cvref_t<T>>::MessageStruct& msg) {
217 return pb_encode(&m_streamLocal, m_msgDesc, &msg);
254 typename Protobuf<typename std::remove_cvref_t<T>>;
256 Protobuf<typename std::remove_cvref_t<T>>::Unpack(istream)
257 } -> std::same_as<std::optional<typename std::remove_cvref_t<T>>>;
259 Protobuf<typename std::remove_cvref_t<T>>::Pack(ostream, value)
260 } -> std::same_as<bool>;
261 typename Protobuf<typename std::remove_cvref_t<T>>::MessageStruct;
263 Protobuf<typename std::remove_cvref_t<T>>::MessageStruct::msg_descriptor()
264 } -> std::same_as<const pb_msgdesc_t*>;
266 Protobuf<typename std::remove_cvref_t<T>>::MessageStruct::msg_name()
267 } -> std::same_as<std::string_view>;
269 Protobuf<typename std::remove_cvref_t<T>>::MessageStruct::file_descriptor()
270 } -> std::same_as<pb_filedesc_t>;
286 Protobuf<typename std::remove_cvref_t<T>>::UnpackInto(out, istream)
287 } -> std::same_as<bool>;
296 std::span<const uint8_t> descriptor)>
306template <ProtobufSerializable T>
315 std::optional<std::remove_cvref_t<T>>
Unpack(std::span<const uint8_t> data) {
332 auto unpacked =
Unpack(data);
336 *out = std::move(unpacked.value());
360 bool Pack(std::vector<uint8_t>& out,
const T& value) {
372 Protobuf<std::remove_cvref_t<T>>::MessageStruct::msg_descriptor());
386 std::span<const uint8_t> descriptor)>
389 Protobuf<std::remove_cvref_t<T>>::MessageStruct::msg_descriptor(),
Class for wrapping a nanopb ostream.
Definition Protobuf.h:119
ProtoOutputStream(detail::StdVectorType &out)
Constructs a nanopb ostream from a buffer.
Definition Protobuf.h:160
const pb_msgdesc_t * MsgDesc() const noexcept
Gets the nanopb message descriptor.
Definition Protobuf.h:203
ProtoOutputStream()
Constructs a empty nanopb stream.
Definition Protobuf.h: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.h:196
pb_ostream_t * Stream() noexcept
Gets the backing nanopb stream object.
Definition Protobuf.h:186
ProtoOutputStream(pb_ostream_t *stream)
Constructs a nanopb ostream from an existing ostream object Generally used internally for encoding me...
Definition Protobuf.h:130
bool Encode(const typename Protobuf< std::remove_cvref_t< T > >::MessageStruct &msg)
Decodes a protobuf.
Definition Protobuf.h:211
ProtoOutputStream(detail::SmallVectorType &out)
Constructs a nanopb ostream from a buffer.
Definition Protobuf.h:143
Ease of use wrapper to make nanopb streams more opaque to the user.
Definition Protobuf.h:307
std::string GetTypeString() const
Gets the type string for the message.
Definition Protobuf.h:370
bool UnpackInto(T *out, std::span< const uint8_t > data)
Unpacks from a byte array into an existing object.
Definition Protobuf.h:327
std::optional< std::remove_cvref_t< T > > Unpack(std::span< const uint8_t > data)
Unpacks from a byte array.
Definition Protobuf.h:315
bool Pack(std::vector< uint8_t > &out, const T &value)
Packs object into a std::vector.
Definition Protobuf.h:360
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.h:383
bool Pack(wpi::SmallVectorImpl< uint8_t > &out, const T &value)
Packs object into a SmallVector.
Definition Protobuf.h:348
An efficient, type-erasing, non-owning reference to a callable.
Definition function_ref.h:31
Specifies that a type is capable of in-place protobuf deserialization.
Definition Protobuf.h:282
Specifies that a type is capable of protobuf serialization and deserialization.
Definition Protobuf.h:251
detail namespace with internal helper functions
Definition input_adapters.h:32
Implement std::hash so that hash_code can be used in STL containers.
Definition PointerIntPair.h:280
bool WriteFromStdVector(pb_ostream_t *stream, const pb_byte_t *buf, size_t count)
std::string GetTypeString(const pb_msgdesc_t *msg)
bool WriteSubmessage(pb_ostream_t *stream, const pb_msgdesc_t *desc, const void *msg)
bool WriteFromSmallVector(pb_ostream_t *stream, const pb_byte_t *buf, size_t count)
std::vector< uint8_t > StdVectorType
Definition Protobuf.h:40
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)
Foonathan namespace.
Definition ntcore_cpp.h:26
flags
Definition http_parser.h:206
uint_least8_t pb_byte_t
Definition pb.h:228
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)
Definition pb_decode.h:27
Definition pb_encode.h:26
size_t bytes_written
Definition pb_encode.h:49
bool(* callback)(pb_ostream_t *stream, const pb_byte_t *buf, size_t count)
Definition pb_encode.h:36
const char * errmsg
Definition pb_encode.h:53
void * state
Definition pb_encode.h:43
size_t max_size
Definition pb_encode.h:46
Protobuf serialization template.
Definition Protobuf.h:36
typename std::remove_cv< remove_reference_t< T > >::type remove_cvref_t
Definition base.h:306