diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2018-03-07 12:13:54 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-07 12:13:54 -0800 |
commit | 69719e0a06da41e074dc43b7f593006a5f145f86 (patch) | |
tree | ba2f68ad7cf385751f663e2ea68b488436f30e62 | |
parent | 10ae4951fba613067fe4bb967bbd6093d77bdc98 (diff) | |
parent | 719f644232bf143d48e7bc041ab8a0ae3fddaa9b (diff) |
Merge pull request #98 from TeBoring/php-change
Field missing submsg, hasbit and default value information.
-rw-r--r-- | upb/msg.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -221,7 +221,8 @@ static bool upb_msglayout_initdefault(upb_msglayout *l, const upb_msgdef *m) { return true; } -static upb_msglayout *upb_msglayout_new(const upb_msgdef *m) { +static upb_msglayout *upb_msglayout_new(const upb_msgdef *m, + upb_msgfactory *factory) { upb_msg_field_iter it; upb_msg_oneof_iter oit; upb_msglayout *l; @@ -277,6 +278,7 @@ static upb_msglayout *upb_msglayout_new(const upb_msgdef *m) { */ /* Allocate hasbits and set basic field attributes. */ + submsg_count = 0; for (upb_msg_field_begin(&it, m), hasbit = 0; !upb_msg_field_done(&it); upb_msg_field_next(&it)) { @@ -293,8 +295,19 @@ static upb_msglayout *upb_msglayout_new(const upb_msgdef *m) { field->oneof_index = UPB_NOT_IN_ONEOF; } + if (upb_fielddef_issubmsg(f)) { + const upb_msglayout *sub_layout = + upb_msgfactory_getlayout(factory, upb_fielddef_msgsubdef(f)); + field->submsg_index = submsg_count++; + submsgs[field->submsg_index] = &sub_layout->data; + } else { + field->submsg_index = UPB_NO_SUBMSG; + } + if (upb_fielddef_haspresence(f) && !upb_fielddef_containingoneof(f)) { field->hasbit = hasbit++; + } else { + field->hasbit = UPB_NO_HASBIT; } } @@ -405,7 +418,7 @@ const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f, return upb_value_getptr(v); } else { upb_msgfactory *mutable_f = (void*)f; - upb_msglayout *l = upb_msglayout_new(m); + upb_msglayout *l = upb_msglayout_new(m, mutable_f); upb_inttable_insertptr(&mutable_f->layouts, m, upb_value_ptr(l)); UPB_ASSERT(l); return l; |