Merge pull request #100 from TeBoring/php-change

Fix oneof encoding/decoding
pull/13171/head
Paul Yang 7 years ago committed by GitHub
commit 681cf4279c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      upb/decode.c
  2. 6
      upb/encode.c

@ -269,7 +269,8 @@ static bool upb_decode_submsg(upb_decstate *d,
const char *limit,
const upb_msglayout_fieldinit_v1 *field,
int group_number) {
char *submsg = *(void**)&frame->msg[field->offset];
char *submsg_slot = upb_decode_prepareslot(d, frame, field);
char *submsg = *(void**)submsg_slot;
const upb_msglayout_msginit_v1 *subm;
UPB_ASSERT(field->submsg_index != UPB_NO_SUBMSG);
@ -281,7 +282,7 @@ static bool upb_decode_submsg(upb_decstate *d,
CHK(submsg);
submsg = upb_msg_init(
submsg, (upb_msglayout*)subm, upb_arena_alloc(upb_env_arena(d->env)));
*(void**)&frame->msg[field->offset] = submsg;
*(void**)submsg_slot = submsg;
}
upb_decode_message(d, limit, group_number, submsg, subm);

@ -360,7 +360,13 @@ bool upb_encode_message(upb_encstate* e, const char *msg,
CHK(upb_encode_array(e, msg + f->offset, m, f));
} else {
if (upb_encode_hasscalarfield(msg, m, f)) {
if (f->oneof_index == UPB_NOT_IN_ONEOF) {
CHK(upb_encode_scalarfield(e, msg + f->offset, m, f, !m->is_proto2));
} else {
const upb_msglayout_oneofinit_v1 *o = &m->oneofs[f->oneof_index];
CHK(upb_encode_scalarfield(e, msg + o->data_offset,
m, f, !m->is_proto2));
}
}
}
}

Loading…
Cancel
Save