Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
kcenon::monitoring::protobuf_wire::reader Class Reference

Minimal protobuf wire reader used for round-trip tests. More...

#include <protobuf_wire.h>

Collaboration diagram for kcenon::monitoring::protobuf_wire::reader:
Collaboration graph

Public Member Functions

 reader (const std::uint8_t *data, std::size_t size)
 
bool eof () const
 
std::size_t position () const
 
std::size_t size () const
 
std::optional< std::uint64_t > read_varint ()
 
std::optional< std::uint64_t > read_fixed64 ()
 
std::optional< std::uint32_t > read_fixed32 ()
 
bool read_length_delimited (const std::uint8_t **out_ptr, std::size_t *out_len)
 Read a length-delimited payload. Returns pointer into the underlying buffer and the length. The pointer is valid for the lifetime of the wrapped buffer.
 
bool read_string (std::string &out)
 
bool read_bytes (std::vector< std::uint8_t > &out)
 
bool skip_field (wire_type wt)
 Skip a field whose wire type is given.
 

Private Attributes

const std::uint8_t * data_
 
std::size_t size_
 
std::size_t pos_
 

Detailed Description

Minimal protobuf wire reader used for round-trip tests.

Definition at line 169 of file protobuf_wire.h.

Constructor & Destructor Documentation

◆ reader()

kcenon::monitoring::protobuf_wire::reader::reader ( const std::uint8_t * data,
std::size_t size )
inline

Member Function Documentation

◆ eof()

◆ position()

std::size_t kcenon::monitoring::protobuf_wire::reader::position ( ) const
inline

Definition at line 175 of file protobuf_wire.h.

175{ return pos_; }

References pos_.

◆ read_bytes()

bool kcenon::monitoring::protobuf_wire::reader::read_bytes ( std::vector< std::uint8_t > & out)
inline

Definition at line 241 of file protobuf_wire.h.

241 {
242 const std::uint8_t* ptr = nullptr;
243 std::size_t len = 0;
244 if (!read_length_delimited(&ptr, &len)) return false;
245 out.assign(ptr, ptr + len);
246 return true;
247 }
bool read_length_delimited(const std::uint8_t **out_ptr, std::size_t *out_len)
Read a length-delimited payload. Returns pointer into the underlying buffer and the length....

References read_length_delimited().

Referenced by kcenon::monitoring::zipkin_proto::decode_endpoint(), kcenon::monitoring::jaeger_proto::decode_key_value(), kcenon::monitoring::jaeger_proto::decode_span(), kcenon::monitoring::zipkin_proto::decode_span(), and kcenon::monitoring::jaeger_proto::decode_span_ref().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_fixed32()

std::optional< std::uint32_t > kcenon::monitoring::protobuf_wire::reader::read_fixed32 ( )
inline

Definition at line 206 of file protobuf_wire.h.

206 {
207 if (pos_ + 4 > size_) {
208 return std::nullopt;
209 }
210 std::uint32_t result = 0;
211 for (int i = 0; i < 4; ++i) {
212 result |= static_cast<std::uint32_t>(data_[pos_++]) << (i * 8);
213 }
214 return result;
215 }

References data_, pos_, and size_.

Referenced by skip_field().

Here is the caller graph for this function:

◆ read_fixed64()

std::optional< std::uint64_t > kcenon::monitoring::protobuf_wire::reader::read_fixed64 ( )
inline

Definition at line 195 of file protobuf_wire.h.

195 {
196 if (pos_ + 8 > size_) {
197 return std::nullopt;
198 }
199 std::uint64_t result = 0;
200 for (int i = 0; i < 8; ++i) {
201 result |= static_cast<std::uint64_t>(data_[pos_++]) << (i * 8);
202 }
203 return result;
204 }

References data_, pos_, and size_.

Referenced by kcenon::monitoring::zipkin_proto::decode_annotation(), kcenon::monitoring::jaeger_proto::decode_key_value(), kcenon::monitoring::zipkin_proto::decode_span(), and skip_field().

Here is the caller graph for this function:

◆ read_length_delimited()

bool kcenon::monitoring::protobuf_wire::reader::read_length_delimited ( const std::uint8_t ** out_ptr,
std::size_t * out_len )
inline

Read a length-delimited payload. Returns pointer into the underlying buffer and the length. The pointer is valid for the lifetime of the wrapped buffer.

Definition at line 222 of file protobuf_wire.h.

223 {
224 auto len = read_varint();
225 if (!len) return false;
226 if (pos_ + *len > size_) return false;
227 *out_ptr = data_ + pos_;
228 *out_len = static_cast<std::size_t>(*len);
229 pos_ += *len;
230 return true;
231 }
std::optional< std::uint64_t > read_varint()

References data_, pos_, read_varint(), and size_.

