Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions protobuf-c-text/generate.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ protobuf_c_text_to_string_internal(ReturnString *rs,
return;
}

if (0 != (f[i].flags & PROTOBUF_C_FIELD_FLAG_ONEOF) &&
f[i].id != STRUCT_MEMBER(uint32_t, m, f[i].quantifier_offset))
{
/* This is not the selected oneof, skip it */
continue;
}


/* Decide if something needs to be done for this field. */
switch (f[i].label) {
case PROTOBUF_C_LABEL_OPTIONAL:
Expand Down
10 changes: 10 additions & 0 deletions protobuf-c-text/parse.re
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,10 @@ state_assignment(State *state, Token *t)
} else {
STRUCT_MEMBER(ProtobufCMessage *, msg, state->field->offset)
= state->msgs[state->current_msg];
/* Set the field as the assigned oneof */
if (0 != (state->field->flags & PROTOBUF_C_FIELD_FLAG_ONEOF)) {
STRUCT_MEMBER(uint32_t, msg, state->field->quantifier_offset) = state->field->id;
}
return STATE_OPEN;
}

Expand Down Expand Up @@ -789,6 +793,12 @@ state_value(State *state, Token *t)
state->field->quantifier_offset) = 1;
}
}

/* Set the field as the assigned oneof */
if (0 != (state->field->flags & PROTOBUF_C_FIELD_FLAG_ONEOF)) {
STRUCT_MEMBER(uint32_t, msg, state->field->quantifier_offset) = state->field->id;
}

switch (t->id) {
case TOK_BAREWORD:
if (state->field->type == PROTOBUF_C_TYPE_ENUM) {
Expand Down