diff --git a/LICENSE b/LICENSE index ec85a0d499..159a95af36 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,6 @@ Copyright (c) 2009, Joshua Haberman +Copyright (c) 2009, Google Inc. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/Makefile b/Makefile index b82f9e046b..eb2f10ddee 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,19 @@ .PHONY: all clean CFLAGS=-std=c99 -O3 -Wall -Wextra -pedantic -all: pbstream.o tests +OBJ=upb_parse.o upb_fieldmap.o upb_struct.o +all: $(OBJ) tests clean: - rm -f pbstream.o pbstruct.o tests + rm -f $(OBJ) tests -pbstream.o: pbstream.c pbstream.h - gcc $(CFLAGS) -o pbstream.o -c pbstream.c +upb_parse.o: upb_parse.c upb_parse.h + gcc $(CFLAGS) -o upb_parse.o -c upb_parse.c -tests: tests.c pbstream.c pbstream.h +upb_fieldmap.o: upb_fieldmap.c upb_fieldmap.h + gcc $(CFLAGS) -o upb_fieldmap.o -c upb_fieldmap.c + +upb_struct.o: upb_struct.c upb_struct.h + gcc $(CFLAGS) -o upb_struct.o -c upb_struct.c + +tests: tests.c upb_parse.c upb_parse.h gcc $(CFLAGS) -o tests tests.c diff --git a/README b/README index 8ee8c411ab..10e905adf5 100644 --- a/README +++ b/README @@ -1,9 +1,9 @@ -pbstream: a stream-oriented implementation of protocol buffers. +upb - a minimalist implementation of protocol buffers. -- For API documentation, see the header file. +- For API documentation, see the header files. - To build type "make". -Author: Joshua Haberman +Author: Joshua Haberman (joshua@reverberate.org, haberman@google.com) See LICENSE for copyright information. diff --git a/descriptor.c b/descriptor.c index 4a10abe2ad..951e7edfbd 100644 --- a/descriptor.c +++ b/descriptor.c @@ -1,57 +1,1494 @@ +#include "descriptor.h" -/* FileDescriptorSet */ -struct pbstream_FieldDescriptorProto pbstream_FileDescriptorSet_fields[] = { - {"file", 1, PBSTREAM_LABEL_OPTIONAL, PBSTREAM_TYPE_MESSAGE, "FileDescriptorProto"}, +static struct upb_string google_protobuf_filedescriptor_name = { + .byte_len=32, .data=(uint8_t*)"google/protobuf/descriptor.proto" }; -struct pbstream_DescriptorProto pbstream_FileDescriptorSet_desc = { - "FileDescriptorSet", .field_count=1, .field = pbstream_FileDescriptorSet_fields, + +static struct upb_string google_protobuf_filedescriptor_package = { + .byte_len=15, .data=(uint8_t*)"google.protobuf" +}; + +struct google_protobuf_DescriptorProto google_protobuf_FileDescriptorSet_descriptor; +struct google_protobuf_DescriptorProto google_protobuf_FileDescriptorProto_descriptor; +struct google_protobuf_DescriptorProto google_protobuf_DescriptorProto_descriptor; +struct google_protobuf_DescriptorProto google_protobuf_FieldDescriptorProto_descriptor; +struct google_protobuf_DescriptorProto google_protobuf_EnumDescriptorProto_descriptor; +struct google_protobuf_DescriptorProto google_protobuf_EnumValueDescriptorProto_descriptor; +struct google_protobuf_DescriptorProto google_protobuf_ServiceDescriptorProto_descriptor; +struct google_protobuf_DescriptorProto google_protobuf_MethodDescriptorProto_descriptor; +struct google_protobuf_DescriptorProto google_protobuf_FileOptions_descriptor; +struct google_protobuf_DescriptorProto google_protobuf_MessageOptions_descriptor; +struct google_protobuf_DescriptorProto google_protobuf_FieldOptions_descriptor; +struct google_protobuf_DescriptorProto google_protobuf_EnumOptions_descriptor; +struct google_protobuf_DescriptorProto google_protobuf_EnumValueOptions_descriptor; +struct google_protobuf_DescriptorProto google_protobuf_ServiceOptions_descriptor; +struct google_protobuf_DescriptorProto google_protobuf_MethodOptions_descriptor; +struct google_protobuf_DescriptorProto google_protobuf_UninterpretedOption_descriptor; + +static google_protobuf_DescriptorProto *google_protobuf_filedescriptor_message_type_array[] = { + &google_protobuf_FileDescriptorSet_descriptor, + &google_protobuf_FileDescriptorProto_descriptor, + &google_protobuf_DescriptorProto_descriptor, + &google_protobuf_FieldDescriptorProto_descriptor, + &google_protobuf_EnumDescriptorProto_descriptor, + &google_protobuf_EnumValueDescriptorProto_descriptor, + &google_protobuf_ServiceDescriptorProto_descriptor, + &google_protobuf_MethodDescriptorProto_descriptor, + &google_protobuf_FileOptions_descriptor, + &google_protobuf_MessageOptions_descriptor, + &google_protobuf_FieldOptions_descriptor, + &google_protobuf_EnumOptions_descriptor, + &google_protobuf_EnumValueOptions_descriptor, + &google_protobuf_ServiceOptions_descriptor, + &google_protobuf_MethodOptions_descriptor, + &google_protobuf_UninterpretedOption_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_DescriptorProto) google_protobuf_filedescriptor_message_type = { + .len=16, .elements=google_protobuf_filedescriptor_message_type_array +}; + +google_protobuf_FileDescriptorProto google_protobuf_filedescriptor = { + .set_flags = { .has = { + .name = 1, + .package = 1, + .dependency = 0, + .message_type = 1, + .enum_type = 0, + .service = 0, + .extension = 0, + .options = 1, + } }, + .name = &google_protobuf_filedescriptor_name, + .package = &google_protobuf_filedescriptor_package, + .dependency = NULL, + .message_type = &google_protobuf_filedescriptor_message_type, +}; + +/* google_protobuf_FileDescriptorSet_descriptor */ +static struct upb_string google_protobuf_FileDescriptorSet_descriptor_name = { + .byte_len=17, .data=(uint8_t*)"FileDescriptorSet" +}; + +struct google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorSet_file_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_FileDescriptorSet_descriptor_field_array[] = { + &google_protobuf_FileDescriptorSet_file_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_FileDescriptorSet_descriptor_field = { + .len=1, .elements=google_protobuf_FileDescriptorSet_descriptor_field_array +}; + +google_protobuf_DescriptorProto google_protobuf_FileDescriptorSet_descriptor = { + .name = &google_protobuf_FileDescriptorSet_descriptor_name, + .field = &google_protobuf_FileDescriptorSet_descriptor_field, + .nested_type = NULL, + .enum_type = NULL, + .extension_range = NULL, +}; +static struct upb_string google_protobuf_FileDescriptorSet_file_fieldname = { + .byte_len=4, .data=(uint8_t*)"file" +}; + +static struct upb_string google_protobuf_FileDescriptorSet_file_field_typename = { + .byte_len=19, .data=(uint8_t*)"FileDescriptorProto" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorSet_file = { + .name = &google_protobuf_FileDescriptorSet_file_fieldname, + .number = (uint32_t)1, + .label = 3, + .type = 11, + .type_name = &google_protobuf_FileDescriptorSet_file_field_typename, +}; +/* google_protobuf_FileDescriptorProto_descriptor */ +static struct upb_string google_protobuf_FileDescriptorProto_descriptor_name = { + .byte_len=19, .data=(uint8_t*)"FileDescriptorProto" +}; + +struct google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorProto_name_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorProto_package_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorProto_dependency_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorProto_message_type_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorProto_enum_type_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorProto_service_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorProto_extension_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorProto_options_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_FileDescriptorProto_descriptor_field_array[] = { + &google_protobuf_FileDescriptorProto_name_descriptor, + &google_protobuf_FileDescriptorProto_package_descriptor, + &google_protobuf_FileDescriptorProto_dependency_descriptor, + &google_protobuf_FileDescriptorProto_message_type_descriptor, + &google_protobuf_FileDescriptorProto_enum_type_descriptor, + &google_protobuf_FileDescriptorProto_service_descriptor, + &google_protobuf_FileDescriptorProto_extension_descriptor, + &google_protobuf_FileDescriptorProto_options_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_FileDescriptorProto_descriptor_field = { + .len=8, .elements=google_protobuf_FileDescriptorProto_descriptor_field_array +}; + +google_protobuf_DescriptorProto google_protobuf_FileDescriptorProto_descriptor = { + .name = &google_protobuf_FileDescriptorProto_descriptor_name, + .field = &google_protobuf_FileDescriptorProto_descriptor_field, + .nested_type = NULL, + .enum_type = NULL, + .extension_range = NULL, +}; +static struct upb_string google_protobuf_FileDescriptorProto_name_fieldname = { + .byte_len=4, .data=(uint8_t*)"name" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorProto_name = { + .name = &google_protobuf_FileDescriptorProto_name_fieldname, + .number = (uint32_t)1, + .label = 1, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_FileDescriptorProto_package_fieldname = { + .byte_len=7, .data=(uint8_t*)"package" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorProto_package = { + .name = &google_protobuf_FileDescriptorProto_package_fieldname, + .number = (uint32_t)2, + .label = 1, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_FileDescriptorProto_dependency_fieldname = { + .byte_len=10, .data=(uint8_t*)"dependency" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorProto_dependency = { + .name = &google_protobuf_FileDescriptorProto_dependency_fieldname, + .number = (uint32_t)3, + .label = 3, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_FileDescriptorProto_message_type_fieldname = { + .byte_len=12, .data=(uint8_t*)"message_type" +}; + +static struct upb_string google_protobuf_FileDescriptorProto_message_type_field_typename = { + .byte_len=15, .data=(uint8_t*)"DescriptorProto" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorProto_message_type = { + .name = &google_protobuf_FileDescriptorProto_message_type_fieldname, + .number = (uint32_t)4, + .label = 3, + .type = 11, + .type_name = &google_protobuf_FileDescriptorProto_message_type_field_typename, +}; +static struct upb_string google_protobuf_FileDescriptorProto_enum_type_fieldname = { + .byte_len=9, .data=(uint8_t*)"enum_type" +}; + +static struct upb_string google_protobuf_FileDescriptorProto_enum_type_field_typename = { + .byte_len=19, .data=(uint8_t*)"EnumDescriptorProto" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorProto_enum_type = { + .name = &google_protobuf_FileDescriptorProto_enum_type_fieldname, + .number = (uint32_t)5, + .label = 3, + .type = 11, + .type_name = &google_protobuf_FileDescriptorProto_enum_type_field_typename, +}; +static struct upb_string google_protobuf_FileDescriptorProto_service_fieldname = { + .byte_len=7, .data=(uint8_t*)"service" +}; + +static struct upb_string google_protobuf_FileDescriptorProto_service_field_typename = { + .byte_len=22, .data=(uint8_t*)"ServiceDescriptorProto" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorProto_service = { + .name = &google_protobuf_FileDescriptorProto_service_fieldname, + .number = (uint32_t)6, + .label = 3, + .type = 11, + .type_name = &google_protobuf_FileDescriptorProto_service_field_typename, +}; +static struct upb_string google_protobuf_FileDescriptorProto_extension_fieldname = { + .byte_len=9, .data=(uint8_t*)"extension" +}; + +static struct upb_string google_protobuf_FileDescriptorProto_extension_field_typename = { + .byte_len=20, .data=(uint8_t*)"FieldDescriptorProto" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorProto_extension = { + .name = &google_protobuf_FileDescriptorProto_extension_fieldname, + .number = (uint32_t)7, + .label = 3, + .type = 11, + .type_name = &google_protobuf_FileDescriptorProto_extension_field_typename, +}; +static struct upb_string google_protobuf_FileDescriptorProto_options_fieldname = { + .byte_len=7, .data=(uint8_t*)"options" +}; + +static struct upb_string google_protobuf_FileDescriptorProto_options_field_typename = { + .byte_len=11, .data=(uint8_t*)"FileOptions" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FileDescriptorProto_options = { + .name = &google_protobuf_FileDescriptorProto_options_fieldname, + .number = (uint32_t)8, + .label = 1, + .type = 11, + .type_name = &google_protobuf_FileDescriptorProto_options_field_typename, +}; +/* google_protobuf_DescriptorProto_descriptor */ +static struct upb_string google_protobuf_DescriptorProto_descriptor_name = { + .byte_len=15, .data=(uint8_t*)"DescriptorProto" +}; + +struct google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_name_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_field_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_extension_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_nested_type_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_enum_type_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_extension_range_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_options_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_DescriptorProto_descriptor_field_array[] = { + &google_protobuf_DescriptorProto_name_descriptor, + &google_protobuf_DescriptorProto_field_descriptor, + &google_protobuf_DescriptorProto_extension_descriptor, + &google_protobuf_DescriptorProto_nested_type_descriptor, + &google_protobuf_DescriptorProto_enum_type_descriptor, + &google_protobuf_DescriptorProto_extension_range_descriptor, + &google_protobuf_DescriptorProto_options_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_DescriptorProto_descriptor_field = { + .len=7, .elements=google_protobuf_DescriptorProto_descriptor_field_array +}; + +struct google_protobuf_DescriptorProto google_protobuf_DescriptorProto_ExtensionRange_descriptor; + +static google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_descriptor_nested_type_array[] = { + &google_protobuf_DescriptorProto_ExtensionRange_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_DescriptorProto) google_protobuf_DescriptorProto_descriptor_nested_type = { + .len=1, .elements=google_protobuf_DescriptorProto_descriptor_nested_type_array +}; + +google_protobuf_DescriptorProto google_protobuf_DescriptorProto_descriptor = { + .name = &google_protobuf_DescriptorProto_descriptor_name, + .field = &google_protobuf_DescriptorProto_descriptor_field, + .nested_type = &google_protobuf_DescriptorProto_descriptor_nested_type, + .enum_type = NULL, + .extension_range = NULL, +}; +static struct upb_string google_protobuf_DescriptorProto_name_fieldname = { + .byte_len=4, .data=(uint8_t*)"name" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_name = { + .name = &google_protobuf_DescriptorProto_name_fieldname, + .number = (uint32_t)1, + .label = 1, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_DescriptorProto_field_fieldname = { + .byte_len=5, .data=(uint8_t*)"field" +}; + +static struct upb_string google_protobuf_DescriptorProto_field_field_typename = { + .byte_len=20, .data=(uint8_t*)"FieldDescriptorProto" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_field = { + .name = &google_protobuf_DescriptorProto_field_fieldname, + .number = (uint32_t)2, + .label = 3, + .type = 11, + .type_name = &google_protobuf_DescriptorProto_field_field_typename, +}; +static struct upb_string google_protobuf_DescriptorProto_extension_fieldname = { + .byte_len=9, .data=(uint8_t*)"extension" +}; + +static struct upb_string google_protobuf_DescriptorProto_extension_field_typename = { + .byte_len=20, .data=(uint8_t*)"FieldDescriptorProto" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_extension = { + .name = &google_protobuf_DescriptorProto_extension_fieldname, + .number = (uint32_t)6, + .label = 3, + .type = 11, + .type_name = &google_protobuf_DescriptorProto_extension_field_typename, +}; +static struct upb_string google_protobuf_DescriptorProto_nested_type_fieldname = { + .byte_len=11, .data=(uint8_t*)"nested_type" +}; + +static struct upb_string google_protobuf_DescriptorProto_nested_type_field_typename = { + .byte_len=15, .data=(uint8_t*)"DescriptorProto" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_nested_type = { + .name = &google_protobuf_DescriptorProto_nested_type_fieldname, + .number = (uint32_t)3, + .label = 3, + .type = 11, + .type_name = &google_protobuf_DescriptorProto_nested_type_field_typename, +}; +static struct upb_string google_protobuf_DescriptorProto_enum_type_fieldname = { + .byte_len=9, .data=(uint8_t*)"enum_type" +}; + +static struct upb_string google_protobuf_DescriptorProto_enum_type_field_typename = { + .byte_len=19, .data=(uint8_t*)"EnumDescriptorProto" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_enum_type = { + .name = &google_protobuf_DescriptorProto_enum_type_fieldname, + .number = (uint32_t)4, + .label = 3, + .type = 11, + .type_name = &google_protobuf_DescriptorProto_enum_type_field_typename, +}; +static struct upb_string google_protobuf_DescriptorProto_extension_range_fieldname = { + .byte_len=15, .data=(uint8_t*)"extension_range" +}; + +static struct upb_string google_protobuf_DescriptorProto_extension_range_field_typename = { + .byte_len=14, .data=(uint8_t*)"ExtensionRange" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_extension_range = { + .name = &google_protobuf_DescriptorProto_extension_range_fieldname, + .number = (uint32_t)5, + .label = 3, + .type = 11, + .type_name = &google_protobuf_DescriptorProto_extension_range_field_typename, +}; +static struct upb_string google_protobuf_DescriptorProto_options_fieldname = { + .byte_len=7, .data=(uint8_t*)"options" +}; + +static struct upb_string google_protobuf_DescriptorProto_options_field_typename = { + .byte_len=14, .data=(uint8_t*)"MessageOptions" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_options = { + .name = &google_protobuf_DescriptorProto_options_fieldname, + .number = (uint32_t)7, + .label = 1, + .type = 11, + .type_name = &google_protobuf_DescriptorProto_options_field_typename, +}; +/* google_protobuf_DescriptorProto_ExtensionRange_descriptor */ +static struct upb_string google_protobuf_DescriptorProto_ExtensionRange_descriptor_name = { + .byte_len=14, .data=(uint8_t*)"ExtensionRange" +}; + +struct google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_ExtensionRange_start_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_ExtensionRange_end_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_DescriptorProto_ExtensionRange_descriptor_field_array[] = { + &google_protobuf_DescriptorProto_ExtensionRange_start_descriptor, + &google_protobuf_DescriptorProto_ExtensionRange_end_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_DescriptorProto_ExtensionRange_descriptor_field = { + .len=2, .elements=google_protobuf_DescriptorProto_ExtensionRange_descriptor_field_array +}; + +google_protobuf_DescriptorProto google_protobuf_DescriptorProto_ExtensionRange_descriptor = { + .name = &google_protobuf_DescriptorProto_ExtensionRange_descriptor_name, + .field = &google_protobuf_DescriptorProto_ExtensionRange_descriptor_field, + .nested_type = NULL, + .enum_type = NULL, + .extension_range = NULL, +}; +static struct upb_string google_protobuf_DescriptorProto_ExtensionRange_start_fieldname = { + .byte_len=5, .data=(uint8_t*)"start" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_ExtensionRange_start = { + .name = &google_protobuf_DescriptorProto_ExtensionRange_start_fieldname, + .number = (uint32_t)1, + .label = 1, + .type = 5, + .type_name = NULL, +}; +static struct upb_string google_protobuf_DescriptorProto_ExtensionRange_end_fieldname = { + .byte_len=3, .data=(uint8_t*)"end" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_DescriptorProto_ExtensionRange_end = { + .name = &google_protobuf_DescriptorProto_ExtensionRange_end_fieldname, + .number = (uint32_t)2, + .label = 1, + .type = 5, + .type_name = NULL, +}; +/* google_protobuf_FieldDescriptorProto_descriptor */ +static struct upb_string google_protobuf_FieldDescriptorProto_descriptor_name = { + .byte_len=20, .data=(uint8_t*)"FieldDescriptorProto" +}; + +struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto_name_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto_number_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto_label_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto_type_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto_type_name_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto_extendee_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto_default_value_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto_options_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_descriptor_field_array[] = { + &google_protobuf_FieldDescriptorProto_name_descriptor, + &google_protobuf_FieldDescriptorProto_number_descriptor, + &google_protobuf_FieldDescriptorProto_label_descriptor, + &google_protobuf_FieldDescriptorProto_type_descriptor, + &google_protobuf_FieldDescriptorProto_type_name_descriptor, + &google_protobuf_FieldDescriptorProto_extendee_descriptor, + &google_protobuf_FieldDescriptorProto_default_value_descriptor, + &google_protobuf_FieldDescriptorProto_options_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_FieldDescriptorProto_descriptor_field = { + .len=8, .elements=google_protobuf_FieldDescriptorProto_descriptor_field_array +}; + +struct google_protobuf_EnumDescriptorProto google_protobuf_FieldDescriptorProto_Type_descriptor; +struct google_protobuf_EnumDescriptorProto google_protobuf_FieldDescriptorProto_Label_descriptor; + +static google_protobuf_EnumDescriptorProto *google_protobuf_FieldDescriptorProto_descriptor_enum_type_array[] = { + &google_protobuf_FieldDescriptorProto_Type_descriptor, + &google_protobuf_FieldDescriptorProto_Label_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_EnumDescriptorProto) google_protobuf_FieldDescriptorProto_descriptor_enum_type = { + .len=2, .elements=google_protobuf_FieldDescriptorProto_descriptor_enum_type_array +}; + +google_protobuf_DescriptorProto google_protobuf_FieldDescriptorProto_descriptor = { + .name = &google_protobuf_FieldDescriptorProto_descriptor_name, + .field = &google_protobuf_FieldDescriptorProto_descriptor_field, + .nested_type = NULL, + .enum_type = &google_protobuf_FieldDescriptorProto_descriptor_enum_type, + .extension_range = NULL, +}; +static struct upb_string google_protobuf_FieldDescriptorProto_name_fieldname = { + .byte_len=4, .data=(uint8_t*)"name" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto_name = { + .name = &google_protobuf_FieldDescriptorProto_name_fieldname, + .number = (uint32_t)1, + .label = 1, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_FieldDescriptorProto_number_fieldname = { + .byte_len=6, .data=(uint8_t*)"number" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto_number = { + .name = &google_protobuf_FieldDescriptorProto_number_fieldname, + .number = (uint32_t)3, + .label = 1, + .type = 5, + .type_name = NULL, +}; +static struct upb_string google_protobuf_FieldDescriptorProto_label_fieldname = { + .byte_len=5, .data=(uint8_t*)"label" +}; + +static struct upb_string google_protobuf_FieldDescriptorProto_label_field_typename = { + .byte_len=5, .data=(uint8_t*)"Label" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto_label = { + .name = &google_protobuf_FieldDescriptorProto_label_fieldname, + .number = (uint32_t)4, + .label = 1, + .type = 14, + .type_name = &google_protobuf_FieldDescriptorProto_label_field_typename, +}; +static struct upb_string google_protobuf_FieldDescriptorProto_type_fieldname = { + .byte_len=4, .data=(uint8_t*)"type" +}; + +static struct upb_string google_protobuf_FieldDescriptorProto_type_field_typename = { + .byte_len=4, .data=(uint8_t*)"Type" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto_type = { + .name = &google_protobuf_FieldDescriptorProto_type_fieldname, + .number = (uint32_t)5, + .label = 1, + .type = 14, + .type_name = &google_protobuf_FieldDescriptorProto_type_field_typename, +}; +static struct upb_string google_protobuf_FieldDescriptorProto_type_name_fieldname = { + .byte_len=9, .data=(uint8_t*)"type_name" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto_type_name = { + .name = &google_protobuf_FieldDescriptorProto_type_name_fieldname, + .number = (uint32_t)6, + .label = 1, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_FieldDescriptorProto_extendee_fieldname = { + .byte_len=8, .data=(uint8_t*)"extendee" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto_extendee = { + .name = &google_protobuf_FieldDescriptorProto_extendee_fieldname, + .number = (uint32_t)2, + .label = 1, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_FieldDescriptorProto_default_value_fieldname = { + .byte_len=13, .data=(uint8_t*)"default_value" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto_default_value = { + .name = &google_protobuf_FieldDescriptorProto_default_value_fieldname, + .number = (uint32_t)7, + .label = 1, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_FieldDescriptorProto_options_fieldname = { + .byte_len=7, .data=(uint8_t*)"options" +}; + +static struct upb_string google_protobuf_FieldDescriptorProto_options_field_typename = { + .byte_len=12, .data=(uint8_t*)"FieldOptions" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto_options = { + .name = &google_protobuf_FieldDescriptorProto_options_fieldname, + .number = (uint32_t)8, + .label = 1, + .type = 11, + .type_name = &google_protobuf_FieldDescriptorProto_options_field_typename, +}; +static struct upb_string google_protobuf_FieldDescriptorProto_Type_name = { + .byte_len=4, .data=(uint8_t*)"Type" +}; + +google_protobuf_EnumDescriptorProto google_protobuf_FieldDescriptorProto_Type_descriptor = { + .name = &google_protobuf_FieldDescriptorProto_Type_name, +}; +static struct upb_string google_protobuf_FieldDescriptorProto_Label_name = { + .byte_len=5, .data=(uint8_t*)"Label" +}; + +google_protobuf_EnumDescriptorProto google_protobuf_FieldDescriptorProto_Label_descriptor = { + .name = &google_protobuf_FieldDescriptorProto_Label_name, +}; +/* google_protobuf_EnumDescriptorProto_descriptor */ +static struct upb_string google_protobuf_EnumDescriptorProto_descriptor_name = { + .byte_len=19, .data=(uint8_t*)"EnumDescriptorProto" +}; + +struct google_protobuf_FieldDescriptorProto google_protobuf_EnumDescriptorProto_name_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_EnumDescriptorProto_value_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_EnumDescriptorProto_options_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_EnumDescriptorProto_descriptor_field_array[] = { + &google_protobuf_EnumDescriptorProto_name_descriptor, + &google_protobuf_EnumDescriptorProto_value_descriptor, + &google_protobuf_EnumDescriptorProto_options_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_EnumDescriptorProto_descriptor_field = { + .len=3, .elements=google_protobuf_EnumDescriptorProto_descriptor_field_array +}; + +google_protobuf_DescriptorProto google_protobuf_EnumDescriptorProto_descriptor = { + .name = &google_protobuf_EnumDescriptorProto_descriptor_name, + .field = &google_protobuf_EnumDescriptorProto_descriptor_field, + .nested_type = NULL, + .enum_type = NULL, + .extension_range = NULL, +}; +static struct upb_string google_protobuf_EnumDescriptorProto_name_fieldname = { + .byte_len=4, .data=(uint8_t*)"name" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_EnumDescriptorProto_name = { + .name = &google_protobuf_EnumDescriptorProto_name_fieldname, + .number = (uint32_t)1, + .label = 1, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_EnumDescriptorProto_value_fieldname = { + .byte_len=5, .data=(uint8_t*)"value" +}; + +static struct upb_string google_protobuf_EnumDescriptorProto_value_field_typename = { + .byte_len=24, .data=(uint8_t*)"EnumValueDescriptorProto" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_EnumDescriptorProto_value = { + .name = &google_protobuf_EnumDescriptorProto_value_fieldname, + .number = (uint32_t)2, + .label = 3, + .type = 11, + .type_name = &google_protobuf_EnumDescriptorProto_value_field_typename, +}; +static struct upb_string google_protobuf_EnumDescriptorProto_options_fieldname = { + .byte_len=7, .data=(uint8_t*)"options" +}; + +static struct upb_string google_protobuf_EnumDescriptorProto_options_field_typename = { + .byte_len=11, .data=(uint8_t*)"EnumOptions" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_EnumDescriptorProto_options = { + .name = &google_protobuf_EnumDescriptorProto_options_fieldname, + .number = (uint32_t)3, + .label = 1, + .type = 11, + .type_name = &google_protobuf_EnumDescriptorProto_options_field_typename, +}; +/* google_protobuf_EnumValueDescriptorProto_descriptor */ +static struct upb_string google_protobuf_EnumValueDescriptorProto_descriptor_name = { + .byte_len=24, .data=(uint8_t*)"EnumValueDescriptorProto" +}; + +struct google_protobuf_FieldDescriptorProto google_protobuf_EnumValueDescriptorProto_name_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_EnumValueDescriptorProto_number_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_EnumValueDescriptorProto_options_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_EnumValueDescriptorProto_descriptor_field_array[] = { + &google_protobuf_EnumValueDescriptorProto_name_descriptor, + &google_protobuf_EnumValueDescriptorProto_number_descriptor, + &google_protobuf_EnumValueDescriptorProto_options_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_EnumValueDescriptorProto_descriptor_field = { + .len=3, .elements=google_protobuf_EnumValueDescriptorProto_descriptor_field_array +}; + +google_protobuf_DescriptorProto google_protobuf_EnumValueDescriptorProto_descriptor = { + .name = &google_protobuf_EnumValueDescriptorProto_descriptor_name, + .field = &google_protobuf_EnumValueDescriptorProto_descriptor_field, + .nested_type = NULL, + .enum_type = NULL, + .extension_range = NULL, +}; +static struct upb_string google_protobuf_EnumValueDescriptorProto_name_fieldname = { + .byte_len=4, .data=(uint8_t*)"name" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_EnumValueDescriptorProto_name = { + .name = &google_protobuf_EnumValueDescriptorProto_name_fieldname, + .number = (uint32_t)1, + .label = 1, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_EnumValueDescriptorProto_number_fieldname = { + .byte_len=6, .data=(uint8_t*)"number" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_EnumValueDescriptorProto_number = { + .name = &google_protobuf_EnumValueDescriptorProto_number_fieldname, + .number = (uint32_t)2, + .label = 1, + .type = 5, + .type_name = NULL, +}; +static struct upb_string google_protobuf_EnumValueDescriptorProto_options_fieldname = { + .byte_len=7, .data=(uint8_t*)"options" +}; + +static struct upb_string google_protobuf_EnumValueDescriptorProto_options_field_typename = { + .byte_len=16, .data=(uint8_t*)"EnumValueOptions" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_EnumValueDescriptorProto_options = { + .name = &google_protobuf_EnumValueDescriptorProto_options_fieldname, + .number = (uint32_t)3, + .label = 1, + .type = 11, + .type_name = &google_protobuf_EnumValueDescriptorProto_options_field_typename, +}; +/* google_protobuf_ServiceDescriptorProto_descriptor */ +static struct upb_string google_protobuf_ServiceDescriptorProto_descriptor_name = { + .byte_len=22, .data=(uint8_t*)"ServiceDescriptorProto" +}; + +struct google_protobuf_FieldDescriptorProto google_protobuf_ServiceDescriptorProto_name_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_ServiceDescriptorProto_method_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_ServiceDescriptorProto_options_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_ServiceDescriptorProto_descriptor_field_array[] = { + &google_protobuf_ServiceDescriptorProto_name_descriptor, + &google_protobuf_ServiceDescriptorProto_method_descriptor, + &google_protobuf_ServiceDescriptorProto_options_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_ServiceDescriptorProto_descriptor_field = { + .len=3, .elements=google_protobuf_ServiceDescriptorProto_descriptor_field_array +}; + +google_protobuf_DescriptorProto google_protobuf_ServiceDescriptorProto_descriptor = { + .name = &google_protobuf_ServiceDescriptorProto_descriptor_name, + .field = &google_protobuf_ServiceDescriptorProto_descriptor_field, + .nested_type = NULL, + .enum_type = NULL, + .extension_range = NULL, +}; +static struct upb_string google_protobuf_ServiceDescriptorProto_name_fieldname = { + .byte_len=4, .data=(uint8_t*)"name" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_ServiceDescriptorProto_name = { + .name = &google_protobuf_ServiceDescriptorProto_name_fieldname, + .number = (uint32_t)1, + .label = 1, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_ServiceDescriptorProto_method_fieldname = { + .byte_len=6, .data=(uint8_t*)"method" +}; + +static struct upb_string google_protobuf_ServiceDescriptorProto_method_field_typename = { + .byte_len=21, .data=(uint8_t*)"MethodDescriptorProto" }; -/* FileDescriptorProto */ -struct pbstream_FieldDescriptorProto pbstream_FileDescriptorProto_fields[] = { - {"message_type", 4, PBSTREAM_LABEL_REPEATED, PBSTREAM_TYPE_MESSAGE, "DescriptorProto"}, +google_protobuf_FieldDescriptorProto google_protobuf_ServiceDescriptorProto_method = { + .name = &google_protobuf_ServiceDescriptorProto_method_fieldname, + .number = (uint32_t)2, + .label = 3, + .type = 11, + .type_name = &google_protobuf_ServiceDescriptorProto_method_field_typename, }; -struct pbstream_DescriptorProto pbstream_FileDescriptorProto_desc = { - "FileDescriptorProto", .field_count=1, .field = pbstream_FileDescriptorProto_fields +static struct upb_string google_protobuf_ServiceDescriptorProto_options_fieldname = { + .byte_len=7, .data=(uint8_t*)"options" }; -/* DescriptorProto */ -struct pbstream_FieldDescriptorProto pbstream_DescriptorProto_fields[] = { - {"name", 1, PBSTREAM_LABEL_OPTIONAL, PBSTREAM_TYPE_STRING}, - {"field", 2, PBSTREAM_LABEL_REPEATED, PBSTREAM_TYPE_MESSAGE, "FieldDescriptorProto"}, - {"nested_type", 3, PBSTREAM_LABEL_REPEATED, PBSTREAM_TYPE_MESSAGE, "DescriptorProto"}, - {"enum_type", 4, PBSTREAM_LABEL_REPEATED, PBSTREAM_TYPE_MESSAGE, "EnumDescriptorProto"}, +static struct upb_string google_protobuf_ServiceDescriptorProto_options_field_typename = { + .byte_len=14, .data=(uint8_t*)"ServiceOptions" }; -struct pbstream_DescriptorProto pbstream_DescriptorProto_desc = { - "DescriptorProto", .field_count=4, .field = pbstream_DescriptorProto_fields + +google_protobuf_FieldDescriptorProto google_protobuf_ServiceDescriptorProto_options = { + .name = &google_protobuf_ServiceDescriptorProto_options_fieldname, + .number = (uint32_t)3, + .label = 1, + .type = 11, + .type_name = &google_protobuf_ServiceDescriptorProto_options_field_typename, +}; +/* google_protobuf_MethodDescriptorProto_descriptor */ +static struct upb_string google_protobuf_MethodDescriptorProto_descriptor_name = { + .byte_len=21, .data=(uint8_t*)"MethodDescriptorProto" +}; + +struct google_protobuf_FieldDescriptorProto google_protobuf_MethodDescriptorProto_name_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_MethodDescriptorProto_input_type_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_MethodDescriptorProto_output_type_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_MethodDescriptorProto_options_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_MethodDescriptorProto_descriptor_field_array[] = { + &google_protobuf_MethodDescriptorProto_name_descriptor, + &google_protobuf_MethodDescriptorProto_input_type_descriptor, + &google_protobuf_MethodDescriptorProto_output_type_descriptor, + &google_protobuf_MethodDescriptorProto_options_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_MethodDescriptorProto_descriptor_field = { + .len=4, .elements=google_protobuf_MethodDescriptorProto_descriptor_field_array +}; + +google_protobuf_DescriptorProto google_protobuf_MethodDescriptorProto_descriptor = { + .name = &google_protobuf_MethodDescriptorProto_descriptor_name, + .field = &google_protobuf_MethodDescriptorProto_descriptor_field, + .nested_type = NULL, + .enum_type = NULL, + .extension_range = NULL, +}; +static struct upb_string google_protobuf_MethodDescriptorProto_name_fieldname = { + .byte_len=4, .data=(uint8_t*)"name" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_MethodDescriptorProto_name = { + .name = &google_protobuf_MethodDescriptorProto_name_fieldname, + .number = (uint32_t)1, + .label = 1, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_MethodDescriptorProto_input_type_fieldname = { + .byte_len=10, .data=(uint8_t*)"input_type" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_MethodDescriptorProto_input_type = { + .name = &google_protobuf_MethodDescriptorProto_input_type_fieldname, + .number = (uint32_t)2, + .label = 1, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_MethodDescriptorProto_output_type_fieldname = { + .byte_len=11, .data=(uint8_t*)"output_type" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_MethodDescriptorProto_output_type = { + .name = &google_protobuf_MethodDescriptorProto_output_type_fieldname, + .number = (uint32_t)3, + .label = 1, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_MethodDescriptorProto_options_fieldname = { + .byte_len=7, .data=(uint8_t*)"options" +}; + +static struct upb_string google_protobuf_MethodDescriptorProto_options_field_typename = { + .byte_len=13, .data=(uint8_t*)"MethodOptions" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_MethodDescriptorProto_options = { + .name = &google_protobuf_MethodDescriptorProto_options_fieldname, + .number = (uint32_t)4, + .label = 1, + .type = 11, + .type_name = &google_protobuf_MethodDescriptorProto_options_field_typename, +}; +/* google_protobuf_FileOptions_descriptor */ +static struct upb_string google_protobuf_FileOptions_descriptor_name = { + .byte_len=11, .data=(uint8_t*)"FileOptions" +}; + +struct google_protobuf_FieldDescriptorProto google_protobuf_FileOptions_java_package_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FileOptions_java_outer_classname_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FileOptions_java_multiple_files_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FileOptions_optimize_for_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FileOptions_uninterpreted_option_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_FileOptions_descriptor_field_array[] = { + &google_protobuf_FileOptions_java_package_descriptor, + &google_protobuf_FileOptions_java_outer_classname_descriptor, + &google_protobuf_FileOptions_java_multiple_files_descriptor, + &google_protobuf_FileOptions_optimize_for_descriptor, + &google_protobuf_FileOptions_uninterpreted_option_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_FileOptions_descriptor_field = { + .len=5, .elements=google_protobuf_FileOptions_descriptor_field_array +}; + +struct google_protobuf_EnumDescriptorProto google_protobuf_FileOptions_OptimizeMode_descriptor; + +static google_protobuf_EnumDescriptorProto *google_protobuf_FileOptions_descriptor_enum_type_array[] = { + &google_protobuf_FileOptions_OptimizeMode_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_EnumDescriptorProto) google_protobuf_FileOptions_descriptor_enum_type = { + .len=1, .elements=google_protobuf_FileOptions_descriptor_enum_type_array +}; + +struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_FileOptions_descriptor_extension_range0_descriptor; + +static google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_FileOptions_descriptor_extension_range_array[] = { + &google_protobuf_FileOptions_descriptor_extension_range0_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_DescriptorProto_ExtensionRange) google_protobuf_FileOptions_descriptor_extension_range = { + .len=1, .elements=google_protobuf_FileOptions_descriptor_extension_range_array +}; + +google_protobuf_DescriptorProto google_protobuf_FileOptions_descriptor = { + .name = &google_protobuf_FileOptions_descriptor_name, + .field = &google_protobuf_FileOptions_descriptor_field, + .nested_type = NULL, + .enum_type = &google_protobuf_FileOptions_descriptor_enum_type, + .extension_range = &google_protobuf_FileOptions_descriptor_extension_range, +}; +static struct upb_string google_protobuf_FileOptions_java_package_fieldname = { + .byte_len=12, .data=(uint8_t*)"java_package" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FileOptions_java_package = { + .name = &google_protobuf_FileOptions_java_package_fieldname, + .number = (uint32_t)1, + .label = 1, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_FileOptions_java_outer_classname_fieldname = { + .byte_len=20, .data=(uint8_t*)"java_outer_classname" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FileOptions_java_outer_classname = { + .name = &google_protobuf_FileOptions_java_outer_classname_fieldname, + .number = (uint32_t)8, + .label = 1, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_FileOptions_java_multiple_files_fieldname = { + .byte_len=19, .data=(uint8_t*)"java_multiple_files" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FileOptions_java_multiple_files = { + .name = &google_protobuf_FileOptions_java_multiple_files_fieldname, + .number = (uint32_t)10, + .label = 1, + .type = 8, + .type_name = NULL, +}; +static struct upb_string google_protobuf_FileOptions_optimize_for_fieldname = { + .byte_len=12, .data=(uint8_t*)"optimize_for" +}; + +static struct upb_string google_protobuf_FileOptions_optimize_for_field_typename = { + .byte_len=12, .data=(uint8_t*)"OptimizeMode" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FileOptions_optimize_for = { + .name = &google_protobuf_FileOptions_optimize_for_fieldname, + .number = (uint32_t)9, + .label = 1, + .type = 14, + .type_name = &google_protobuf_FileOptions_optimize_for_field_typename, +}; +static struct upb_string google_protobuf_FileOptions_uninterpreted_option_fieldname = { + .byte_len=20, .data=(uint8_t*)"uninterpreted_option" +}; + +static struct upb_string google_protobuf_FileOptions_uninterpreted_option_field_typename = { + .byte_len=19, .data=(uint8_t*)"UninterpretedOption" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FileOptions_uninterpreted_option = { + .name = &google_protobuf_FileOptions_uninterpreted_option_fieldname, + .number = (uint32_t)999, + .label = 3, + .type = 11, + .type_name = &google_protobuf_FileOptions_uninterpreted_option_field_typename, +}; +static struct upb_string google_protobuf_FileOptions_OptimizeMode_name = { + .byte_len=12, .data=(uint8_t*)"OptimizeMode" }; -/* FieldDescriptorProto */ -struct pbstream_FieldDescriptorProto pbstream_FieldDescriptorProto_fields[] = { - {"name", 1, PBSTREAM_LABEL_OPTIONAL, PBSTREAM_TYPE_STRING}, - {"number", 3, PBSTREAM_LABEL_OPTIONAL, PBSTREAM_TYPE_INT32}, - {"type", 5, PBSTREAM_LABEL_OPTIONAL, PBSTREAM_TYPE_ENUM, "Type"}, - {"type_name", 6, PBSTREAM_LABEL_OPTIONAL, PBSTREAM_TYPE_STRING}, +google_protobuf_EnumDescriptorProto google_protobuf_FileOptions_OptimizeMode_descriptor = { + .name = &google_protobuf_FileOptions_OptimizeMode_name, }; -struct pbstream_DescriptorProto pbstream_FieldDescriptorProto_desc = { - "FieldDescriptorProto", .field_count=4, .field = pbstream_FieldDescriptorProto_fields +/* google_protobuf_MessageOptions_descriptor */ +static struct upb_string google_protobuf_MessageOptions_descriptor_name = { + .byte_len=14, .data=(uint8_t*)"MessageOptions" }; -/* EnumDescriptorProto */ -struct pbstream_FieldDescriptorProto pbstream_EnumDescriptorProto_fields[] = { - {"name", 1, PBSTREAM_LABEL_OPTIONAL, PBSTREAM_TYPE_STRING}, - {"value", 2, PBSTREAM_LABEL_REPEATED, PBSTREAM_TYPE_MESSAGE, "EnumValueDescriptorProto"}, +struct google_protobuf_FieldDescriptorProto google_protobuf_MessageOptions_message_set_wire_format_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_MessageOptions_uninterpreted_option_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_MessageOptions_descriptor_field_array[] = { + &google_protobuf_MessageOptions_message_set_wire_format_descriptor, + &google_protobuf_MessageOptions_uninterpreted_option_descriptor, }; -struct pbstream_DescriptorProto pbstream_EnumDescriptorProto_desc = { - "EnumDescriptorProto", .field_count=2, .field = pbstream_EnumDescriptorProto_fields + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_MessageOptions_descriptor_field = { + .len=2, .elements=google_protobuf_MessageOptions_descriptor_field_array }; -/* EnumValueDescriptorProto */ -struct pbstream_FieldDescriptorProto pbstream_EnumValueDescriptorProto_fields[] = { - {"name", 1, PBSTREAM_LABEL_OPTIONAL, PBSTREAM_TYPE_STRING}, - {"number", 2, PBSTREAM_LABEL_OPTIONAL, PBSTREAM_TYPE_INT32}, +struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_MessageOptions_descriptor_extension_range0_descriptor; + +static google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_MessageOptions_descriptor_extension_range_array[] = { + &google_protobuf_MessageOptions_descriptor_extension_range0_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_DescriptorProto_ExtensionRange) google_protobuf_MessageOptions_descriptor_extension_range = { + .len=1, .elements=google_protobuf_MessageOptions_descriptor_extension_range_array +}; + +google_protobuf_DescriptorProto google_protobuf_MessageOptions_descriptor = { + .name = &google_protobuf_MessageOptions_descriptor_name, + .field = &google_protobuf_MessageOptions_descriptor_field, + .nested_type = NULL, + .enum_type = NULL, + .extension_range = &google_protobuf_MessageOptions_descriptor_extension_range, +}; +static struct upb_string google_protobuf_MessageOptions_message_set_wire_format_fieldname = { + .byte_len=23, .data=(uint8_t*)"message_set_wire_format" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_MessageOptions_message_set_wire_format = { + .name = &google_protobuf_MessageOptions_message_set_wire_format_fieldname, + .number = (uint32_t)1, + .label = 1, + .type = 8, + .type_name = NULL, +}; +static struct upb_string google_protobuf_MessageOptions_uninterpreted_option_fieldname = { + .byte_len=20, .data=(uint8_t*)"uninterpreted_option" }; -struct pbstream_DescriptorProto pbstream_EnumValueDescriptorProto_desc = { - "EnumDescriptorProto", .field_count=4, .field = pbstream_EnumValueDescriptorProto_fields + +static struct upb_string google_protobuf_MessageOptions_uninterpreted_option_field_typename = { + .byte_len=19, .data=(uint8_t*)"UninterpretedOption" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_MessageOptions_uninterpreted_option = { + .name = &google_protobuf_MessageOptions_uninterpreted_option_fieldname, + .number = (uint32_t)999, + .label = 3, + .type = 11, + .type_name = &google_protobuf_MessageOptions_uninterpreted_option_field_typename, +}; +/* google_protobuf_FieldOptions_descriptor */ +static struct upb_string google_protobuf_FieldOptions_descriptor_name = { + .byte_len=12, .data=(uint8_t*)"FieldOptions" +}; + +struct google_protobuf_FieldDescriptorProto google_protobuf_FieldOptions_ctype_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FieldOptions_experimental_map_key_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_FieldOptions_uninterpreted_option_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_FieldOptions_descriptor_field_array[] = { + &google_protobuf_FieldOptions_ctype_descriptor, + &google_protobuf_FieldOptions_experimental_map_key_descriptor, + &google_protobuf_FieldOptions_uninterpreted_option_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_FieldOptions_descriptor_field = { + .len=3, .elements=google_protobuf_FieldOptions_descriptor_field_array +}; + +struct google_protobuf_EnumDescriptorProto google_protobuf_FieldOptions_CType_descriptor; + +static google_protobuf_EnumDescriptorProto *google_protobuf_FieldOptions_descriptor_enum_type_array[] = { + &google_protobuf_FieldOptions_CType_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_EnumDescriptorProto) google_protobuf_FieldOptions_descriptor_enum_type = { + .len=1, .elements=google_protobuf_FieldOptions_descriptor_enum_type_array }; +struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_FieldOptions_descriptor_extension_range0_descriptor; + +static google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_FieldOptions_descriptor_extension_range_array[] = { + &google_protobuf_FieldOptions_descriptor_extension_range0_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_DescriptorProto_ExtensionRange) google_protobuf_FieldOptions_descriptor_extension_range = { + .len=1, .elements=google_protobuf_FieldOptions_descriptor_extension_range_array +}; + +google_protobuf_DescriptorProto google_protobuf_FieldOptions_descriptor = { + .name = &google_protobuf_FieldOptions_descriptor_name, + .field = &google_protobuf_FieldOptions_descriptor_field, + .nested_type = NULL, + .enum_type = &google_protobuf_FieldOptions_descriptor_enum_type, + .extension_range = &google_protobuf_FieldOptions_descriptor_extension_range, +}; +static struct upb_string google_protobuf_FieldOptions_ctype_fieldname = { + .byte_len=5, .data=(uint8_t*)"ctype" +}; + +static struct upb_string google_protobuf_FieldOptions_ctype_field_typename = { + .byte_len=5, .data=(uint8_t*)"CType" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FieldOptions_ctype = { + .name = &google_protobuf_FieldOptions_ctype_fieldname, + .number = (uint32_t)1, + .label = 1, + .type = 14, + .type_name = &google_protobuf_FieldOptions_ctype_field_typename, +}; +static struct upb_string google_protobuf_FieldOptions_experimental_map_key_fieldname = { + .byte_len=20, .data=(uint8_t*)"experimental_map_key" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FieldOptions_experimental_map_key = { + .name = &google_protobuf_FieldOptions_experimental_map_key_fieldname, + .number = (uint32_t)9, + .label = 1, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_FieldOptions_uninterpreted_option_fieldname = { + .byte_len=20, .data=(uint8_t*)"uninterpreted_option" +}; + +static struct upb_string google_protobuf_FieldOptions_uninterpreted_option_field_typename = { + .byte_len=19, .data=(uint8_t*)"UninterpretedOption" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_FieldOptions_uninterpreted_option = { + .name = &google_protobuf_FieldOptions_uninterpreted_option_fieldname, + .number = (uint32_t)999, + .label = 3, + .type = 11, + .type_name = &google_protobuf_FieldOptions_uninterpreted_option_field_typename, +}; +static struct upb_string google_protobuf_FieldOptions_CType_name = { + .byte_len=5, .data=(uint8_t*)"CType" +}; + +google_protobuf_EnumDescriptorProto google_protobuf_FieldOptions_CType_descriptor = { + .name = &google_protobuf_FieldOptions_CType_name, +}; +/* google_protobuf_EnumOptions_descriptor */ +static struct upb_string google_protobuf_EnumOptions_descriptor_name = { + .byte_len=11, .data=(uint8_t*)"EnumOptions" +}; + +struct google_protobuf_FieldDescriptorProto google_protobuf_EnumOptions_uninterpreted_option_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_EnumOptions_descriptor_field_array[] = { + &google_protobuf_EnumOptions_uninterpreted_option_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_EnumOptions_descriptor_field = { + .len=1, .elements=google_protobuf_EnumOptions_descriptor_field_array +}; + +struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_EnumOptions_descriptor_extension_range0_descriptor; + +static google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_EnumOptions_descriptor_extension_range_array[] = { + &google_protobuf_EnumOptions_descriptor_extension_range0_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_DescriptorProto_ExtensionRange) google_protobuf_EnumOptions_descriptor_extension_range = { + .len=1, .elements=google_protobuf_EnumOptions_descriptor_extension_range_array +}; + +google_protobuf_DescriptorProto google_protobuf_EnumOptions_descriptor = { + .name = &google_protobuf_EnumOptions_descriptor_name, + .field = &google_protobuf_EnumOptions_descriptor_field, + .nested_type = NULL, + .enum_type = NULL, + .extension_range = &google_protobuf_EnumOptions_descriptor_extension_range, +}; +static struct upb_string google_protobuf_EnumOptions_uninterpreted_option_fieldname = { + .byte_len=20, .data=(uint8_t*)"uninterpreted_option" +}; + +static struct upb_string google_protobuf_EnumOptions_uninterpreted_option_field_typename = { + .byte_len=19, .data=(uint8_t*)"UninterpretedOption" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_EnumOptions_uninterpreted_option = { + .name = &google_protobuf_EnumOptions_uninterpreted_option_fieldname, + .number = (uint32_t)999, + .label = 3, + .type = 11, + .type_name = &google_protobuf_EnumOptions_uninterpreted_option_field_typename, +}; +/* google_protobuf_EnumValueOptions_descriptor */ +static struct upb_string google_protobuf_EnumValueOptions_descriptor_name = { + .byte_len=16, .data=(uint8_t*)"EnumValueOptions" +}; + +struct google_protobuf_FieldDescriptorProto google_protobuf_EnumValueOptions_uninterpreted_option_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_EnumValueOptions_descriptor_field_array[] = { + &google_protobuf_EnumValueOptions_uninterpreted_option_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_EnumValueOptions_descriptor_field = { + .len=1, .elements=google_protobuf_EnumValueOptions_descriptor_field_array +}; + +struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_EnumValueOptions_descriptor_extension_range0_descriptor; + +static google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_EnumValueOptions_descriptor_extension_range_array[] = { + &google_protobuf_EnumValueOptions_descriptor_extension_range0_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_DescriptorProto_ExtensionRange) google_protobuf_EnumValueOptions_descriptor_extension_range = { + .len=1, .elements=google_protobuf_EnumValueOptions_descriptor_extension_range_array +}; + +google_protobuf_DescriptorProto google_protobuf_EnumValueOptions_descriptor = { + .name = &google_protobuf_EnumValueOptions_descriptor_name, + .field = &google_protobuf_EnumValueOptions_descriptor_field, + .nested_type = NULL, + .enum_type = NULL, + .extension_range = &google_protobuf_EnumValueOptions_descriptor_extension_range, +}; +static struct upb_string google_protobuf_EnumValueOptions_uninterpreted_option_fieldname = { + .byte_len=20, .data=(uint8_t*)"uninterpreted_option" +}; + +static struct upb_string google_protobuf_EnumValueOptions_uninterpreted_option_field_typename = { + .byte_len=19, .data=(uint8_t*)"UninterpretedOption" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_EnumValueOptions_uninterpreted_option = { + .name = &google_protobuf_EnumValueOptions_uninterpreted_option_fieldname, + .number = (uint32_t)999, + .label = 3, + .type = 11, + .type_name = &google_protobuf_EnumValueOptions_uninterpreted_option_field_typename, +}; +/* google_protobuf_ServiceOptions_descriptor */ +static struct upb_string google_protobuf_ServiceOptions_descriptor_name = { + .byte_len=14, .data=(uint8_t*)"ServiceOptions" +}; + +struct google_protobuf_FieldDescriptorProto google_protobuf_ServiceOptions_uninterpreted_option_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_ServiceOptions_descriptor_field_array[] = { + &google_protobuf_ServiceOptions_uninterpreted_option_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_ServiceOptions_descriptor_field = { + .len=1, .elements=google_protobuf_ServiceOptions_descriptor_field_array +}; + +struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_ServiceOptions_descriptor_extension_range0_descriptor; + +static google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_ServiceOptions_descriptor_extension_range_array[] = { + &google_protobuf_ServiceOptions_descriptor_extension_range0_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_DescriptorProto_ExtensionRange) google_protobuf_ServiceOptions_descriptor_extension_range = { + .len=1, .elements=google_protobuf_ServiceOptions_descriptor_extension_range_array +}; + +google_protobuf_DescriptorProto google_protobuf_ServiceOptions_descriptor = { + .name = &google_protobuf_ServiceOptions_descriptor_name, + .field = &google_protobuf_ServiceOptions_descriptor_field, + .nested_type = NULL, + .enum_type = NULL, + .extension_range = &google_protobuf_ServiceOptions_descriptor_extension_range, +}; +static struct upb_string google_protobuf_ServiceOptions_uninterpreted_option_fieldname = { + .byte_len=20, .data=(uint8_t*)"uninterpreted_option" +}; + +static struct upb_string google_protobuf_ServiceOptions_uninterpreted_option_field_typename = { + .byte_len=19, .data=(uint8_t*)"UninterpretedOption" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_ServiceOptions_uninterpreted_option = { + .name = &google_protobuf_ServiceOptions_uninterpreted_option_fieldname, + .number = (uint32_t)999, + .label = 3, + .type = 11, + .type_name = &google_protobuf_ServiceOptions_uninterpreted_option_field_typename, +}; +/* google_protobuf_MethodOptions_descriptor */ +static struct upb_string google_protobuf_MethodOptions_descriptor_name = { + .byte_len=13, .data=(uint8_t*)"MethodOptions" +}; + +struct google_protobuf_FieldDescriptorProto google_protobuf_MethodOptions_uninterpreted_option_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_MethodOptions_descriptor_field_array[] = { + &google_protobuf_MethodOptions_uninterpreted_option_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_MethodOptions_descriptor_field = { + .len=1, .elements=google_protobuf_MethodOptions_descriptor_field_array +}; + +struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_MethodOptions_descriptor_extension_range0_descriptor; + +static google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_MethodOptions_descriptor_extension_range_array[] = { + &google_protobuf_MethodOptions_descriptor_extension_range0_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_DescriptorProto_ExtensionRange) google_protobuf_MethodOptions_descriptor_extension_range = { + .len=1, .elements=google_protobuf_MethodOptions_descriptor_extension_range_array +}; + +google_protobuf_DescriptorProto google_protobuf_MethodOptions_descriptor = { + .name = &google_protobuf_MethodOptions_descriptor_name, + .field = &google_protobuf_MethodOptions_descriptor_field, + .nested_type = NULL, + .enum_type = NULL, + .extension_range = &google_protobuf_MethodOptions_descriptor_extension_range, +}; +static struct upb_string google_protobuf_MethodOptions_uninterpreted_option_fieldname = { + .byte_len=20, .data=(uint8_t*)"uninterpreted_option" +}; + +static struct upb_string google_protobuf_MethodOptions_uninterpreted_option_field_typename = { + .byte_len=19, .data=(uint8_t*)"UninterpretedOption" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_MethodOptions_uninterpreted_option = { + .name = &google_protobuf_MethodOptions_uninterpreted_option_fieldname, + .number = (uint32_t)999, + .label = 3, + .type = 11, + .type_name = &google_protobuf_MethodOptions_uninterpreted_option_field_typename, +}; +/* google_protobuf_UninterpretedOption_descriptor */ +static struct upb_string google_protobuf_UninterpretedOption_descriptor_name = { + .byte_len=19, .data=(uint8_t*)"UninterpretedOption" +}; + +struct google_protobuf_FieldDescriptorProto google_protobuf_UninterpretedOption_name_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_UninterpretedOption_identifier_value_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_UninterpretedOption_positive_int_value_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_UninterpretedOption_negative_int_value_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_UninterpretedOption_double_value_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_UninterpretedOption_string_value_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_UninterpretedOption_descriptor_field_array[] = { + &google_protobuf_UninterpretedOption_name_descriptor, + &google_protobuf_UninterpretedOption_identifier_value_descriptor, + &google_protobuf_UninterpretedOption_positive_int_value_descriptor, + &google_protobuf_UninterpretedOption_negative_int_value_descriptor, + &google_protobuf_UninterpretedOption_double_value_descriptor, + &google_protobuf_UninterpretedOption_string_value_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_UninterpretedOption_descriptor_field = { + .len=6, .elements=google_protobuf_UninterpretedOption_descriptor_field_array +}; + +struct google_protobuf_DescriptorProto google_protobuf_UninterpretedOption_NamePart_descriptor; + +static google_protobuf_DescriptorProto *google_protobuf_UninterpretedOption_descriptor_nested_type_array[] = { + &google_protobuf_UninterpretedOption_NamePart_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_DescriptorProto) google_protobuf_UninterpretedOption_descriptor_nested_type = { + .len=1, .elements=google_protobuf_UninterpretedOption_descriptor_nested_type_array +}; + +google_protobuf_DescriptorProto google_protobuf_UninterpretedOption_descriptor = { + .name = &google_protobuf_UninterpretedOption_descriptor_name, + .field = &google_protobuf_UninterpretedOption_descriptor_field, + .nested_type = &google_protobuf_UninterpretedOption_descriptor_nested_type, + .enum_type = NULL, + .extension_range = NULL, +}; +static struct upb_string google_protobuf_UninterpretedOption_name_fieldname = { + .byte_len=4, .data=(uint8_t*)"name" +}; + +static struct upb_string google_protobuf_UninterpretedOption_name_field_typename = { + .byte_len=8, .data=(uint8_t*)"NamePart" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_UninterpretedOption_name = { + .name = &google_protobuf_UninterpretedOption_name_fieldname, + .number = (uint32_t)2, + .label = 3, + .type = 11, + .type_name = &google_protobuf_UninterpretedOption_name_field_typename, +}; +static struct upb_string google_protobuf_UninterpretedOption_identifier_value_fieldname = { + .byte_len=16, .data=(uint8_t*)"identifier_value" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_UninterpretedOption_identifier_value = { + .name = &google_protobuf_UninterpretedOption_identifier_value_fieldname, + .number = (uint32_t)3, + .label = 1, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_UninterpretedOption_positive_int_value_fieldname = { + .byte_len=18, .data=(uint8_t*)"positive_int_value" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_UninterpretedOption_positive_int_value = { + .name = &google_protobuf_UninterpretedOption_positive_int_value_fieldname, + .number = (uint32_t)4, + .label = 1, + .type = 4, + .type_name = NULL, +}; +static struct upb_string google_protobuf_UninterpretedOption_negative_int_value_fieldname = { + .byte_len=18, .data=(uint8_t*)"negative_int_value" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_UninterpretedOption_negative_int_value = { + .name = &google_protobuf_UninterpretedOption_negative_int_value_fieldname, + .number = (uint32_t)5, + .label = 1, + .type = 3, + .type_name = NULL, +}; +static struct upb_string google_protobuf_UninterpretedOption_double_value_fieldname = { + .byte_len=12, .data=(uint8_t*)"double_value" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_UninterpretedOption_double_value = { + .name = &google_protobuf_UninterpretedOption_double_value_fieldname, + .number = (uint32_t)6, + .label = 1, + .type = 1, + .type_name = NULL, +}; +static struct upb_string google_protobuf_UninterpretedOption_string_value_fieldname = { + .byte_len=12, .data=(uint8_t*)"string_value" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_UninterpretedOption_string_value = { + .name = &google_protobuf_UninterpretedOption_string_value_fieldname, + .number = (uint32_t)7, + .label = 1, + .type = 12, + .type_name = NULL, +}; +/* google_protobuf_UninterpretedOption_NamePart_descriptor */ +static struct upb_string google_protobuf_UninterpretedOption_NamePart_descriptor_name = { + .byte_len=8, .data=(uint8_t*)"NamePart" +}; + +struct google_protobuf_FieldDescriptorProto google_protobuf_UninterpretedOption_NamePart_name_part_descriptor; +struct google_protobuf_FieldDescriptorProto google_protobuf_UninterpretedOption_NamePart_is_extension_descriptor; + +static google_protobuf_FieldDescriptorProto *google_protobuf_UninterpretedOption_NamePart_descriptor_field_array[] = { + &google_protobuf_UninterpretedOption_NamePart_name_part_descriptor, + &google_protobuf_UninterpretedOption_NamePart_is_extension_descriptor, +}; + +static UPB_STRUCT_ARRAY(google_protobuf_FieldDescriptorProto) google_protobuf_UninterpretedOption_NamePart_descriptor_field = { + .len=2, .elements=google_protobuf_UninterpretedOption_NamePart_descriptor_field_array +}; + +google_protobuf_DescriptorProto google_protobuf_UninterpretedOption_NamePart_descriptor = { + .name = &google_protobuf_UninterpretedOption_NamePart_descriptor_name, + .field = &google_protobuf_UninterpretedOption_NamePart_descriptor_field, + .nested_type = NULL, + .enum_type = NULL, + .extension_range = NULL, +}; +static struct upb_string google_protobuf_UninterpretedOption_NamePart_name_part_fieldname = { + .byte_len=9, .data=(uint8_t*)"name_part" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_UninterpretedOption_NamePart_name_part = { + .name = &google_protobuf_UninterpretedOption_NamePart_name_part_fieldname, + .number = (uint32_t)1, + .label = 2, + .type = 9, + .type_name = NULL, +}; +static struct upb_string google_protobuf_UninterpretedOption_NamePart_is_extension_fieldname = { + .byte_len=12, .data=(uint8_t*)"is_extension" +}; + +google_protobuf_FieldDescriptorProto google_protobuf_UninterpretedOption_NamePart_is_extension = { + .name = &google_protobuf_UninterpretedOption_NamePart_is_extension_fieldname, + .number = (uint32_t)2, + .label = 2, + .type = 8, + .type_name = NULL, +}; diff --git a/pbstream.h b/pbstream.h deleted file mode 100644 index 6ad6685b26..0000000000 --- a/pbstream.h +++ /dev/null @@ -1,189 +0,0 @@ -/* - * pbstream - a stream-oriented implementation of protocol buffers. - * - * Copyright (c) 2008 Joshua Haberman. See LICENSE for details. - */ - -#ifndef PBSTREAM_H_ -#define PBSTREAM_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* The maximum that any submessages can be nested. Matches proto2's limit. */ -#define PBSTREAM_MAX_STACK 64 - -/* A list of types as they can appear in a .proto file. */ -typedef enum pbstream_type { - PBSTREAM_TYPE_DOUBLE = 0, - PBSTREAM_TYPE_FLOAT, - PBSTREAM_TYPE_INT32, - PBSTREAM_TYPE_INT64, - PBSTREAM_TYPE_UINT32, - PBSTREAM_TYPE_UINT64, - PBSTREAM_TYPE_SINT32, - PBSTREAM_TYPE_SINT64, - PBSTREAM_TYPE_FIXED32, - PBSTREAM_TYPE_FIXED64, - PBSTREAM_TYPE_SFIXED32, - PBSTREAM_TYPE_SFIXED64, - PBSTREAM_TYPE_BOOL, - PBSTREAM_TYPE_STRING, - PBSTREAM_TYPE_BYTES, - PBSTREAM_TYPE_ENUM, - PBSTREAM_TYPE_MESSAGE -} pbstream_type_t; - -/* A list of types as they are encoded on-the-wire. */ -typedef enum pbstream_wire_type { - PBSTREAM_WIRE_TYPE_VARINT = 0, - PBSTREAM_WIRE_TYPE_64BIT = 1, - PBSTREAM_WIRE_TYPE_DELIMITED = 2, - PBSTREAM_WIRE_TYPE_START_GROUP = 3, - PBSTREAM_WIRE_TYPE_END_GROUP = 4, - PBSTREAM_WIRE_TYPE_32BIT = 5, -} pbstream_wire_type_t; - -typedef int32_t pbstream_field_number_t; - -/* A deserialized value as described in a .proto file. */ -struct pbstream_tagged_value { - struct pbstream_field *field; - union pbstream_value { - double _double; - float _float; - int32_t int32; - int64_t int64; - uint32_t uint32; - uint64_t uint64; - bool _bool; - struct pbstream_delimited { - size_t offset; /* relative to the beginning of the stream. */ - uint32_t len; - } delimited; - } v; -}; - -/* A value as it is encoded on-the-wire, before it has been interpreted as - * any particular .proto type. */ -struct pbstream_tagged_wire_value { - pbstream_wire_type_t type; - union pbstream_wire_value { - uint64_t varint; - uint64_t _64bit; - struct { - size_t offset; /* relative to the beginning of the stream. */ - uint32_t len; - } delimited; - uint32_t _32bit; - } v; -}; - -/* Definition of a single field in a message. Note that this does not include - * nearly all of the information that can be specified about a field in a - * .proto file. For example, we don't even know the field's name. We keep - * only the information necessary to parse the field. */ -struct pbstream_field { - pbstream_field_number_t field_number; - pbstream_type_t type; - struct pbstream_fieldset *fieldset; /* if type == MESSAGE */ -}; - -/* A fieldset is a data structure that supports fast lookup of fields by number. - * It is logically a map of {field_number -> struct pbstream_field*}. Fast - * lookup is important, because it is in the critical path of parsing. */ -struct pbstream_fieldset { - int num_fields; - struct pbstream_field *fields; - int array_size; - struct pbstream_field **array; - /* TODO: the hashtable part. */ -}; - -/* Takes an array of num_fields fields and builds an optimized table for fast - * lookup of fields by number. The input fields need not be sorted. This - * fieldset must be freed with pbstream_free_fieldset(). */ -void pbstream_init_fieldset(struct pbstream_fieldset *fieldset, - struct pbstream_field *fields, - int num_fields); -void pbstream_free_fieldset(struct pbstream_fieldset *fieldset); - -struct pbstream_parse_stack_frame { - struct pbstream_fieldset *fieldset; - size_t end_offset; /* unknown for the top frame, so we set to SIZE_MAX */ -}; - -/* The stream parser's state. */ -struct pbstream_parse_state { - size_t offset; - struct pbstream_parse_stack_frame stack[PBSTREAM_MAX_STACK]; - struct pbstream_parse_stack_frame *top, *limit; -}; - -/* Call this once before parsing to initialize the data structures. - * message_type can be NULL, in which case all fields will be reported as - * unknown. */ -void pbstream_init_parser( - struct pbstream_parse_state *state, - struct pbstream_fieldset *toplevel_fieldset); - -/* Status as returned by pbstream_parse(). Status codes <0 are fatal errors - * that cannot be recovered. Status codes >0 are unusual but nonfatal events, - * which nonetheless must be handled differently since they do not return data - * in val. */ -typedef enum pbstream_status { - PBSTREAM_STATUS_OK = 0, - PBSTREAM_STATUS_SUBMESSAGE_END = 1, // No data is stored in val or wv. - - /** FATAL ERRORS: these indicate corruption, and cannot be recovered. */ - - // A varint did not terminate before hitting 64 bits. - PBSTREAM_ERROR_UNTERMINATED_VARINT = -1, - - // A submessage ended in the middle of data. - PBSTREAM_ERROR_BAD_SUBMESSAGE_END = -2, - - // Encountered a "group" on the wire (deprecated and unsupported). - PBSTREAM_ERROR_GROUP = -3, - - // Input was nested more than PBSTREAM_MAX_STACK deep. - PBSTREAM_ERROR_STACK_OVERFLOW = -4, - - // The input data caused the pb's offset (a size_t) to overflow. - PBSTREAM_ERROR_OVERFLOW = -5, - - /** NONFATAL ERRORS: the input was invalid, but we can continue if desired. */ - - // A value was encountered that was not defined in the .proto file. The - // unknown value is stored in wv. - PBSTREAM_ERROR_UNKNOWN_VALUE = 2, - - // A field was encoded with the wrong wire type. The wire value is stored in - // wv. - PBSTREAM_ERROR_MISMATCHED_TYPE = 3, -} pbstream_status_t; -struct pbstream_parse_state; - -/* The main parsing function. Parses the next value from buf, storing the - * parsed value in val. If val is of type PBSTREAM_TYPE_MESSAGE, then a - * submessage was entered. - * - * IMPORTANT NOTE: for efficiency, the parsing routines do not do bounds checks, - * and may read as much as far as buf+10. So the caller must ensure that buf is - * not within 10 bytes of unmapped memory, or the program will segfault. Clients - * are encouraged to overallocate their buffers by ten bytes to compensate. */ -pbstream_status_t pbstream_parse_field(struct pbstream_parse_state *s, - uint8_t *buf, - pbstream_field_number_t *fieldnum, - struct pbstream_tagged_value *val, - struct pbstream_tagged_wire_value *wv); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* PBSTREAM_H_ */ diff --git a/pbstream_lowlevel.h b/pbstream_lowlevel.h deleted file mode 100644 index c25b16d572..0000000000 --- a/pbstream_lowlevel.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * pbstream - a stream-oriented implementation of protocol buffers. - * - * Copyright (c) 2008 Joshua Haberman. See LICENSE for details. - * - * The structures and functions in this file offer more control than what is - * offered in pbstream.h. These can be used for more specialized/optimized - * parsing applications. */ - -#ifndef PBSTREAM_LOWLEVEL_H_ -#define PBSTREAM_LOWLEVEL_H_ - -#include "pbstream.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* A tag occurs before each value on-the-wire. */ -struct pbstream_tag { - pbstream_field_number_t field_number; - pbstream_wire_type_t wire_type; -}; - -/* Parses a single tag from the character data starting at buf, and updates - * buf to point one past the bytes that were consumed. buf will be incremented - * by at most ten bytes. */ -pbstream_status_t parse_tag(uint8_t **buf, struct pbstream_tag *tag); - -/* Parses a wire value with the given type (which must have been obtained from - * a tag that was just parsed) and adds the number of bytes that were consumed - * to *offset. */ -pbstream_status_t parse_wire_value(uint8_t *buf, size_t *offset, - pbstream_wire_type_t wt, - union pbstream_wire_value *wv); - -/* Like the above, but discards the wire value instead of saving it. */ -pbstream_status_t skip_wire_value(uint8_t *buf, size_t *offset, - pbstream_wire_type_t wt); - -/* Looks the given field number up in the fieldset, and returns the - * corresponding pbstream_field definition (or NULL if this field number - * does not exist in this fieldset). */ -struct pbstream_field *pbstream_find_field(struct pbstream_fieldset *fs, - pbstream_field_number_t num); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* PBSTREAM_LOWLEVEL_H_ */ diff --git a/upb.h b/upb.h new file mode 100644 index 0000000000..d63e207a51 --- /dev/null +++ b/upb.h @@ -0,0 +1,68 @@ +/* + * upb - a minimalist implementation of protocol buffers. + * + * Copyright (c) 2009 Joshua Haberman. See LICENSE for details. + */ + +#ifndef UPB_H_ +#define UPB_H_ + +#include +#include +#include /* for size_t. */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* The maximum that any submessages can be nested. Matches proto2's limit. */ +#define UPB_MAX_NESTING 64 + +/* A list of types as they are encoded on-the-wire. */ +typedef enum upb_wire_type { + UPB_WIRE_TYPE_VARINT = 0, + UPB_WIRE_TYPE_64BIT = 1, + UPB_WIRE_TYPE_DELIMITED = 2, + UPB_WIRE_TYPE_START_GROUP = 3, + UPB_WIRE_TYPE_END_GROUP = 4, + UPB_WIRE_TYPE_32BIT = 5, +} upb_wire_type_t; + +struct upb_delimited { + size_t offset; /* relative to the beginning of the stream. */ + uint32_t len; +}; + +/* A value as it is encoded on-the-wire. */ +union upb_wire_value { + uint64_t varint; + uint64_t _64bit; + uint32_t _32bit; + struct upb_delimited delimited; +}; + +/* A value as described in a .proto file. */ +union upb_value { + double _double; + float _float; + int32_t int32; + int64_t int64; + uint32_t uint32; + uint64_t uint64; + bool _bool; + struct upb_delimited delimited; +}; + +typedef int32_t upb_field_number_t; + +/* A tag occurs before each value on-the-wire. */ +struct upb_tag { + upb_field_number_t field_number; + upb_wire_type_t wire_type; +}; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* UPB_H_ */ diff --git a/upb_fieldmap.c b/upb_fieldmap.c new file mode 100644 index 0000000000..015b2e14f2 --- /dev/null +++ b/upb_fieldmap.c @@ -0,0 +1,50 @@ +/* + * upb - a minimalist implementation of protocol buffers. + * + * Copyright (c) 2009 Joshua Haberman. See LICENSE for details. + */ + +#include "upb_fieldmap.h" + +#include + +void pbstream_init_fieldmap(struct pbstream_fieldmap *fieldmap, + struct pbstream_field *fields, + int num_fields) +{ + qsort(fields, num_fields, sizeof(*fields), compare_fields); + + /* Find the largest n for which at least half the fieldnums 8 && maybe_n/(i+1) >= 2) break; + n = maybe_n; + } + + fieldmap->num_fields = num_fields; + fieldmap->fields = malloc(sizeof(*fieldmap->fields)*num_fields); + memcpy(fieldmap->fields, fields, sizeof(*fields)*num_fields); + + fieldmap->array_size = n; + fieldmap->array = malloc(sizeof(*fieldmap->array)*n); + memset(fieldmap->array, 0, sizeof(*fieldmap->array)*n); + + for (int i = 0; i < num_fields && fields[i].field_number <= n; i++) + fieldmap->array[fields[i].field_number-1] = &fieldmap->fields[i]; + + /* Until we support the hashtable part... */ + assert(n == fields[num_fields-1].field_number); +} + +void pbstream_free_fieldmap(struct pbstream_fieldmap *fieldmap) +{ + free(fieldmap->fields); + free(fieldmap->array); +} + +/* Emit definition for inline function. */ +extern void *upb_fieldmap_find(struct upb_fieldmap *fm, + pbstream_field_number_t num, + size_t info_size); diff --git a/upb_fieldmap.h b/upb_fieldmap.h new file mode 100644 index 0000000000..0fb5a3e634 --- /dev/null +++ b/upb_fieldmap.h @@ -0,0 +1,53 @@ +/* + * upb - a minimalist implementation of protocol buffers. + * + * Copyright (c) 2009 Joshua Haberman. See LICENSE for details. + * + * A fieldmap is a data structure that supports fast lookup of fields by + * number. It is logically a map of {field_number -> }, where + * is any struct that begins with the field number. Fast lookup + * is important, because it is in the critical path of parsing. */ + +#ifndef UPB_FIELDMAP_H_ +#define UPB_FIELDMAP_H_ + +#include "upb.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct upb_fieldmap { + int array_size; + void *array; + /* TODO: the hashtable part. */ +}; + +/* Takes an array of num_fields fields and builds an optimized table for fast + * lookup of fields by number. The input fields need not be sorted. This + * fieldmap must be freed with upb_free_fieldmap(). */ +void upb_init_fieldmap(struct upb_fieldmap *fieldmap, + void *fields, + int num_fields, + int field_size); +void upb_free_fieldmap(struct upb_fieldmap *fieldmap); + +/* Looks the given field number up in the fieldmap, and returns the + * corresponding field definition (or NULL if this field number does not exist + * in this fieldmap). */ +inline void *upb_fieldmap_find(struct upb_fieldmap *fm, + upb_field_number_t num, + size_t info_size) +{ + if (num < array_size) { + return (char*)fs->array + (num*info_size); + } else { + /* TODO: the hashtable part. */ + } +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* UPB_PARSE_H_ */ diff --git a/pbstream.c b/upb_parse.c similarity index 53% rename from pbstream.c rename to upb_parse.c index b613e339f6..c0fc0077d5 100644 --- a/pbstream.c +++ b/upb_parse.c @@ -1,14 +1,13 @@ /* - * pbstream - a stream-oriented implementation of protocol buffers. + * upb - a minimalist implementation of protocol buffers. * * Copyright (c) 2008-2009 Joshua Haberman. See LICENSE for details. */ +#include "upb_parse.h" + #include -#include #include -#include "pbstream.h" -#include "pbstream_lowlevel.h" /* Branch prediction hints for GCC. */ #ifdef __GNUC__ @@ -20,16 +19,16 @@ #endif #define CHECK(func) do { \ - pbstream_status_t status = func; \ - if(status != PBSTREAM_STATUS_OK) return status; \ + upb_status_t status = func; \ + if(status != UPB_STATUS_OK) return status; \ } while (0) /* Lowest-level functions -- these read integers from the input buffer. * To avoid branches, none of these do bounds checking. So we force clients * to overallocate their buffers by >=9 bytes. */ -static pbstream_status_t get_v_uint64_t(uint8_t *restrict *buf, - uint64_t *restrict val) +static upb_status_t get_v_uint64_t(uint8_t *restrict *buf, + uint64_t *restrict val) { uint8_t *ptr = *buf, b; uint32_t part0 = 0, part1 = 0, part2 = 0; @@ -45,15 +44,15 @@ static pbstream_status_t get_v_uint64_t(uint8_t *restrict *buf, b = *(ptr++); part1 |= (b & 0x7F) << 21; if (!(b & 0x80)) goto done; b = *(ptr++); part2 = (b & 0x7F) ; if (!(b & 0x80)) goto done; b = *(ptr++); part2 |= (b & 0x7F) << 7; if (!(b & 0x80)) goto done; - return PBSTREAM_ERROR_UNTERMINATED_VARINT; + return UPB_ERROR_UNTERMINATED_VARINT; done: *buf = ptr; *val = (uint64_t)part0 | ((uint64_t)part1 << 28) | ((uint64_t)part2 << 56); - return PBSTREAM_STATUS_OK; + return UPB_STATUS_OK; } -static pbstream_status_t skip_v_uint64_t(uint8_t **buf) +static upb_status_t skip_v_uint64_t(uint8_t **buf) { uint8_t *ptr = *buf, b; b = *(ptr++); if (!(b & 0x80)) goto done; @@ -66,15 +65,15 @@ static pbstream_status_t skip_v_uint64_t(uint8_t **buf) b = *(ptr++); if (!(b & 0x80)) goto done; b = *(ptr++); if (!(b & 0x80)) goto done; b = *(ptr++); if (!(b & 0x80)) goto done; - return PBSTREAM_ERROR_UNTERMINATED_VARINT; + return UPB_ERROR_UNTERMINATED_VARINT; done: *buf = (uint8_t*)ptr; - return PBSTREAM_STATUS_OK; + return UPB_STATUS_OK; } -static pbstream_status_t get_v_uint32_t(uint8_t *restrict *buf, - uint32_t *restrict val) +static upb_status_t get_v_uint32_t(uint8_t *restrict *buf, + uint32_t *restrict val) { uint8_t *ptr = *buf, b; uint32_t result; @@ -85,33 +84,33 @@ static pbstream_status_t get_v_uint32_t(uint8_t *restrict *buf, b = *(ptr++); result |= (b & 0x7F) << 14; if (!(b & 0x80)) goto done; b = *(ptr++); result |= (b & 0x7F) << 21; if (!(b & 0x80)) goto done; b = *(ptr++); result = (b & 0x7F) << 28; if (!(b & 0x80)) goto done; - return PBSTREAM_ERROR_UNTERMINATED_VARINT; + return UPB_ERROR_UNTERMINATED_VARINT; done: *buf = ptr; *val = result; - return PBSTREAM_STATUS_OK; + return UPB_STATUS_OK; } -static pbstream_status_t get_f_uint32_t(uint8_t *restrict *buf, - uint32_t *restrict val) +static upb_status_t get_f_uint32_t(uint8_t *restrict *buf, + uint32_t *restrict val) { uint8_t *b = *buf; #define SHL(val, bits) ((uint32_t)val << bits) *val = SHL(b[0], 0) | SHL(b[1], 8) | SHL(b[2], 16) | SHL(b[3], 24); #undef SHL *buf += sizeof(uint32_t); - return PBSTREAM_STATUS_OK; + return UPB_STATUS_OK; } -static pbstream_status_t skip_f_uint32_t(uint8_t **buf) +static upb_status_t skip_f_uint32_t(uint8_t **buf) { *buf += sizeof(uint32_t); - return PBSTREAM_STATUS_OK; + return UPB_STATUS_OK; } -static pbstream_status_t get_f_uint64_t(uint8_t *restrict *buf, - uint64_t *restrict val) +static upb_status_t get_f_uint64_t(uint8_t *restrict *buf, + uint64_t *restrict val) { uint8_t *b = *buf; /* TODO: is this worth 32/64 specializing? */ @@ -120,13 +119,13 @@ static pbstream_status_t get_f_uint64_t(uint8_t *restrict *buf, SHL(b[4], 32) | SHL(b[5], 40) | SHL(b[6], 48) | SHL(b[7], 56); #undef SHL *buf += sizeof(uint64_t); - return PBSTREAM_STATUS_OK; + return UPB_STATUS_OK; } -static pbstream_status_t skip_f_uint64_t(uint8_t **buf) +static upb_status_t skip_f_uint64_t(uint8_t **buf) { *buf += sizeof(uint64_t); - return PBSTREAM_STATUS_OK; + return UPB_STATUS_OK; } static int32_t zz_decode_32(uint32_t n) { return (n >> 1) ^ -(int32_t)(n & 1); } @@ -139,15 +138,15 @@ static int64_t zz_decode_64(uint64_t n) { return (n >> 1) ^ -(int64_t)(n & 1); } static void wvtov_ ## type(wire_t s, val_t *d) #define GET(type, v_or_f, wire_t, val_t, member_name) \ - static pbstream_status_t get_ ## type(struct pbstream_parse_state *s, \ + static upb_status_t get_ ## type(struct upb_parse_state *s, \ uint8_t *buf, \ - struct pbstream_tagged_value *d) { \ + struct upb_tagged_value *d) { \ wire_t tmp; \ uint8_t *b = buf; \ CHECK(get_ ## v_or_f ## _ ## wire_t(&b, &tmp)); \ wvtov_ ## type(tmp, &d->v.member_name); \ s->offset += (b-buf); \ - return PBSTREAM_STATUS_OK; \ + return UPB_STATUS_OK; \ } #define T(type, v_or_f, wire_t, val_t, member_name) \ @@ -173,28 +172,28 @@ T(ENUM, v, uint32_t, int32_t, int32) { *d = (int32_t)s; } #undef GET #undef T -static void wvtov_delimited(uint32_t s, struct pbstream_delimited *d, size_t o) +static void wvtov_delimited(uint32_t s, struct upb_delimited *d, size_t o) { d->offset = o; d->len = s; } /* Use BYTES version for both STRING and BYTES, leave UTF-8 checks to client. */ -static pbstream_status_t get_BYTES(struct pbstream_parse_state *s, uint8_t *buf, - struct pbstream_tagged_value *d) { +static upb_status_t get_BYTES(struct upb_parse_state *s, uint8_t *buf, + struct upb_tagged_value *d) { uint32_t tmp; uint8_t *b = buf; CHECK(get_v_uint32_t(&b, &tmp)); s->offset += (b-buf); /* advance past length varint. */ wvtov_delimited(tmp, &d->v.delimited, s->offset); size_t new_offset = s->offset + d->v.delimited.len; /* skip bytes */ - if (unlikely(new_offset < s->offset)) return PBSTREAM_ERROR_OVERFLOW; + if (unlikely(new_offset < s->offset)) return UPB_ERROR_OVERFLOW; s->offset = new_offset; - return PBSTREAM_STATUS_OK; + return UPB_STATUS_OK; } -static pbstream_status_t get_MESSAGE(struct pbstream_parse_state *s, uint8_t *buf, - struct pbstream_tagged_value *d) { +static upb_status_t get_MESSAGE(struct upb_parse_state *s, uint8_t *buf, + struct upb_tagged_value *d) { /* We're entering a sub-message. */ uint32_t tmp; uint8_t *b = buf; @@ -202,146 +201,139 @@ static pbstream_status_t get_MESSAGE(struct pbstream_parse_state *s, uint8_t *bu s->offset += (b-buf); /* advance past length varint. */ wvtov_delimited(tmp, &d->v.delimited, s->offset); /* Unlike STRING and BYTES, we *don't* advance past delimited here. */ - if (unlikely(++s->top == s->limit)) return PBSTREAM_ERROR_STACK_OVERFLOW; + if (unlikely(++s->top == s->limit)) return UPB_ERROR_STACK_OVERFLOW; s->top->fieldset = d->field->fieldset; s->top->end_offset = d->v.delimited.offset + d->v.delimited.len; - if (unlikely(s->top->end_offset < s->offset)) return PBSTREAM_ERROR_OVERFLOW; - return PBSTREAM_STATUS_OK; + if (unlikely(s->top->end_offset < s->offset)) return UPB_ERROR_OVERFLOW; + return UPB_STATUS_OK; } -struct pbstream_type_info { - pbstream_wire_type_t expected_wire_type; - pbstream_status_t (*get)(struct pbstream_parse_state *s, uint8_t *buf, - struct pbstream_tagged_value *d); +struct upb_type_info { + upb_wire_type_t expected_wire_type; + upb_status_t (*get)(struct upb_parse_state *s, uint8_t *buf, + struct upb_tagged_value *d); }; -static struct pbstream_type_info type_info[] = { - {PBSTREAM_WIRE_TYPE_64BIT, get_DOUBLE}, - {PBSTREAM_WIRE_TYPE_32BIT, get_FLOAT}, - {PBSTREAM_WIRE_TYPE_VARINT, get_INT32}, - {PBSTREAM_WIRE_TYPE_VARINT, get_INT64}, - {PBSTREAM_WIRE_TYPE_VARINT, get_UINT32}, - {PBSTREAM_WIRE_TYPE_VARINT, get_UINT64}, - {PBSTREAM_WIRE_TYPE_VARINT, get_SINT32}, - {PBSTREAM_WIRE_TYPE_VARINT, get_SINT64}, - {PBSTREAM_WIRE_TYPE_32BIT, get_FIXED32}, - {PBSTREAM_WIRE_TYPE_64BIT, get_FIXED64}, - {PBSTREAM_WIRE_TYPE_32BIT, get_SFIXED32}, - {PBSTREAM_WIRE_TYPE_64BIT, get_SFIXED64}, - {PBSTREAM_WIRE_TYPE_VARINT, get_BOOL}, - {PBSTREAM_WIRE_TYPE_DELIMITED, get_BYTES}, - {PBSTREAM_WIRE_TYPE_DELIMITED, get_BYTES}, - {PBSTREAM_WIRE_TYPE_VARINT, get_ENUM}, - {PBSTREAM_WIRE_TYPE_DELIMITED, get_MESSAGE} +static struct upb_type_info type_info[] = { + {UPB_WIRE_TYPE_64BIT, get_DOUBLE}, + {UPB_WIRE_TYPE_32BIT, get_FLOAT}, + {UPB_WIRE_TYPE_VARINT, get_INT32}, + {UPB_WIRE_TYPE_VARINT, get_INT64}, + {UPB_WIRE_TYPE_VARINT, get_UINT32}, + {UPB_WIRE_TYPE_VARINT, get_UINT64}, + {UPB_WIRE_TYPE_VARINT, get_SINT32}, + {UPB_WIRE_TYPE_VARINT, get_SINT64}, + {UPB_WIRE_TYPE_32BIT, get_FIXED32}, + {UPB_WIRE_TYPE_64BIT, get_FIXED64}, + {UPB_WIRE_TYPE_32BIT, get_SFIXED32}, + {UPB_WIRE_TYPE_64BIT, get_SFIXED64}, + {UPB_WIRE_TYPE_VARINT, get_BOOL}, + {UPB_WIRE_TYPE_DELIMITED, get_BYTES}, + {UPB_WIRE_TYPE_DELIMITED, get_BYTES}, + {UPB_WIRE_TYPE_VARINT, get_ENUM}, + {UPB_WIRE_TYPE_DELIMITED, get_MESSAGE} }; -pbstream_status_t parse_tag(uint8_t **buf, struct pbstream_tag *tag) +upb_status_t parse_tag(uint8_t **buf, struct upb_tag *tag) { uint32_t tag_int; CHECK(get_v_uint32_t(buf, &tag_int)); - tag->wire_type = (pbstream_wire_type_t)(tag_int & 0x07); + tag->wire_type = (upb_wire_type_t)(tag_int & 0x07); tag->field_number = tag_int >> 3; - return PBSTREAM_STATUS_OK; + return UPB_STATUS_OK; } -pbstream_status_t parse_wire_value(uint8_t *buf, size_t *offset, - pbstream_wire_type_t wt, - union pbstream_wire_value *wv) +upb_status_t parse_wire_value(uint8_t *buf, size_t *offset, + upb_wire_type_t wt, + union upb_wire_value *wv) { #define READ(expr) CHECK(expr); *offset += (b-buf) uint8_t *b = buf; switch(wt) { - case PBSTREAM_WIRE_TYPE_VARINT: + case UPB_WIRE_TYPE_VARINT: READ(get_v_uint64_t(&b, &wv->varint)); break; - case PBSTREAM_WIRE_TYPE_64BIT: + case UPB_WIRE_TYPE_64BIT: READ(get_f_uint64_t(&b, &wv->_64bit)); break; - case PBSTREAM_WIRE_TYPE_32BIT: + case UPB_WIRE_TYPE_32BIT: READ(get_f_uint32_t(&b, &wv->_32bit)); break; - case PBSTREAM_WIRE_TYPE_DELIMITED: + case UPB_WIRE_TYPE_DELIMITED: wv->delimited.offset = *offset; READ(get_v_uint32_t(&b, &wv->delimited.len)); size_t new_offset = *offset + wv->delimited.len; - if (new_offset < *offset) return PBSTREAM_ERROR_OVERFLOW; + if (new_offset < *offset) return UPB_ERROR_OVERFLOW; *offset += new_offset; break; - case PBSTREAM_WIRE_TYPE_START_GROUP: - case PBSTREAM_WIRE_TYPE_END_GROUP: - return PBSTREAM_ERROR_GROUP; /* deprecated, no plans to support. */ + case UPB_WIRE_TYPE_START_GROUP: + case UPB_WIRE_TYPE_END_GROUP: + return UPB_ERROR_GROUP; /* deprecated, no plans to support. */ } - return PBSTREAM_STATUS_OK; + return UPB_STATUS_OK; } -pbstream_status_t skip_wire_value(uint8_t *buf, size_t *offset, - pbstream_wire_type_t wt) +upb_status_t skip_wire_value(uint8_t *buf, size_t *offset, + upb_wire_type_t wt) { uint8_t *b = buf; switch(wt) { - case PBSTREAM_WIRE_TYPE_VARINT: + case UPB_WIRE_TYPE_VARINT: READ(skip_v_uint64_t(&b)); break; - case PBSTREAM_WIRE_TYPE_64BIT: + case UPB_WIRE_TYPE_64BIT: READ(skip_f_uint64_t(&b)); break; - case PBSTREAM_WIRE_TYPE_32BIT: + case UPB_WIRE_TYPE_32BIT: READ(skip_f_uint32_t(&b)); break; - case PBSTREAM_WIRE_TYPE_DELIMITED: { + case UPB_WIRE_TYPE_DELIMITED: { /* Have to get (not skip) the length to skip the bytes. */ uint32_t len; READ(get_v_uint32_t(&b, &len)); size_t new_offset = *offset + len; - if (new_offset < *offset) return PBSTREAM_ERROR_OVERFLOW; + if (new_offset < *offset) return UPB_ERROR_OVERFLOW; *offset += new_offset; break; } - case PBSTREAM_WIRE_TYPE_START_GROUP: - case PBSTREAM_WIRE_TYPE_END_GROUP: - return PBSTREAM_ERROR_GROUP; /* deprecated, no plans to support. */ + case UPB_WIRE_TYPE_START_GROUP: + case UPB_WIRE_TYPE_END_GROUP: + return UPB_ERROR_GROUP; /* deprecated, no plans to support. */ } - return PBSTREAM_STATUS_OK; + return UPB_STATUS_OK; #undef READ } -struct pbstream_field *pbstream_find_field(struct pbstream_fieldset* fs, - pbstream_field_number_t num) -{ - /* TODO: the hashtable part. */ - return fs->array[num-1]; -} - /* Parses and processes the next value from buf. */ -pbstream_status_t pbstream_parse_field(struct pbstream_parse_state *s, - uint8_t *buf, - pbstream_field_number_t *fieldnum, - struct pbstream_tagged_value *val, - struct pbstream_tagged_wire_value *wv) +upb_status_t upb_parse_field(struct upb_parse_state *s, + uint8_t *buf, + upb_field_number_t *fieldnum, + struct upb_tagged_value *val, + struct upb_tagged_wire_value *wv) { /* Check for end-of-message at the current stack depth. */ if(unlikely(s->offset >= s->top->end_offset)) { /* If the end offset isn't an exact field boundary, the pb is corrupt. */ if(unlikely(s->offset != s->top->end_offset)) - return PBSTREAM_ERROR_BAD_SUBMESSAGE_END; + return UPB_ERROR_BAD_SUBMESSAGE_END; s->top--; - return PBSTREAM_STATUS_SUBMESSAGE_END; + return UPB_STATUS_SUBMESSAGE_END; } - struct pbstream_tag tag; + struct upb_tag tag; uint8_t *b = buf; CHECK(parse_tag(&b, &tag)); s->offset += (b-buf); - struct pbstream_field *fd = pbstream_find_field(s->top->fieldset, + struct upb_field *fd = upb_find_field(s->top->fieldset, tag.field_number); - pbstream_status_t unknown_value_status; + upb_status_t unknown_value_status; if(unlikely(!fd)) { - unknown_value_status = PBSTREAM_ERROR_UNKNOWN_VALUE; + unknown_value_status = UPB_ERROR_UNKNOWN_VALUE; goto unknown_value; } - struct pbstream_type_info *info = &type_info[fd->type]; + struct upb_type_info *info = &type_info[fd->type]; if(unlikely(tag.wire_type != info->expected_wire_type)) { - unknown_value_status = PBSTREAM_ERROR_MISMATCHED_TYPE; + unknown_value_status = UPB_ERROR_MISMATCHED_TYPE; goto unknown_value; } *fieldnum = tag.field_number; val->field = fd; CHECK(info->get(s, b, val)); - return PBSTREAM_STATUS_OK; + return UPB_STATUS_OK; unknown_value: wv->type = tag.wire_type; @@ -349,55 +341,20 @@ unknown_value: return unknown_value_status; } -void pbstream_init_parser( - struct pbstream_parse_state *state, - struct pbstream_fieldset *toplevel_fieldset) +void upb_init_parser( + struct upb_parse_state *state, + struct upb_fieldset *toplevel_fieldset) { state->offset = 0; state->top = state->stack; - state->limit = state->top + PBSTREAM_MAX_STACK; + state->limit = state->top + UPB_MAX_STACK; state->top->fieldset = toplevel_fieldset; state->top->end_offset = SIZE_MAX; } static int compare_fields(const void *f1, const void *f2) { - return ((struct pbstream_field*)f1)->field_number - - ((struct pbstream_field*)f2)->field_number; -} - -void pbstream_init_fieldset(struct pbstream_fieldset *fieldset, - struct pbstream_field *fields, - int num_fields) -{ - qsort(fields, num_fields, sizeof(*fields), compare_fields); - - /* Find the largest n for which at least half the fieldnums 8 && maybe_n/(i+1) >= 2) break; - n = maybe_n; - } - - fieldset->num_fields = num_fields; - fieldset->fields = malloc(sizeof(*fieldset->fields)*num_fields); - memcpy(fieldset->fields, fields, sizeof(*fields)*num_fields); - - fieldset->array_size = n; - fieldset->array = malloc(sizeof(*fieldset->array)*n); - memset(fieldset->array, 0, sizeof(*fieldset->array)*n); - - for (int i = 0; i < num_fields && fields[i].field_number <= n; i++) - fieldset->array[fields[i].field_number-1] = &fieldset->fields[i]; - - /* Until we support the hashtable part... */ - assert(n == fields[num_fields-1].field_number); + return ((struct upb_field*)f1)->field_number - + ((struct upb_field*)f2)->field_number; } -void pbstream_free_fieldset(struct pbstream_fieldset *fieldset) -{ - free(fieldset->fields); - free(fieldset->array); -} diff --git a/upb_parse.h b/upb_parse.h new file mode 100644 index 0000000000..75752a0370 --- /dev/null +++ b/upb_parse.h @@ -0,0 +1,137 @@ +/* + * upb - a minimalist implementation of protocol buffers. + * + * This file contains parsing routines; both stream-oriented and tree-oriented + * models are supported. + * + * Copyright (c) 2008 Joshua Haberman. See LICENSE for details. + */ + +#ifndef UPB_PARSE_H_ +#define UPB_PARSE_H_ + +#include +#include +#include "upb.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* A deserialized value as described in a .proto file. */ +struct upb_tagged_value { + struct upb_field *field; + union upb_value v; +}; + +/* A value as it is encoded on-the-wire, before it has been interpreted as + * any particular .proto type. */ +struct upb_tagged_wire_value { + upb_wire_type_t type; + union upb_wire_value v; +}; + +/* Definition of a single field in a message, for the purposes of the parser's + * fieldmap. Note that this does not include nearly all of the information + * that can be specified about a field in a .proto file. For example, we don't + * even know the field's name. We keep only the information necessary to parse + * the field. */ +struct upb_field { + upb_field_number_t field_number; + int32_t type; /* google_protobuf_FieldDescriptorProto_Type */ + struct upb_fieldset *fieldset; /* if type == MESSAGE */ +}; + +struct upb_parse_stack_frame { + struct upb_fieldset *fieldset; + size_t end_offset; /* unknown for the top frame, so we set to SIZE_MAX */ +}; + +/* The stream parser's state. */ +struct upb_parse_state { + size_t offset; + struct upb_parse_stack_frame stack[UPB_MAX_STACK]; + struct upb_parse_stack_frame *top, *limit; +}; + +/* Call this once before parsing to initialize the data structures. + * message_type can be NULL, in which case all fields will be reported as + * unknown. */ +void upb_init_parser(struct upb_parse_state *state, + struct upb_fieldset *toplevel_fieldset); + +/* Status as returned by upb_parse(). Status codes <0 are fatal errors + * that cannot be recovered. Status codes >0 are unusual but nonfatal events, + * which nonetheless must be handled differently since they do not return data + * in val. */ +typedef enum upb_status { + UPB_STATUS_OK = 0, + UPB_STATUS_SUBMESSAGE_END = 1, // No data is stored in val or wv. + + /** FATAL ERRORS: these indicate corruption, and cannot be recovered. */ + + // A varint did not terminate before hitting 64 bits. + UPB_ERROR_UNTERMINATED_VARINT = -1, + + // A submessage ended in the middle of data. + UPB_ERROR_BAD_SUBMESSAGE_END = -2, + + // Encountered a "group" on the wire (deprecated and unsupported). + UPB_ERROR_GROUP = -3, + + // Input was nested more than UPB_MAX_NESTING deep. + UPB_ERROR_STACK_OVERFLOW = -4, + + // The input data caused the pb's offset (a size_t) to overflow. + UPB_ERROR_OVERFLOW = -5, + + /** NONFATAL ERRORS: the input was invalid, but we can continue if desired. */ + + // A value was encountered that was not defined in the .proto file. The + // unknown value is stored in wv. + UPB_ERROR_UNKNOWN_VALUE = 2, + + // A field was encoded with the wrong wire type. The wire value is stored in + // wv. + UPB_ERROR_MISMATCHED_TYPE = 3, +} upb_status_t; +struct upb_parse_state; + +/* The main parsing function. Parses the next value from buf, storing the + * parsed value in val. If val is of type UPB_TYPE_MESSAGE, then a + * submessage was entered. + * + * IMPORTANT NOTE: for efficiency, the parsing routines do not do bounds checks, + * and may read as much as far as buf+10. So the caller must ensure that buf is + * not within 10 bytes of unmapped memory, or the program will segfault. Clients + * are encouraged to overallocate their buffers by ten bytes to compensate. */ +upb_status_t upb_parse_field(struct upb_parse_state *s, + uint8_t *buf, + upb_field_number_t *fieldnum, + struct upb_tagged_value *val, + struct upb_tagged_wire_value *wv); + +/* Low-level parsing functions. ***********************************************/ + +/* Parses a single tag from the character data starting at buf, and updates + * buf to point one past the bytes that were consumed. buf will be incremented + * by at most ten bytes. */ +upb_status_t parse_tag(uint8_t **buf, struct upb_tag *tag); + +/* Parses a wire value with the given type (which must have been obtained from + * a tag that was just parsed) and adds the number of bytes that were consumed + * to *offset. For delimited types, offset is advanced past the delimited + * data. */ +upb_status_t upb_parse_wire_value(uint8_t *buf, size_t *offset, + upb_wire_type_t wt, + union upb_wire_value *wv); + +/* Like the above, but discards the wire value instead of saving it. */ +upb_status_t skip_wire_value(uint8_t *buf, size_t *offset, + upb_wire_type_t wt); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* UPB_PARSE_H_ */