C/C++ API Reference
Loading...
Searching...
No Matches
pw::protobuf::Decoder Class Reference

Public Member Functions

constexpr Decoder (span< const std::byte > proto)
 
 Decoder (const Decoder &other)=delete
 
Decoderoperator= (const Decoder &other)=delete
 
Status Next ()
 
uint32_t FieldNumber () const
 
Result< FieldKeyGetFieldKey () const
 
Status ReadInt32 (int32_t *out)
 
Status ReadUint32 (uint32_t *out)
 
Status ReadInt64 (int64_t *out)
 
Status ReadUint64 (uint64_t *out)
 
Status ReadSint32 (int32_t *out)
 
Status ReadSint64 (int64_t *out)
 
Status ReadBool (bool *out)
 
Status ReadFixed32 (uint32_t *out)
 
Status ReadFixed64 (uint64_t *out)
 
Status ReadSfixed32 (int32_t *out)
 
Status ReadSfixed64 (int64_t *out)
 
Status ReadFloat (float *out)
 
Status ReadDouble (double *out)
 
Status ReadString (std::string_view *out)
 
Status ReadBytes (span< const std::byte > *out)
 
void Reset (span< const std::byte > proto)
 

Friends

class internal::RawFinder
 

Constructor & Destructor Documentation

◆ Decoder()

constexpr pw::protobuf::Decoder::Decoder ( span< const std::byte >  proto)
inlineconstexpr

Constructs a Decoder operating on an in-memory protobuf buffer.

Parameters
[in]protoSpan containing the raw serialized protobuf message.

Member Function Documentation

◆ FieldNumber()

uint32_t pw::protobuf::Decoder::FieldNumber ( ) const

Returns the field number of the field at the current cursor position.

A return value of 0 indicates that the field number is invalid. An invalid field number terminates the decode operation; any subsequent calls to Next() or Read*() will return \ref pw::Status::DataLoss() "DATA_LOSS".

◆ GetFieldKey()

Result< FieldKey > pw::protobuf::Decoder::GetFieldKey ( ) const

Gets the field key of the field at the current cursor position if valid.

Note
Avoid using this function unless you need to examine the field wire format properties. FieldNumber() is sufficient for manual decoding in most cases.
Returns
A Result containing the FieldKey of the current field on success or one of the following error codes on failure:

◆ Next()

Status pw::protobuf::Decoder::Next ( )

Advances to the next field in the proto.

If Next() returns \ref pw::OkStatus() "OK", there is guaranteed to be a valid protobuf field at the current cursor position.

Returns
  • OK: Advanced to a valid proto field.
  • OUT_OF_RANGE: Reached the end of the proto message.
  • DATA_LOSS: Invalid protobuf wire data.

◆ ReadBool()

Status pw::protobuf::Decoder::ReadBool ( bool *  out)

Reads a proto bool value from the current cursor position.

Parameters
[out]outPointer to store the read bool value.

◆ ReadBytes()

Status pw::protobuf::Decoder::ReadBytes ( span< const std::byte > *  out)
inline

Reads a proto bytes value from the current cursor position as a view.

Note
The raw protobuf data must outlive out. If the bytes field is invalid, out is not modified.
Parameters
[out]outPointer to store the byte span view (span<const std::byte>).

◆ ReadDouble()

Status pw::protobuf::Decoder::ReadDouble ( double *  out)
inline

Reads a proto double value from the current cursor position.

Parameters
[out]outPointer to store the read double value.

◆ ReadFixed32()

Status pw::protobuf::Decoder::ReadFixed32 ( uint32_t *  out)
inline

Reads a proto fixed32 value from the current cursor position.

Parameters
[out]outPointer to store the read fixed32 value.

◆ ReadFixed64()

Status pw::protobuf::Decoder::ReadFixed64 ( uint64_t *  out)
inline

Reads a proto fixed64 value from the current cursor position.

Parameters
[out]outPointer to store the read fixed64 value.

◆ ReadFloat()

Status pw::protobuf::Decoder::ReadFloat ( float *  out)
inline

Reads a proto float value from the current cursor position.

Parameters
[out]outPointer to store the read float value.

◆ ReadInt32()

Status pw::protobuf::Decoder::ReadInt32 ( int32_t *  out)
inline

Reads a proto int32 value from the current cursor position.

Parameters
[out]outPointer to store the read int32 value.

◆ ReadInt64()

Status pw::protobuf::Decoder::ReadInt64 ( int64_t *  out)
inline

Reads a proto int64 value from the current cursor position.

Parameters
[out]outPointer to store the read int64 value.

◆ ReadSfixed32()

Status pw::protobuf::Decoder::ReadSfixed32 ( int32_t *  out)
inline

Reads a proto sfixed32 value from the current cursor position.

Parameters
[out]outPointer to store the read sfixed32 value.

◆ ReadSfixed64()

Status pw::protobuf::Decoder::ReadSfixed64 ( int64_t *  out)
inline

Reads a proto sfixed64 value from the current cursor position.

Parameters
[out]outPointer to store the read sfixed64 value.

◆ ReadSint32()

Status pw::protobuf::Decoder::ReadSint32 ( int32_t *  out)

Reads a proto sint32 value from the current cursor position.

Parameters
[out]outPointer to store the read sint32 value.

◆ ReadSint64()

Status pw::protobuf::Decoder::ReadSint64 ( int64_t *  out)

Reads a proto sint64 value from the current cursor position.

Parameters
[out]outPointer to store the read sint64 value.

◆ ReadString()

Status pw::protobuf::Decoder::ReadString ( std::string_view *  out)

Reads a proto string value from the current cursor position as a view.

Note
The raw protobuf data must outlive out. If the string field is invalid, out is not modified.
Parameters
[out]outPointer to store the std::string_view of the string.

◆ ReadUint32()

Status pw::protobuf::Decoder::ReadUint32 ( uint32_t *  out)

Reads a proto uint32 value from the current cursor position.

Parameters
[out]outPointer to store the read uint32 value.

◆ ReadUint64()

Status pw::protobuf::Decoder::ReadUint64 ( uint64_t *  out)
inline

Reads a proto uint64 value from the current cursor position.

Parameters
[out]outPointer to store the read uint64 value.

◆ Reset()

void pw::protobuf::Decoder::Reset ( span< const std::byte >  proto)
inline

Resets the decoder to start reading a new proto message.

Parameters
[in]protoSpan containing the new raw serialized protobuf message.

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