Referenced by kcenon::monitoring::jaeger_proto::decode_batch(), kcenon::monitoring::zipkin_proto::decode_list_of_spans(), kcenon::monitoring::zipkin_proto::decode_map_entry(), kcenon::monitoring::jaeger_proto::decode_process(), kcenon::monitoring::jaeger_proto::decode_span(), kcenon::monitoring::zipkin_proto::decode_span(), read_bytes(), read_string(), and skip_field().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_string()

bool kcenon::monitoring::protobuf_wire::reader::read_string ( std::string & out)
inline

Definition at line 233 of file protobuf_wire.h.

233 {
234 const std::uint8_t* ptr = nullptr;
235 std::size_t len = 0;
236 if (!read_length_delimited(&ptr, &len)) return false;
237 out.assign(reinterpret_cast<const char*>(ptr), len);
238 return true;
239 }

References read_length_delimited().

Referenced by kcenon::monitoring::zipkin_proto::decode_annotation(), kcenon::monitoring::zipkin_proto::decode_endpoint(), kcenon::monitoring::jaeger_proto::decode_key_value(), kcenon::monitoring::zipkin_proto::decode_map_entry(), kcenon::monitoring::jaeger_proto::decode_process(), kcenon::monitoring::jaeger_proto::decode_span(), and kcenon::monitoring::zipkin_proto::decode_span().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_varint()

std::optional< std::uint64_t > kcenon::monitoring::protobuf_wire::reader::read_varint ( )
inline

Definition at line 178 of file protobuf_wire.h.

178 {
179 std::uint64_t result = 0;
180 int shift = 0;
181 while (pos_ < size_) {
182 std::uint8_t byte = data_[pos_++];
183 result |= static_cast<std::uint64_t>(byte & 0x7F) << shift;
184 if ((byte & 0x80) == 0) {
185 return result;
186 }
187 shift += 7;
188 if (shift > 63) {
189 return std::nullopt;
190 }
191 }
192 return std::nullopt;
193 }

References data_, pos_, and size_.

Referenced by kcenon::monitoring::zipkin_proto::decode_endpoint(), kcenon::monitoring::jaeger_proto::decode_key_value(), kcenon::monitoring::jaeger_proto::decode_span(), kcenon::monitoring::zipkin_proto::decode_span(), kcenon::monitoring::jaeger_proto::decode_span_ref(), kcenon::monitoring::protobuf_wire::decode_tag(), kcenon::monitoring::jaeger_proto::decode_timestamp(), read_length_delimited(), skip_field(), and TEST().

Here is the caller graph for this function:

◆ size()

std::size_t kcenon::monitoring::protobuf_wire::reader::size ( ) const
inline

Definition at line 176 of file protobuf_wire.h.

176{ return size_; }

References size_.

◆ skip_field()

bool kcenon::monitoring::protobuf_wire::reader::skip_field ( wire_type wt)
inline

Skip a field whose wire type is given.

Definition at line 250 of file protobuf_wire.h.

250 {
251 switch (wt) {
253 return read_varint().has_value();
255 return read_fixed64().has_value();
257 const std::uint8_t* ptr;
258 std::size_t len;
259 return read_length_delimited(&ptr, &len);
260 }
262 return read_fixed32().has_value();
263 }
264 return false;
265 }
std::optional< std::uint64_t > read_fixed64()
std::optional< std::uint32_t > read_fixed32()
@ varint
int32/int64/uint32/uint64/sint*‍/bool/enum
@ length_delimited
string/bytes/embedded messages/packed repeated

References kcenon::monitoring::protobuf_wire::fixed32, kcenon::monitoring::protobuf_wire::fixed64, kcenon::monitoring::protobuf_wire::length_delimited, read_fixed32(), read_fixed64(), read_length_delimited(), read_varint(), and kcenon::monitoring::protobuf_wire::varint.

Referenced by kcenon::monitoring::zipkin_proto::decode_annotation(), kcenon::monitoring::jaeger_proto::decode_batch(), kcenon::monitoring::zipkin_proto::decode_endpoint(), kcenon::monitoring::jaeger_proto::decode_key_value(), kcenon::monitoring::zipkin_proto::decode_list_of_spans(), kcenon::monitoring::zipkin_proto::decode_map_entry(), kcenon::monitoring::jaeger_proto::decode_process(), kcenon::monitoring::jaeger_proto::decode_span(), kcenon::monitoring::zipkin_proto::decode_span(), kcenon::monitoring::jaeger_proto::decode_span_ref(), and kcenon::monitoring::jaeger_proto::decode_timestamp().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ data_

const std::uint8_t* kcenon::monitoring::protobuf_wire::reader::data_
private

Definition at line 268 of file protobuf_wire.h.

Referenced by read_fixed32(), read_fixed64(), read_length_delimited(), and read_varint().

◆ pos_

std::size_t kcenon::monitoring::protobuf_wire::reader::pos_
private

◆ size_

std::size_t kcenon::monitoring::protobuf_wire::reader::size_
private

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