8static const char *
const TAG =
"api.proto";
12 const uint8_t *ptr = buffer;
20 if (!res.has_value()) {
24 uint32_t tag = res->as_uint32();
26 uint32_t field_id = tag >> 3;
30 if (field_id == target_field_id) {
38 if (!res.has_value()) {
46 if (!res.has_value()) {
49 uint32_t field_length = res->as_uint32();
51 if (ptr + field_length >
end) {
74 const uint8_t *ptr = buffer;
82 if (!res.has_value()) {
83 ESP_LOGV(TAG,
"Invalid field start at offset %ld", (
long) (ptr - buffer));
87 uint32_t tag = res->as_uint32();
89 uint32_t field_id = tag >> 3;
95 if (!res.has_value()) {
96 ESP_LOGV(TAG,
"Invalid VarInt at offset %ld", (
long) (ptr - buffer));
100 ESP_LOGV(TAG,
"Cannot decode VarInt field %" PRIu32
" with value %" PRIu32
"!", field_id, res->as_uint32());
107 if (!res.has_value()) {
108 ESP_LOGV(TAG,
"Invalid Length Delimited at offset %ld", (
long) (ptr - buffer));
111 uint32_t field_length = res->as_uint32();
113 if (ptr + field_length >
end) {
114 ESP_LOGV(TAG,
"Out-of-bounds Length Delimited at offset %ld", (
long) (ptr - buffer));
118 ESP_LOGV(TAG,
"Cannot decode Length Delimited field %" PRIu32
"!", field_id);
125 ESP_LOGV(TAG,
"Out-of-bounds Fixed32-bit at offset %ld", (
long) (ptr - buffer));
130 ESP_LOGV(TAG,
"Cannot decode 32-bit field %" PRIu32
" with value %" PRIu32
"!", field_id,
val);
136 ESP_LOGV(TAG,
"Invalid field type %u at offset %ld", field_type, (
long) (ptr - buffer));
142#ifdef HAS_PROTO_MESSAGE_DUMP
virtual bool decode_32bit(uint32_t field_id, Proto32Bit value)
virtual bool decode_varint(uint32_t field_id, ProtoVarInt value)
virtual void decode(const uint8_t *buffer, size_t length)
virtual bool decode_length(uint32_t field_id, ProtoLengthDelimited value)
static uint32_t count_repeated_field(const uint8_t *buffer, size_t length, uint32_t target_field_id)
Count occurrences of a repeated field in a protobuf buffer.
virtual void dump_to(std::string &out) const =0
static optional< ProtoVarInt > parse(const uint8_t *buffer, uint32_t len, uint32_t *consumed)
constexpr uint8_t WIRE_TYPE_VARINT
constexpr uint8_t WIRE_TYPE_MASK
constexpr uint8_t WIRE_TYPE_LENGTH_DELIMITED
constexpr uint8_t WIRE_TYPE_FIXED32
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
Encode a 32-bit value given four bytes in most to least significant byte order.