8static const char *
const TAG =
"api.proto";
11 const uint8_t *ptr = buffer;
19 if (!res.has_value()) {
20 ESP_LOGV(TAG,
"Invalid field start at offset %ld", (
long) (ptr - buffer));
24 uint32_t tag = res->as_uint32();
25 uint32_t field_type = tag & 0b111;
26 uint32_t field_id = tag >> 3;
32 if (!res.has_value()) {
33 ESP_LOGV(TAG,
"Invalid VarInt at offset %ld", (
long) (ptr - buffer));
37 ESP_LOGV(TAG,
"Cannot decode VarInt field %" PRIu32
" with value %" PRIu32
"!", field_id, res->as_uint32());
44 if (!res.has_value()) {
45 ESP_LOGV(TAG,
"Invalid Length Delimited at offset %ld", (
long) (ptr - buffer));
48 uint32_t field_length = res->as_uint32();
50 if (ptr + field_length >
end) {
51 ESP_LOGV(TAG,
"Out-of-bounds Length Delimited at offset %ld", (
long) (ptr - buffer));
55 ESP_LOGV(TAG,
"Cannot decode Length Delimited field %" PRIu32
"!", field_id);
62 ESP_LOGV(TAG,
"Out-of-bounds Fixed32-bit at offset %ld", (
long) (ptr - buffer));
67 ESP_LOGV(TAG,
"Cannot decode 32-bit field %" PRIu32
" with value %" PRIu32
"!", field_id,
val);
73 ESP_LOGV(TAG,
"Invalid field type %u at offset %ld", field_type, (
long) (ptr - buffer));
79#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)
void decode(const uint8_t *buffer, size_t length)
virtual bool decode_length(uint32_t field_id, ProtoLengthDelimited value)
virtual void dump_to(std::string &out) const =0
static optional< ProtoVarInt > parse(const uint8_t *buffer, uint32_t len, uint32_t *consumed)
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.