diff options
Diffstat (limited to 'upb')
-rw-r--r-- | upb/decode.c | 5 | ||||
-rw-r--r-- | upb/encode.c | 13 |
2 files changed, 14 insertions, 4 deletions
diff --git a/upb/decode.c b/upb/decode.c index a1910a1..3a44021 100644 --- a/upb/decode.c +++ b/upb/decode.c @@ -309,6 +309,11 @@ static bool upb_decode_varintfield(upb_decstate *d, upb_decframe *frame, memcpy(field_mem, &val32, sizeof(val32)); break; } + case UPB_DESCRIPTOR_TYPE_BOOL: { + bool valbool = val != 0; + memcpy(field_mem, &valbool, sizeof(valbool)); + break; + } case UPB_DESCRIPTOR_TYPE_SINT32: { int32_t decoded = upb_zzdec_32(val); memcpy(field_mem, &decoded, sizeof(decoded)); diff --git a/upb/encode.c b/upb/encode.c index 8a220ef..4aafb9c 100644 --- a/upb/encode.c +++ b/upb/encode.c @@ -258,7 +258,7 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, bool is_proto3) { #define CASE(ctype, type, wire_type, encodeval) do { \ ctype val = *(ctype*)field_mem; \ - if (is_proto3 && val == 0) { \ + if (is_proto3 && f->oneof_index == UPB_NOT_IN_ONEOF && val == 0) { \ return true; \ } \ return upb_put_ ## type(e, encodeval) && \ @@ -292,7 +292,7 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, case UPB_DESCRIPTOR_TYPE_STRING: case UPB_DESCRIPTOR_TYPE_BYTES: { upb_stringview view = *(upb_stringview*)field_mem; - if (is_proto3 && view.size == 0) { + if (is_proto3 && f->oneof_index == UPB_NOT_IN_ONEOF && view.size == 0) { return true; } return upb_put_bytes(e, view.data, view.size) && @@ -303,7 +303,7 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, size_t size; void *submsg = *(void**)field_mem; const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; - if (is_proto3 && submsg == NULL) { + if (is_proto3 && f->oneof_index == UPB_NOT_IN_ONEOF && submsg == NULL) { return true; } return upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) && @@ -314,7 +314,7 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem, size_t size; void *submsg = *(void**)field_mem; const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index]; - if (is_proto3 && submsg == NULL) { + if (is_proto3 && f->oneof_index == UPB_NOT_IN_ONEOF && submsg == NULL) { return true; } return upb_encode_message(e, submsg, subm, &size) && @@ -344,6 +344,11 @@ bool upb_encode_message(upb_encstate* e, const char *msg, size_t *size) { int i; char *buf_end = e->ptr; + + if (msg == NULL) { + return true; + } + for (i = m->field_count - 1; i >= 0; i--) { const upb_msglayout_fieldinit_v1 *f = &m->fields[i]; |