|
|
|
@ -473,7 +473,7 @@ static size_t align_up_to(size_t offset, size_t granularity) { |
|
|
|
|
return (offset + granularity - 1) & ~(granularity - 1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
MessageLayout* create_layout(const Descriptor* desc) { |
|
|
|
|
void create_layout(Descriptor* desc) { |
|
|
|
|
const upb_msgdef *msgdef = desc->msgdef; |
|
|
|
|
MessageLayout* layout = ALLOC(MessageLayout); |
|
|
|
|
int nfields = upb_msgdef_numfields(msgdef); |
|
|
|
@ -482,7 +482,10 @@ MessageLayout* create_layout(const Descriptor* desc) { |
|
|
|
|
size_t off = 0; |
|
|
|
|
size_t hasbit = 0; |
|
|
|
|
|
|
|
|
|
layout->empty_template = NULL; |
|
|
|
|
layout->desc = desc; |
|
|
|
|
desc->layout = layout; |
|
|
|
|
|
|
|
|
|
layout->fields = ALLOC_N(MessageField, nfields); |
|
|
|
|
|
|
|
|
|
for (upb_msg_field_begin(&it, msgdef); |
|
|
|
@ -584,10 +587,19 @@ MessageLayout* create_layout(const Descriptor* desc) { |
|
|
|
|
layout->size = off; |
|
|
|
|
layout->msgdef = msgdef; |
|
|
|
|
|
|
|
|
|
return layout; |
|
|
|
|
// Create the empty message template.
|
|
|
|
|
layout->empty_template = ALLOC_N(char, layout->size); |
|
|
|
|
memset(layout->empty_template, 0, layout->size); |
|
|
|
|
|
|
|
|
|
for (upb_msg_field_begin(&it, layout->msgdef); |
|
|
|
|
!upb_msg_field_done(&it); |
|
|
|
|
upb_msg_field_next(&it)) { |
|
|
|
|
layout_clear(layout, layout->empty_template, upb_msg_iter_field(&it)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void free_layout(MessageLayout* layout) { |
|
|
|
|
xfree(layout->empty_template); |
|
|
|
|
xfree(layout->fields); |
|
|
|
|
xfree(layout); |
|
|
|
|
} |
|
|
|
@ -868,15 +880,16 @@ void layout_set(MessageLayout* layout, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void layout_init(MessageLayout* layout, |
|
|
|
|
void* storage) { |
|
|
|
|
|
|
|
|
|
void layout_init(MessageLayout* layout, void* storage) { |
|
|
|
|
memcpy(storage, layout->empty_template, layout->size); |
|
|
|
|
/*
|
|
|
|
|
upb_msg_field_iter it; |
|
|
|
|
for (upb_msg_field_begin(&it, layout->msgdef); |
|
|
|
|
!upb_msg_field_done(&it); |
|
|
|
|
upb_msg_field_next(&it)) { |
|
|
|
|
layout_clear(layout, storage, upb_msg_iter_field(&it)); |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void layout_mark(MessageLayout* layout, void* storage) { |
|
|
|
|