Skip to content

Commit 5e3f2d8

Browse files
committed
Fix json2protobuf with oneof fields.
The <field>_case member was not set, causing the protobuf structure to appear as having no value even though a value was given in the JSON.
1 parent c730faa commit 5e3f2d8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/protobuf2json.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,10 @@ static int json2protobuf_process_message(
743743
void *protobuf_value = ((char *)*protobuf_message) + field_descriptor->offset;
744744
void *protobuf_value_quantifier = ((char *)*protobuf_message) + field_descriptor->quantifier_offset;
745745

746+
if (field_descriptor->flags & PROTOBUF_C_FIELD_FLAG_ONEOF) {
747+
*(uint32_t*)protobuf_value_quantifier = field_descriptor->id;
748+
}
749+
746750
if (field_descriptor->label == PROTOBUF_C_LABEL_REQUIRED) {
747751
result = json2protobuf_process_field(field_descriptor, json_object_value, protobuf_value, error_string, error_size);
748752
if (result) {
@@ -751,7 +755,8 @@ static int json2protobuf_process_message(
751755
return result;
752756
}
753757
} else if (field_descriptor->label == PROTOBUF_C_LABEL_OPTIONAL) {
754-
if (field_descriptor->type == PROTOBUF_C_TYPE_MESSAGE || field_descriptor->type == PROTOBUF_C_TYPE_STRING) {
758+
if (field_descriptor->type == PROTOBUF_C_TYPE_MESSAGE || field_descriptor->type == PROTOBUF_C_TYPE_STRING
759+
|| (field_descriptor->flags & PROTOBUF_C_FIELD_FLAG_ONEOF)) {
755760
// Do nothing
756761
} else {
757762
*(protobuf_c_boolean *)protobuf_value_quantifier = 1;

0 commit comments

Comments
 (0)