diff options
-rw-r--r-- | descriptor/descriptor.h | 36 | ||||
-rw-r--r-- | src/upb_data.h | 4 | ||||
-rw-r--r-- | tools/upbc.c | 31 |
3 files changed, 17 insertions, 54 deletions
diff --git a/descriptor/descriptor.h b/descriptor/descriptor.h index 313cc89..5e24abd 100644 --- a/descriptor/descriptor.h +++ b/descriptor/descriptor.h @@ -90,8 +90,6 @@ typedef struct google_protobuf_MethodOptions /* The message definitions themselves. */ struct google_protobuf_UninterpretedOption_NamePart { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { @@ -105,8 +103,6 @@ struct google_protobuf_UninterpretedOption_NamePart { UPB_DEFINE_MSG_ARRAY(google_protobuf_UninterpretedOption_NamePart) struct google_protobuf_DescriptorProto { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { @@ -130,8 +126,6 @@ struct google_protobuf_DescriptorProto { UPB_DEFINE_MSG_ARRAY(google_protobuf_DescriptorProto) struct google_protobuf_EnumDescriptorProto { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { @@ -147,8 +141,6 @@ struct google_protobuf_EnumDescriptorProto { UPB_DEFINE_MSG_ARRAY(google_protobuf_EnumDescriptorProto) struct google_protobuf_UninterpretedOption { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { @@ -170,8 +162,6 @@ struct google_protobuf_UninterpretedOption { UPB_DEFINE_MSG_ARRAY(google_protobuf_UninterpretedOption) struct google_protobuf_FileDescriptorProto { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { @@ -197,8 +187,6 @@ struct google_protobuf_FileDescriptorProto { UPB_DEFINE_MSG_ARRAY(google_protobuf_FileDescriptorProto) struct google_protobuf_MethodDescriptorProto { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { @@ -216,8 +204,6 @@ struct google_protobuf_MethodDescriptorProto { UPB_DEFINE_MSG_ARRAY(google_protobuf_MethodDescriptorProto) struct google_protobuf_EnumValueOptions { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { @@ -229,8 +215,6 @@ struct google_protobuf_EnumValueOptions { UPB_DEFINE_MSG_ARRAY(google_protobuf_EnumValueOptions) struct google_protobuf_EnumValueDescriptorProto { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { @@ -246,8 +230,6 @@ struct google_protobuf_EnumValueDescriptorProto { UPB_DEFINE_MSG_ARRAY(google_protobuf_EnumValueDescriptorProto) struct google_protobuf_ServiceDescriptorProto { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { @@ -263,8 +245,6 @@ struct google_protobuf_ServiceDescriptorProto { UPB_DEFINE_MSG_ARRAY(google_protobuf_ServiceDescriptorProto) struct google_protobuf_FileDescriptorSet { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { @@ -276,8 +256,6 @@ struct google_protobuf_FileDescriptorSet { UPB_DEFINE_MSG_ARRAY(google_protobuf_FileDescriptorSet) struct google_protobuf_DescriptorProto_ExtensionRange { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { @@ -291,8 +269,6 @@ struct google_protobuf_DescriptorProto_ExtensionRange { UPB_DEFINE_MSG_ARRAY(google_protobuf_DescriptorProto_ExtensionRange) struct google_protobuf_FieldOptions { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { @@ -312,8 +288,6 @@ struct google_protobuf_FieldOptions { UPB_DEFINE_MSG_ARRAY(google_protobuf_FieldOptions) struct google_protobuf_FileOptions { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { @@ -333,8 +307,6 @@ struct google_protobuf_FileOptions { UPB_DEFINE_MSG_ARRAY(google_protobuf_FileOptions) struct google_protobuf_MessageOptions { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { @@ -348,8 +320,6 @@ struct google_protobuf_MessageOptions { UPB_DEFINE_MSG_ARRAY(google_protobuf_MessageOptions) struct google_protobuf_EnumOptions { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { @@ -361,8 +331,6 @@ struct google_protobuf_EnumOptions { UPB_DEFINE_MSG_ARRAY(google_protobuf_EnumOptions) struct google_protobuf_FieldDescriptorProto { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { @@ -388,8 +356,6 @@ struct google_protobuf_FieldDescriptorProto { UPB_DEFINE_MSG_ARRAY(google_protobuf_FieldDescriptorProto) struct google_protobuf_ServiceOptions { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { @@ -401,8 +367,6 @@ struct google_protobuf_ServiceOptions { UPB_DEFINE_MSG_ARRAY(google_protobuf_ServiceOptions) struct google_protobuf_MethodOptions { - struct upb_mmhead mmhead; - struct upb_msgdef *def; union { uint8_t bytes[1]; struct { diff --git a/src/upb_data.h b/src/upb_data.h index ea59ac7..ac886fe 100644 --- a/src/upb_data.h +++ b/src/upb_data.h @@ -160,8 +160,6 @@ INLINE bool _upb_data_unref(upb_data *d) { } } -struct upb_mmhead {}; - /* upb_string *****************************************************************/ typedef uint32_t upb_strlen_t; @@ -248,7 +246,7 @@ INLINE const char *upb_string_getrobuf(upb_string *s) { } // Returns the current length of the string. -INLINE size_t upb_strlen(upb_string *s) { +INLINE upb_strlen_t upb_strlen(upb_string *s) { return s->common.byte_len; } diff --git a/tools/upbc.c b/tools/upbc.c index 8e89435..5d90fcc 100644 --- a/tools/upbc.c +++ b/tools/upbc.c @@ -438,21 +438,22 @@ static void write_message_c(upb_msg *msg, struct upb_msgdef *md, upb_string *s = str_entries[i]->e.key; str_entries[i]->offset = offset; str_entries[i]->num = i; - for(uint32_t j = 0; j < s->byte_len; j++) { + const char *buf = upb_string_getrobuf(s); + for(uint32_t j = 0; j < upb_strlen(s); j++) { if(++col == 80) { fputs("\"\n \"", stream); col = 3; } - fputc(s->ptr[j], stream); + fputc(buf[j], stream); } - offset += s->byte_len; + offset += upb_strlen(s); } fputs("\";\n\n", stream); fputs("static struct upb_string strings[] = {\n", stream); for(int i = 0; i < size; i++) { struct strtable_entry *e = str_entries[i]; - fprintf(stream, " {.ptr = &strdata[%d], .byte_len=%d},\n", e->offset, e->e.key->byte_len); + fprintf(stream, " {.ptr = &strdata[%d], .byte_len=%d},\n", e->offset, upb_strlen(e->e.key)); } fputs("};\n\n", stream); free(str_entries); @@ -465,10 +466,10 @@ static void write_message_c(upb_msg *msg, struct upb_msgdef *md, /* A fake field to get the recursion going. */ struct upb_fielddef fake_field = { .type = UPB_TYPE(MESSAGE), - .def = UPB_UPCAST(msg->def), + .def = UPB_UPCAST(md), }; - add_value(upb_value_addrof(&val), &fake_field, &types); - add_submsgs(msg, &types); + add_value(val, &fake_field, &types); + add_submsgs(msg, md, &types); /* Emit foward declarations for all msgs of all types, and define arrays. */ fprintf(stream, "/* Forward declarations of messages, and array decls. */\n"); @@ -513,7 +514,7 @@ static void write_message_c(upb_msg *msg, struct upb_msgdef *md, for(upb_field_count_t j = 0; j < m->num_fields; j++) { struct upb_fielddef *f = &m->fields[j]; fprintf(stream, " ." UPB_STRFMT " = ", UPB_STRARG(f->name)); - if(upb_msg_isset(msgdata, f)) + if(upb_msg_has(msgdata, f)) fprintf(stream, "true"); else fprintf(stream, "false"); @@ -523,9 +524,9 @@ static void write_message_c(upb_msg *msg, struct upb_msgdef *md, /* Print msg data. */ for(upb_field_count_t j = 0; j < m->num_fields; j++) { struct upb_fielddef *f = &m->fields[j]; - union upb_value val = upb_value_read(upb_msg_getptr(msgdata, f), f->type); + union upb_value val = upb_msg_get(msgdata, f); fprintf(stream, " ." UPB_STRFMT " = ", UPB_STRARG(f->name)); - if(!upb_msg_isset(msgdata, f)) { + if(!upb_msg_has(msgdata, f)) { fputs("0, /* Not set. */", stream); } else if(upb_isstring(f)) { if(upb_isarray(f)) { @@ -666,13 +667,13 @@ int main(int argc, char *argv[]) if(!outfile_base) outfile_base = input_file; // Read and parse input file. - struct upb_string *descriptor = upb_strreadfile(input_file); + upb_string *descriptor = upb_strreadfile(input_file); if(!descriptor) error("Couldn't read input file."); struct upb_symtab *s = upb_symtab_new(); - struct upb_msg *fds_msg = upb_msg_new(s->fds_msgdef); + upb_msg *fds_msg = upb_msg_new(s->fds_msgdef); struct upb_status status = UPB_STATUS_INIT; - upb_msg_parsestr(fds_msg, descriptor->ptr, descriptor->byte_len, &status); + upb_msg_parsestr(fds_msg, s->fds_msgdef, descriptor, &status); if(!upb_ok(&status)) error("Failed to parse input file descriptor: %s", status.msg); google_protobuf_FileDescriptorSet *fds = (void*)fds_msg; @@ -724,10 +725,10 @@ int main(int argc, char *argv[]) if(cident) { FILE *c_file = fopen(c_filename, "w"); if(!c_file) error("Failed to open .h output file"); - write_message_c(fds_msg, cident, h_filename, argc, argv, input_file, c_file); + write_message_c(fds_msg, s->fds_msgdef, cident, h_filename, argc, argv, input_file, c_file); fclose(c_file); } - upb_msg_unref(fds_msg); + upb_msg_unref(fds_msg, s->fds_msgdef); upb_string_unref(descriptor); fclose(h_file); fclose(h_const_file); |