This commit is contained in:
J. Nick Koston 2025-07-11 06:07:22 -10:00
parent c2657c1896
commit eb7f982b5b
No known key found for this signature in database

View File

@ -351,16 +351,15 @@ void ProtoMessage::decode(const uint8_t *buffer, size_t length) {
// Try regular fields first using binary search // Try regular fields first using binary search
if (const FieldMeta *field = find_field_binary(fields, field_count, field_id)) { if (const FieldMeta *field = find_field_binary(fields, field_count, field_id)) {
void *field_addr = base + field->get_offset(); decoded = decode_varint_field(field->get_type(), base + field->get_offset(), value);
decoded = decode_varint_field(field->get_type(), field_addr, value);
} }
// If not found, try repeated fields (linear search - usually only 1-2 fields) // If not found, try repeated fields (linear search - usually only 1-2 fields)
if (!decoded) { if (!decoded) {
for (uint8_t j = 0; j < repeated_count; j++) { for (uint8_t j = 0; j < repeated_count; j++) {
if (repeated_fields[j].field_num == field_id) { if (repeated_fields[j].field_num == field_id) {
void *field_addr = base + repeated_fields[j].get_offset(); decoded = decode_repeated_varint_field(repeated_fields[j].get_type(),
decoded = decode_repeated_varint_field(repeated_fields[j].get_type(), field_addr, value); base + repeated_fields[j].get_offset(), value);
break; break;
} }
} }
@ -388,17 +387,17 @@ void ProtoMessage::decode(const uint8_t *buffer, size_t length) {
// Try regular fields first using binary search // Try regular fields first using binary search
if (const FieldMeta *field = find_field_binary(fields, field_count, field_id)) { if (const FieldMeta *field = find_field_binary(fields, field_count, field_id)) {
void *field_addr = base + field->get_offset(); decoded =
decoded = decode_length_field(field->get_type(), field_addr, value, field->get_message_type_id()); decode_length_field(field->get_type(), base + field->get_offset(), value, field->get_message_type_id());
} }
// If not found, try repeated fields (linear search - usually only 1-2 fields) // If not found, try repeated fields (linear search - usually only 1-2 fields)
if (!decoded) { if (!decoded) {
for (uint8_t j = 0; j < repeated_count; j++) { for (uint8_t j = 0; j < repeated_count; j++) {
if (repeated_fields[j].field_num == field_id) { if (repeated_fields[j].field_num == field_id) {
void *field_addr = base + repeated_fields[j].get_offset(); decoded =
decoded = decode_repeated_length_field(repeated_fields[j].get_type(), field_addr, value, decode_repeated_length_field(repeated_fields[j].get_type(), base + repeated_fields[j].get_offset(),
repeated_fields[j].get_message_type_id()); value, repeated_fields[j].get_message_type_id());
break; break;
} }
} }
@ -423,16 +422,15 @@ void ProtoMessage::decode(const uint8_t *buffer, size_t length) {
// Try regular fields first using binary search // Try regular fields first using binary search
if (const FieldMeta *field = find_field_binary(fields, field_count, field_id)) { if (const FieldMeta *field = find_field_binary(fields, field_count, field_id)) {
void *field_addr = base + field->get_offset(); decoded = decode_32bit_field(field->get_type(), base + field->get_offset(), value);
decoded = decode_32bit_field(field->get_type(), field_addr, value);
} }
// If not found, try repeated fields (linear search - usually only 1-2 fields) // If not found, try repeated fields (linear search - usually only 1-2 fields)
if (!decoded) { if (!decoded) {
for (uint8_t j = 0; j < repeated_count; j++) { for (uint8_t j = 0; j < repeated_count; j++) {
if (repeated_fields[j].field_num == field_id) { if (repeated_fields[j].field_num == field_id) {
void *field_addr = base + repeated_fields[j].get_offset(); decoded = decode_repeated_32bit_field(repeated_fields[j].get_type(),
decoded = decode_repeated_32bit_field(repeated_fields[j].get_type(), field_addr, value); base + repeated_fields[j].get_offset(), value);
break; break;
} }
} }