aboutsummaryrefslogtreecommitdiff
path: root/php/ext/google/protobuf/upb.c
diff options
context:
space:
mode:
Diffstat (limited to 'php/ext/google/protobuf/upb.c')
-rw-r--r--php/ext/google/protobuf/upb.c4868
1 files changed, 2088 insertions, 2780 deletions
diff --git a/php/ext/google/protobuf/upb.c b/php/ext/google/protobuf/upb.c
index 90c52aa8..2179e2c7 100644
--- a/php/ext/google/protobuf/upb.c
+++ b/php/ext/google/protobuf/upb.c
@@ -1,5 +1,23 @@
// Amalgamated source file
#include "upb.h"
+
+#if UINTPTR_MAX == 0xffffffff
+#define UPB_SIZE(size32, size64) size32
+#else
+#define UPB_SIZE(size32, size64) size64
+#endif
+
+#define UPB_FIELD_AT(msg, fieldtype, offset) \
+ *(fieldtype*)((const char*)(msg) + offset)
+
+#define UPB_READ_ONEOF(msg, fieldtype, offset, case_offset, case_val, default) \
+ UPB_FIELD_AT(msg, int, case_offset) == case_val \
+ ? UPB_FIELD_AT(msg, fieldtype, offset) \
+ : default
+
+#define UPB_WRITE_ONEOF(msg, fieldtype, offset, value, case_offset, case_val) \
+ UPB_FIELD_AT(msg, int, case_offset) = case_val; \
+ UPB_FIELD_AT(msg, fieldtype, offset) = value;
/* This file was generated by upbc (the upb compiler) from the input
* file:
*
@@ -11,64 +29,21 @@
#include <stddef.h>
-struct google_protobuf_FileDescriptorSet {
- upb_array* file;
-};
-
-static const upb_msglayout_msginit_v1 *const google_protobuf_FileDescriptorSet_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_FileDescriptorSet_submsgs[1] = {
&google_protobuf_FileDescriptorProto_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_FileDescriptorSet__fields[1] = {
- {1, offsetof(google_protobuf_FileDescriptorSet, file), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3},
+static const upb_msglayout_field google_protobuf_FileDescriptorSet__fields[1] = {
+ {1, UPB_SIZE(0, 0), 0, 0, 11, 3},
};
-const upb_msglayout_msginit_v1 google_protobuf_FileDescriptorSet_msginit = {
+const upb_msglayout google_protobuf_FileDescriptorSet_msginit = {
&google_protobuf_FileDescriptorSet_submsgs[0],
&google_protobuf_FileDescriptorSet__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_FileDescriptorSet), 1, 0, false, true
+ UPB_SIZE(4, 8), 1, false,
};
-google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_new(upb_env *env) {
- google_protobuf_FileDescriptorSet *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_FileDescriptorSet *msg = google_protobuf_FileDescriptorSet_new(env);
- if (upb_decode(buf, msg, &google_protobuf_FileDescriptorSet_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_FileDescriptorSet_serialize(google_protobuf_FileDescriptorSet *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_FileDescriptorSet_msginit, env, size);
-}
-const upb_array* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet *msg) {
- return msg->file;
-}
-void google_protobuf_FileDescriptorSet_set_file(google_protobuf_FileDescriptorSet *msg, upb_array* value) {
- msg->file = value;
-}
-struct google_protobuf_FileDescriptorProto {
- upb_stringview name;
- upb_stringview package;
- upb_stringview syntax;
- google_protobuf_FileOptions* options;
- google_protobuf_SourceCodeInfo* source_code_info;
- upb_array* dependency;
- upb_array* message_type;
- upb_array* enum_type;
- upb_array* service;
- upb_array* extension;
- upb_array* public_dependency;
- upb_array* weak_dependency;
-};
-
-static const upb_msglayout_msginit_v1 *const google_protobuf_FileDescriptorProto_submsgs[6] = {
+static const upb_msglayout *const google_protobuf_FileDescriptorProto_submsgs[6] = {
&google_protobuf_DescriptorProto_msginit,
&google_protobuf_EnumDescriptorProto_msginit,
&google_protobuf_FieldDescriptorProto_msginit,
@@ -77,131 +52,28 @@ static const upb_msglayout_msginit_v1 *const google_protobuf_FileDescriptorProto
&google_protobuf_SourceCodeInfo_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_FileDescriptorProto__fields[12] = {
- {1, offsetof(google_protobuf_FileDescriptorProto, name), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {2, offsetof(google_protobuf_FileDescriptorProto, package), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {3, offsetof(google_protobuf_FileDescriptorProto, dependency), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 3},
- {4, offsetof(google_protobuf_FileDescriptorProto, message_type), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3},
- {5, offsetof(google_protobuf_FileDescriptorProto, enum_type), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 1, 11, 3},
- {6, offsetof(google_protobuf_FileDescriptorProto, service), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 4, 11, 3},
- {7, offsetof(google_protobuf_FileDescriptorProto, extension), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 2, 11, 3},
- {8, offsetof(google_protobuf_FileDescriptorProto, options), 3, UPB_NOT_IN_ONEOF, 3, 11, 1},
- {9, offsetof(google_protobuf_FileDescriptorProto, source_code_info), 4, UPB_NOT_IN_ONEOF, 5, 11, 1},
- {10, offsetof(google_protobuf_FileDescriptorProto, public_dependency), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 3},
- {11, offsetof(google_protobuf_FileDescriptorProto, weak_dependency), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 3},
- {12, offsetof(google_protobuf_FileDescriptorProto, syntax), 2, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
+static const upb_msglayout_field google_protobuf_FileDescriptorProto__fields[12] = {
+ {1, UPB_SIZE(8, 16), 1, 0, 9, 1},
+ {2, UPB_SIZE(16, 32), 2, 0, 9, 1},
+ {3, UPB_SIZE(40, 80), 0, 0, 9, 3},
+ {4, UPB_SIZE(44, 88), 0, 0, 11, 3},
+ {5, UPB_SIZE(48, 96), 0, 1, 11, 3},
+ {6, UPB_SIZE(52, 104), 0, 4, 11, 3},
+ {7, UPB_SIZE(56, 112), 0, 2, 11, 3},
+ {8, UPB_SIZE(32, 64), 4, 3, 11, 1},
+ {9, UPB_SIZE(36, 72), 5, 5, 11, 1},
+ {10, UPB_SIZE(60, 120), 0, 0, 5, 3},
+ {11, UPB_SIZE(64, 128), 0, 0, 5, 3},
+ {12, UPB_SIZE(24, 48), 3, 0, 9, 1},
};
-const upb_msglayout_msginit_v1 google_protobuf_FileDescriptorProto_msginit = {
+const upb_msglayout google_protobuf_FileDescriptorProto_msginit = {
&google_protobuf_FileDescriptorProto_submsgs[0],
&google_protobuf_FileDescriptorProto__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_FileDescriptorProto), 12, 0, false, true
+ UPB_SIZE(72, 144), 12, false,
};
-google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_env *env) {
- google_protobuf_FileDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_FileDescriptorProto *msg = google_protobuf_FileDescriptorProto_new(env);
- if (upb_decode(buf, msg, &google_protobuf_FileDescriptorProto_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_FileDescriptorProto_serialize(google_protobuf_FileDescriptorProto *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_FileDescriptorProto_msginit, env, size);
-}
-upb_stringview google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto *msg) {
- return msg->name;
-}
-void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_stringview value) {
- msg->name = value;
-}
-upb_stringview google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto *msg) {
- return msg->package;
-}
-void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_stringview value) {
- msg->package = value;
-}
-const upb_array* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto *msg) {
- return msg->dependency;
-}
-void google_protobuf_FileDescriptorProto_set_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) {
- msg->dependency = value;
-}
-const upb_array* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto *msg) {
- return msg->message_type;
-}
-void google_protobuf_FileDescriptorProto_set_message_type(google_protobuf_FileDescriptorProto *msg, upb_array* value) {
- msg->message_type = value;
-}
-const upb_array* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto *msg) {
- return msg->enum_type;
-}
-void google_protobuf_FileDescriptorProto_set_enum_type(google_protobuf_FileDescriptorProto *msg, upb_array* value) {
- msg->enum_type = value;
-}
-const upb_array* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto *msg) {
- return msg->service;
-}
-void google_protobuf_FileDescriptorProto_set_service(google_protobuf_FileDescriptorProto *msg, upb_array* value) {
- msg->service = value;
-}
-const upb_array* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto *msg) {
- return msg->extension;
-}
-void google_protobuf_FileDescriptorProto_set_extension(google_protobuf_FileDescriptorProto *msg, upb_array* value) {
- msg->extension = value;
-}
-const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto *msg) {
- return msg->options;
-}
-void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) {
- msg->options = value;
-}
-const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto *msg) {
- return msg->source_code_info;
-}
-void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) {
- msg->source_code_info = value;
-}
-const upb_array* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto *msg) {
- return msg->public_dependency;
-}
-void google_protobuf_FileDescriptorProto_set_public_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) {
- msg->public_dependency = value;
-}
-const upb_array* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto *msg) {
- return msg->weak_dependency;
-}
-void google_protobuf_FileDescriptorProto_set_weak_dependency(google_protobuf_FileDescriptorProto *msg, upb_array* value) {
- msg->weak_dependency = value;
-}
-upb_stringview google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto *msg) {
- return msg->syntax;
-}
-void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_stringview value) {
- msg->syntax = value;
-}
-struct google_protobuf_DescriptorProto {
- upb_stringview name;
- google_protobuf_MessageOptions* options;
- upb_array* field;
- upb_array* nested_type;
- upb_array* enum_type;
- upb_array* extension_range;
- upb_array* extension;
- upb_array* oneof_decl;
- upb_array* reserved_range;
- upb_array* reserved_name;
-};
-
-static const upb_msglayout_msginit_v1 *const google_protobuf_DescriptorProto_submsgs[8] = {
+static const upb_msglayout *const google_protobuf_DescriptorProto_submsgs[8] = {
&google_protobuf_DescriptorProto_msginit,
&google_protobuf_DescriptorProto_ExtensionRange_msginit,
&google_protobuf_DescriptorProto_ReservedRange_msginit,
@@ -211,1694 +83,420 @@ static const upb_msglayout_msginit_v1 *const google_protobuf_DescriptorProto_sub
&google_protobuf_OneofDescriptorProto_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_DescriptorProto__fields[10] = {
- {1, offsetof(google_protobuf_DescriptorProto, name), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {2, offsetof(google_protobuf_DescriptorProto, field), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 4, 11, 3},
- {3, offsetof(google_protobuf_DescriptorProto, nested_type), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3},
- {4, offsetof(google_protobuf_DescriptorProto, enum_type), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 3, 11, 3},
- {5, offsetof(google_protobuf_DescriptorProto, extension_range), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 1, 11, 3},
- {6, offsetof(google_protobuf_DescriptorProto, extension), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 4, 11, 3},
- {7, offsetof(google_protobuf_DescriptorProto, options), 1, UPB_NOT_IN_ONEOF, 5, 11, 1},
- {8, offsetof(google_protobuf_DescriptorProto, oneof_decl), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 6, 11, 3},
- {9, offsetof(google_protobuf_DescriptorProto, reserved_range), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 2, 11, 3},
- {10, offsetof(google_protobuf_DescriptorProto, reserved_name), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 3},
+static const upb_msglayout_field google_protobuf_DescriptorProto__fields[10] = {
+ {1, UPB_SIZE(8, 16), 1, 0, 9, 1},
+ {2, UPB_SIZE(20, 40), 0, 4, 11, 3},
+ {3, UPB_SIZE(24, 48), 0, 0, 11, 3},
+ {4, UPB_SIZE(28, 56), 0, 3, 11, 3},
+ {5, UPB_SIZE(32, 64), 0, 1, 11, 3},
+ {6, UPB_SIZE(36, 72), 0, 4, 11, 3},
+ {7, UPB_SIZE(16, 32), 2, 5, 11, 1},
+ {8, UPB_SIZE(40, 80), 0, 6, 11, 3},
+ {9, UPB_SIZE(44, 88), 0, 2, 11, 3},
+ {10, UPB_SIZE(48, 96), 0, 0, 9, 3},
};
-const upb_msglayout_msginit_v1 google_protobuf_DescriptorProto_msginit = {
+const upb_msglayout google_protobuf_DescriptorProto_msginit = {
&google_protobuf_DescriptorProto_submsgs[0],
&google_protobuf_DescriptorProto__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_DescriptorProto), 10, 0, false, true
-};
-
-google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_env *env) {
- google_protobuf_DescriptorProto *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_DescriptorProto *msg = google_protobuf_DescriptorProto_new(env);
- if (upb_decode(buf, msg, &google_protobuf_DescriptorProto_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_DescriptorProto_serialize(google_protobuf_DescriptorProto *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_DescriptorProto_msginit, env, size);
-}
-upb_stringview google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto *msg) {
- return msg->name;
-}
-void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_stringview value) {
- msg->name = value;
-}
-const upb_array* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto *msg) {
- return msg->field;
-}
-void google_protobuf_DescriptorProto_set_field(google_protobuf_DescriptorProto *msg, upb_array* value) {
- msg->field = value;
-}
-const upb_array* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto *msg) {
- return msg->nested_type;
-}
-void google_protobuf_DescriptorProto_set_nested_type(google_protobuf_DescriptorProto *msg, upb_array* value) {
- msg->nested_type = value;
-}
-const upb_array* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto *msg) {
- return msg->enum_type;
-}
-void google_protobuf_DescriptorProto_set_enum_type(google_protobuf_DescriptorProto *msg, upb_array* value) {
- msg->enum_type = value;
-}
-const upb_array* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto *msg) {
- return msg->extension_range;
-}
-void google_protobuf_DescriptorProto_set_extension_range(google_protobuf_DescriptorProto *msg, upb_array* value) {
- msg->extension_range = value;
-}
-const upb_array* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto *msg) {
- return msg->extension;
-}
-void google_protobuf_DescriptorProto_set_extension(google_protobuf_DescriptorProto *msg, upb_array* value) {
- msg->extension = value;
-}
-const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto *msg) {
- return msg->options;
-}
-void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) {
- msg->options = value;
-}
-const upb_array* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto *msg) {
- return msg->oneof_decl;
-}
-void google_protobuf_DescriptorProto_set_oneof_decl(google_protobuf_DescriptorProto *msg, upb_array* value) {
- msg->oneof_decl = value;
-}
-const upb_array* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto *msg) {
- return msg->reserved_range;
-}
-void google_protobuf_DescriptorProto_set_reserved_range(google_protobuf_DescriptorProto *msg, upb_array* value) {
- msg->reserved_range = value;
-}
-const upb_array* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto *msg) {
- return msg->reserved_name;
-}
-void google_protobuf_DescriptorProto_set_reserved_name(google_protobuf_DescriptorProto *msg, upb_array* value) {
- msg->reserved_name = value;
-}
-struct google_protobuf_DescriptorProto_ExtensionRange {
- int32_t start;
- int32_t end;
- google_protobuf_ExtensionRangeOptions* options;
+ UPB_SIZE(56, 112), 10, false,
};
-static const upb_msglayout_msginit_v1 *const google_protobuf_DescriptorProto_ExtensionRange_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_DescriptorProto_ExtensionRange_submsgs[1] = {
&google_protobuf_ExtensionRangeOptions_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_DescriptorProto_ExtensionRange__fields[3] = {
- {1, offsetof(google_protobuf_DescriptorProto_ExtensionRange, start), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1},
- {2, offsetof(google_protobuf_DescriptorProto_ExtensionRange, end), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1},
- {3, offsetof(google_protobuf_DescriptorProto_ExtensionRange, options), 2, UPB_NOT_IN_ONEOF, 0, 11, 1},
+static const upb_msglayout_field google_protobuf_DescriptorProto_ExtensionRange__fields[3] = {
+ {1, UPB_SIZE(4, 4), 1, 0, 5, 1},
+ {2, UPB_SIZE(8, 8), 2, 0, 5, 1},
+ {3, UPB_SIZE(12, 16), 3, 0, 11, 1},
};
-const upb_msglayout_msginit_v1 google_protobuf_DescriptorProto_ExtensionRange_msginit = {
+const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit = {
&google_protobuf_DescriptorProto_ExtensionRange_submsgs[0],
&google_protobuf_DescriptorProto_ExtensionRange__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_DescriptorProto_ExtensionRange), 3, 0, false, true
+ UPB_SIZE(16, 24), 3, false,
};
-google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_env *env) {
- google_protobuf_DescriptorProto_ExtensionRange *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_DescriptorProto_ExtensionRange *msg = google_protobuf_DescriptorProto_ExtensionRange_new(env);
- if (upb_decode(buf, msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_DescriptorProto_ExtensionRange_serialize(google_protobuf_DescriptorProto_ExtensionRange *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, env, size);
-}
-int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) {
- return msg->start;
-}
-void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) {
- msg->start = value;
-}
-int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) {
- return msg->end;
-}
-void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) {
- msg->end = value;
-}
-const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange *msg) {
- return msg->options;
-}
-void google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange *msg, google_protobuf_ExtensionRangeOptions* value) {
- msg->options = value;
-}
-struct google_protobuf_DescriptorProto_ReservedRange {
- int32_t start;
- int32_t end;
-};
-
-static const upb_msglayout_fieldinit_v1 google_protobuf_DescriptorProto_ReservedRange__fields[2] = {
- {1, offsetof(google_protobuf_DescriptorProto_ReservedRange, start), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1},
- {2, offsetof(google_protobuf_DescriptorProto_ReservedRange, end), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1},
+static const upb_msglayout_field google_protobuf_DescriptorProto_ReservedRange__fields[2] = {
+ {1, UPB_SIZE(4, 4), 1, 0, 5, 1},
+ {2, UPB_SIZE(8, 8), 2, 0, 5, 1},
};
-const upb_msglayout_msginit_v1 google_protobuf_DescriptorProto_ReservedRange_msginit = {
+const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit = {
NULL,
&google_protobuf_DescriptorProto_ReservedRange__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_DescriptorProto_ReservedRange), 2, 0, false, true
-};
-
-google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_env *env) {
- google_protobuf_DescriptorProto_ReservedRange *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_DescriptorProto_ReservedRange *msg = google_protobuf_DescriptorProto_ReservedRange_new(env);
- if (upb_decode(buf, msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_DescriptorProto_ReservedRange_serialize(google_protobuf_DescriptorProto_ReservedRange *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, env, size);
-}
-int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange *msg) {
- return msg->start;
-}
-void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) {
- msg->start = value;
-}
-int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange *msg) {
- return msg->end;
-}
-void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) {
- msg->end = value;
-}
-struct google_protobuf_ExtensionRangeOptions {
- upb_array* uninterpreted_option;
+ UPB_SIZE(12, 12), 2, false,
};
-static const upb_msglayout_msginit_v1 *const google_protobuf_ExtensionRangeOptions_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_ExtensionRangeOptions_submsgs[1] = {
&google_protobuf_UninterpretedOption_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_ExtensionRangeOptions__fields[1] = {
- {999, offsetof(google_protobuf_ExtensionRangeOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3},
+static const upb_msglayout_field google_protobuf_ExtensionRangeOptions__fields[1] = {
+ {999, UPB_SIZE(0, 0), 0, 0, 11, 3},
};
-const upb_msglayout_msginit_v1 google_protobuf_ExtensionRangeOptions_msginit = {
+const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit = {
&google_protobuf_ExtensionRangeOptions_submsgs[0],
&google_protobuf_ExtensionRangeOptions__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_ExtensionRangeOptions), 1, 0, false, true
+ UPB_SIZE(4, 8), 1, false,
};
-google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_new(upb_env *env) {
- google_protobuf_ExtensionRangeOptions *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_ExtensionRangeOptions *msg = google_protobuf_ExtensionRangeOptions_new(env);
- if (upb_decode(buf, msg, &google_protobuf_ExtensionRangeOptions_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_ExtensionRangeOptions_serialize(google_protobuf_ExtensionRangeOptions *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, env, size);
-}
-const upb_array* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions *msg) {
- return msg->uninterpreted_option;
-}
-void google_protobuf_ExtensionRangeOptions_set_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, upb_array* value) {
- msg->uninterpreted_option = value;
-}
-struct google_protobuf_FieldDescriptorProto {
- google_protobuf_FieldDescriptorProto_Label label;
- google_protobuf_FieldDescriptorProto_Type type;
- int32_t number;
- int32_t oneof_index;
- upb_stringview name;
- upb_stringview extendee;
- upb_stringview type_name;
- upb_stringview default_value;
- upb_stringview json_name;
- google_protobuf_FieldOptions* options;
-};
-
-static const upb_msglayout_msginit_v1 *const google_protobuf_FieldDescriptorProto_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_FieldDescriptorProto_submsgs[1] = {
&google_protobuf_FieldOptions_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_FieldDescriptorProto__fields[10] = {
- {1, offsetof(google_protobuf_FieldDescriptorProto, name), 4, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {2, offsetof(google_protobuf_FieldDescriptorProto, extendee), 5, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {3, offsetof(google_protobuf_FieldDescriptorProto, number), 2, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1},
- {4, offsetof(google_protobuf_FieldDescriptorProto, label), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 14, 1},
- {5, offsetof(google_protobuf_FieldDescriptorProto, type), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 14, 1},
- {6, offsetof(google_protobuf_FieldDescriptorProto, type_name), 6, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {7, offsetof(google_protobuf_FieldDescriptorProto, default_value), 7, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {8, offsetof(google_protobuf_FieldDescriptorProto, options), 9, UPB_NOT_IN_ONEOF, 0, 11, 1},
- {9, offsetof(google_protobuf_FieldDescriptorProto, oneof_index), 3, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1},
- {10, offsetof(google_protobuf_FieldDescriptorProto, json_name), 8, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
+static const upb_msglayout_field google_protobuf_FieldDescriptorProto__fields[10] = {
+ {1, UPB_SIZE(32, 32), 5, 0, 9, 1},
+ {2, UPB_SIZE(40, 48), 6, 0, 9, 1},
+ {3, UPB_SIZE(24, 24), 3, 0, 5, 1},
+ {4, UPB_SIZE(8, 8), 1, 0, 14, 1},
+ {5, UPB_SIZE(16, 16), 2, 0, 14, 1},
+ {6, UPB_SIZE(48, 64), 7, 0, 9, 1},
+ {7, UPB_SIZE(56, 80), 8, 0, 9, 1},
+ {8, UPB_SIZE(72, 112), 10, 0, 11, 1},
+ {9, UPB_SIZE(28, 28), 4, 0, 5, 1},
+ {10, UPB_SIZE(64, 96), 9, 0, 9, 1},
};
-const upb_msglayout_msginit_v1 google_protobuf_FieldDescriptorProto_msginit = {
+const upb_msglayout google_protobuf_FieldDescriptorProto_msginit = {
&google_protobuf_FieldDescriptorProto_submsgs[0],
&google_protobuf_FieldDescriptorProto__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_FieldDescriptorProto), 10, 0, false, true
-};
-
-google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_env *env) {
- google_protobuf_FieldDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_FieldDescriptorProto *msg = google_protobuf_FieldDescriptorProto_new(env);
- if (upb_decode(buf, msg, &google_protobuf_FieldDescriptorProto_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_FieldDescriptorProto_serialize(google_protobuf_FieldDescriptorProto *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_FieldDescriptorProto_msginit, env, size);
-}
-upb_stringview google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto *msg) {
- return msg->name;
-}
-void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) {
- msg->name = value;
-}
-upb_stringview google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto *msg) {
- return msg->extendee;
-}
-void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) {
- msg->extendee = value;
-}
-int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto *msg) {
- return msg->number;
-}
-void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
- msg->number = value;
-}
-google_protobuf_FieldDescriptorProto_Label google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto *msg) {
- return msg->label;
-}
-void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Label value) {
- msg->label = value;
-}
-google_protobuf_FieldDescriptorProto_Type google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto *msg) {
- return msg->type;
-}
-void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Type value) {
- msg->type = value;
-}
-upb_stringview google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto *msg) {
- return msg->type_name;
-}
-void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) {
- msg->type_name = value;
-}
-upb_stringview google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto *msg) {
- return msg->default_value;
-}
-void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) {
- msg->default_value = value;
-}
-const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto *msg) {
- return msg->options;
-}
-void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) {
- msg->options = value;
-}
-int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto *msg) {
- return msg->oneof_index;
-}
-void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
- msg->oneof_index = value;
-}
-upb_stringview google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto *msg) {
- return msg->json_name;
-}
-void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_stringview value) {
- msg->json_name = value;
-}
-struct google_protobuf_OneofDescriptorProto {
- upb_stringview name;
- google_protobuf_OneofOptions* options;
+ UPB_SIZE(80, 128), 10, false,
};
-static const upb_msglayout_msginit_v1 *const google_protobuf_OneofDescriptorProto_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_OneofDescriptorProto_submsgs[1] = {
&google_protobuf_OneofOptions_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_OneofDescriptorProto__fields[2] = {
- {1, offsetof(google_protobuf_OneofDescriptorProto, name), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {2, offsetof(google_protobuf_OneofDescriptorProto, options), 1, UPB_NOT_IN_ONEOF, 0, 11, 1},
+static const upb_msglayout_field google_protobuf_OneofDescriptorProto__fields[2] = {
+ {1, UPB_SIZE(8, 16), 1, 0, 9, 1},
+ {2, UPB_SIZE(16, 32), 2, 0, 11, 1},
};
-const upb_msglayout_msginit_v1 google_protobuf_OneofDescriptorProto_msginit = {
+const upb_msglayout google_protobuf_OneofDescriptorProto_msginit = {
&google_protobuf_OneofDescriptorProto_submsgs[0],
&google_protobuf_OneofDescriptorProto__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_OneofDescriptorProto), 2, 0, false, true
+ UPB_SIZE(24, 48), 2, false,
};
-google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_env *env) {
- google_protobuf_OneofDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_OneofDescriptorProto *msg = google_protobuf_OneofDescriptorProto_new(env);
- if (upb_decode(buf, msg, &google_protobuf_OneofDescriptorProto_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_OneofDescriptorProto_serialize(google_protobuf_OneofDescriptorProto *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_OneofDescriptorProto_msginit, env, size);
-}
-upb_stringview google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto *msg) {
- return msg->name;
-}
-void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_stringview value) {
- msg->name = value;
-}
-const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto *msg) {
- return msg->options;
-}
-void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value) {
- msg->options = value;
-}
-struct google_protobuf_EnumDescriptorProto {
- upb_stringview name;
- google_protobuf_EnumOptions* options;
- upb_array* value;
- upb_array* reserved_range;
- upb_array* reserved_name;
-};
-
-static const upb_msglayout_msginit_v1 *const google_protobuf_EnumDescriptorProto_submsgs[3] = {
+static const upb_msglayout *const google_protobuf_EnumDescriptorProto_submsgs[3] = {
&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit,
&google_protobuf_EnumOptions_msginit,
&google_protobuf_EnumValueDescriptorProto_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_EnumDescriptorProto__fields[5] = {
- {1, offsetof(google_protobuf_EnumDescriptorProto, name), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {2, offsetof(google_protobuf_EnumDescriptorProto, value), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 2, 11, 3},
- {3, offsetof(google_protobuf_EnumDescriptorProto, options), 1, UPB_NOT_IN_ONEOF, 1, 11, 1},
- {4, offsetof(google_protobuf_EnumDescriptorProto, reserved_range), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3},
- {5, offsetof(google_protobuf_EnumDescriptorProto, reserved_name), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 3},
+static const upb_msglayout_field google_protobuf_EnumDescriptorProto__fields[5] = {
+ {1, UPB_SIZE(8, 16), 1, 0, 9, 1},
+ {2, UPB_SIZE(20, 40), 0, 2, 11, 3},
+ {3, UPB_SIZE(16, 32), 2, 1, 11, 1},
+ {4, UPB_SIZE(24, 48), 0, 0, 11, 3},
+ {5, UPB_SIZE(28, 56), 0, 0, 9, 3},
};
-const upb_msglayout_msginit_v1 google_protobuf_EnumDescriptorProto_msginit = {
+const upb_msglayout google_protobuf_EnumDescriptorProto_msginit = {
&google_protobuf_EnumDescriptorProto_submsgs[0],
&google_protobuf_EnumDescriptorProto__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_EnumDescriptorProto), 5, 0, false, true
+ UPB_SIZE(32, 64), 5, false,
};
-google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_env *env) {
- google_protobuf_EnumDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_EnumDescriptorProto *msg = google_protobuf_EnumDescriptorProto_new(env);
- if (upb_decode(buf, msg, &google_protobuf_EnumDescriptorProto_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_EnumDescriptorProto_serialize(google_protobuf_EnumDescriptorProto *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_EnumDescriptorProto_msginit, env, size);
-}
-upb_stringview google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto *msg) {
- return msg->name;
-}
-void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_stringview value) {
- msg->name = value;
-}
-const upb_array* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto *msg) {
- return msg->value;
-}
-void google_protobuf_EnumDescriptorProto_set_value(google_protobuf_EnumDescriptorProto *msg, upb_array* value) {
- msg->value = value;
-}
-const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto *msg) {
- return msg->options;
-}
-void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) {
- msg->options = value;
-}
-const upb_array* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto *msg) {
- return msg->reserved_range;
-}
-void google_protobuf_EnumDescriptorProto_set_reserved_range(google_protobuf_EnumDescriptorProto *msg, upb_array* value) {
- msg->reserved_range = value;
-}
-const upb_array* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto *msg) {
- return msg->reserved_name;
-}
-void google_protobuf_EnumDescriptorProto_set_reserved_name(google_protobuf_EnumDescriptorProto *msg, upb_array* value) {
- msg->reserved_name = value;
-}
-struct google_protobuf_EnumDescriptorProto_EnumReservedRange {
- int32_t start;
- int32_t end;
-};
-
-static const upb_msglayout_fieldinit_v1 google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[2] = {
- {1, offsetof(google_protobuf_EnumDescriptorProto_EnumReservedRange, start), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1},
- {2, offsetof(google_protobuf_EnumDescriptorProto_EnumReservedRange, end), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1},
+static const upb_msglayout_field google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[2] = {
+ {1, UPB_SIZE(4, 4), 1, 0, 5, 1},
+ {2, UPB_SIZE(8, 8), 2, 0, 5, 1},
};
-const upb_msglayout_msginit_v1 google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit = {
+const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit = {
NULL,
&google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_EnumDescriptorProto_EnumReservedRange), 2, 0, false, true
-};
-
-google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_env *env) {
- google_protobuf_EnumDescriptorProto_EnumReservedRange *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_EnumDescriptorProto_EnumReservedRange *msg = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(env);
- if (upb_decode(buf, msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, env, size);
-}
-int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) {
- return msg->start;
-}
-void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) {
- msg->start = value;
-}
-int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) {
- return msg->end;
-}
-void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) {
- msg->end = value;
-}
-struct google_protobuf_EnumValueDescriptorProto {
- int32_t number;
- upb_stringview name;
- google_protobuf_EnumValueOptions* options;
+ UPB_SIZE(12, 12), 2, false,
};
-static const upb_msglayout_msginit_v1 *const google_protobuf_EnumValueDescriptorProto_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_EnumValueDescriptorProto_submsgs[1] = {
&google_protobuf_EnumValueOptions_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_EnumValueDescriptorProto__fields[3] = {
- {1, offsetof(google_protobuf_EnumValueDescriptorProto, name), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {2, offsetof(google_protobuf_EnumValueDescriptorProto, number), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1},
- {3, offsetof(google_protobuf_EnumValueDescriptorProto, options), 2, UPB_NOT_IN_ONEOF, 0, 11, 1},
+static const upb_msglayout_field google_protobuf_EnumValueDescriptorProto__fields[3] = {
+ {1, UPB_SIZE(8, 16), 2, 0, 9, 1},
+ {2, UPB_SIZE(4, 4), 1, 0, 5, 1},
+ {3, UPB_SIZE(16, 32), 3, 0, 11, 1},
};
-const upb_msglayout_msginit_v1 google_protobuf_EnumValueDescriptorProto_msginit = {
+const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit = {
&google_protobuf_EnumValueDescriptorProto_submsgs[0],
&google_protobuf_EnumValueDescriptorProto__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_EnumValueDescriptorProto), 3, 0, false, true
-};
-
-google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_env *env) {
- google_protobuf_EnumValueDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_EnumValueDescriptorProto *msg = google_protobuf_EnumValueDescriptorProto_new(env);
- if (upb_decode(buf, msg, &google_protobuf_EnumValueDescriptorProto_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_EnumValueDescriptorProto_serialize(google_protobuf_EnumValueDescriptorProto *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, env, size);
-}
-upb_stringview google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto *msg) {
- return msg->name;
-}
-void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_stringview value) {
- msg->name = value;
-}
-int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto *msg) {
- return msg->number;
-}
-void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) {
- msg->number = value;
-}
-const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto *msg) {
- return msg->options;
-}
-void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) {
- msg->options = value;
-}
-struct google_protobuf_ServiceDescriptorProto {
- upb_stringview name;
- google_protobuf_ServiceOptions* options;
- upb_array* method;
+ UPB_SIZE(24, 48), 3, false,
};
-static const upb_msglayout_msginit_v1 *const google_protobuf_ServiceDescriptorProto_submsgs[2] = {
+static const upb_msglayout *const google_protobuf_ServiceDescriptorProto_submsgs[2] = {
&google_protobuf_MethodDescriptorProto_msginit,
&google_protobuf_ServiceOptions_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_ServiceDescriptorProto__fields[3] = {
- {1, offsetof(google_protobuf_ServiceDescriptorProto, name), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {2, offsetof(google_protobuf_ServiceDescriptorProto, method), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3},
- {3, offsetof(google_protobuf_ServiceDescriptorProto, options), 1, UPB_NOT_IN_ONEOF, 1, 11, 1},
+static const upb_msglayout_field google_protobuf_ServiceDescriptorProto__fields[3] = {
+ {1, UPB_SIZE(8, 16), 1, 0, 9, 1},
+ {2, UPB_SIZE(20, 40), 0, 0, 11, 3},
+ {3, UPB_SIZE(16, 32), 2, 1, 11, 1},
};
-const upb_msglayout_msginit_v1 google_protobuf_ServiceDescriptorProto_msginit = {
+const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit = {
&google_protobuf_ServiceDescriptorProto_submsgs[0],
&google_protobuf_ServiceDescriptorProto__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_ServiceDescriptorProto), 3, 0, false, true
-};
-
-google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_env *env) {
- google_protobuf_ServiceDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_ServiceDescriptorProto *msg = google_protobuf_ServiceDescriptorProto_new(env);
- if (upb_decode(buf, msg, &google_protobuf_ServiceDescriptorProto_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_ServiceDescriptorProto_serialize(google_protobuf_ServiceDescriptorProto *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_ServiceDescriptorProto_msginit, env, size);
-}
-upb_stringview google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto *msg) {
- return msg->name;
-}
-void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_stringview value) {
- msg->name = value;
-}
-const upb_array* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto *msg) {
- return msg->method;
-}
-void google_protobuf_ServiceDescriptorProto_set_method(google_protobuf_ServiceDescriptorProto *msg, upb_array* value) {
- msg->method = value;
-}
-const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto *msg) {
- return msg->options;
-}
-void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) {
- msg->options = value;
-}
-struct google_protobuf_MethodDescriptorProto {
- bool client_streaming;
- bool server_streaming;
- upb_stringview name;
- upb_stringview input_type;
- upb_stringview output_type;
- google_protobuf_MethodOptions* options;
+ UPB_SIZE(24, 48), 3, false,
};
-static const upb_msglayout_msginit_v1 *const google_protobuf_MethodDescriptorProto_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_MethodDescriptorProto_submsgs[1] = {
&google_protobuf_MethodOptions_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_MethodDescriptorProto__fields[6] = {
- {1, offsetof(google_protobuf_MethodDescriptorProto, name), 2, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {2, offsetof(google_protobuf_MethodDescriptorProto, input_type), 3, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {3, offsetof(google_protobuf_MethodDescriptorProto, output_type), 4, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {4, offsetof(google_protobuf_MethodDescriptorProto, options), 5, UPB_NOT_IN_ONEOF, 0, 11, 1},
- {5, offsetof(google_protobuf_MethodDescriptorProto, client_streaming), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {6, offsetof(google_protobuf_MethodDescriptorProto, server_streaming), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
+static const upb_msglayout_field google_protobuf_MethodDescriptorProto__fields[6] = {
+ {1, UPB_SIZE(8, 16), 3, 0, 9, 1},
+ {2, UPB_SIZE(16, 32), 4, 0, 9, 1},
+ {3, UPB_SIZE(24, 48), 5, 0, 9, 1},
+ {4, UPB_SIZE(32, 64), 6, 0, 11, 1},
+ {5, UPB_SIZE(1, 1), 1, 0, 8, 1},
+ {6, UPB_SIZE(2, 2), 2, 0, 8, 1},
};
-const upb_msglayout_msginit_v1 google_protobuf_MethodDescriptorProto_msginit = {
+const upb_msglayout google_protobuf_MethodDescriptorProto_msginit = {
&google_protobuf_MethodDescriptorProto_submsgs[0],
&google_protobuf_MethodDescriptorProto__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_MethodDescriptorProto), 6, 0, false, true
+ UPB_SIZE(40, 80), 6, false,
};
-google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_env *env) {
- google_protobuf_MethodDescriptorProto *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_MethodDescriptorProto *msg = google_protobuf_MethodDescriptorProto_new(env);
- if (upb_decode(buf, msg, &google_protobuf_MethodDescriptorProto_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_MethodDescriptorProto_serialize(google_protobuf_MethodDescriptorProto *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_MethodDescriptorProto_msginit, env, size);
-}
-upb_stringview google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto *msg) {
- return msg->name;
-}
-void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) {
- msg->name = value;
-}
-upb_stringview google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto *msg) {
- return msg->input_type;
-}
-void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) {
- msg->input_type = value;
-}
-upb_stringview google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto *msg) {
- return msg->output_type;
-}
-void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_stringview value) {
- msg->output_type = value;
-}
-const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto *msg) {
- return msg->options;
-}
-void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) {
- msg->options = value;
-}
-bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto *msg) {
- return msg->client_streaming;
-}
-void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) {
- msg->client_streaming = value;
-}
-bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto *msg) {
- return msg->server_streaming;
-}
-void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) {
- msg->server_streaming = value;
-}
-struct google_protobuf_FileOptions {
- google_protobuf_FileOptions_OptimizeMode optimize_for;
- bool java_multiple_files;
- bool cc_generic_services;
- bool java_generic_services;
- bool py_generic_services;
- bool java_generate_equals_and_hash;
- bool deprecated;
- bool java_string_check_utf8;
- bool cc_enable_arenas;
- bool php_generic_services;
- upb_stringview java_package;
- upb_stringview java_outer_classname;
- upb_stringview go_package;
- upb_stringview objc_class_prefix;
- upb_stringview csharp_namespace;
- upb_stringview swift_prefix;
- upb_stringview php_class_prefix;
- upb_stringview php_namespace;
- upb_array* uninterpreted_option;
-};
-
-static const upb_msglayout_msginit_v1 *const google_protobuf_FileOptions_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_FileOptions_submsgs[1] = {
&google_protobuf_UninterpretedOption_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_FileOptions__fields[19] = {
- {1, offsetof(google_protobuf_FileOptions, java_package), 10, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {8, offsetof(google_protobuf_FileOptions, java_outer_classname), 11, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {9, offsetof(google_protobuf_FileOptions, optimize_for), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 14, 1},
- {10, offsetof(google_protobuf_FileOptions, java_multiple_files), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {11, offsetof(google_protobuf_FileOptions, go_package), 12, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {16, offsetof(google_protobuf_FileOptions, cc_generic_services), 2, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {17, offsetof(google_protobuf_FileOptions, java_generic_services), 3, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {18, offsetof(google_protobuf_FileOptions, py_generic_services), 4, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {20, offsetof(google_protobuf_FileOptions, java_generate_equals_and_hash), 5, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {23, offsetof(google_protobuf_FileOptions, deprecated), 6, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {27, offsetof(google_protobuf_FileOptions, java_string_check_utf8), 7, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {31, offsetof(google_protobuf_FileOptions, cc_enable_arenas), 8, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {36, offsetof(google_protobuf_FileOptions, objc_class_prefix), 13, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {37, offsetof(google_protobuf_FileOptions, csharp_namespace), 14, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {39, offsetof(google_protobuf_FileOptions, swift_prefix), 15, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {40, offsetof(google_protobuf_FileOptions, php_class_prefix), 16, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {41, offsetof(google_protobuf_FileOptions, php_namespace), 17, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {42, offsetof(google_protobuf_FileOptions, php_generic_services), 9, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {999, offsetof(google_protobuf_FileOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3},
+static const upb_msglayout_field google_protobuf_FileOptions__fields[19] = {
+ {1, UPB_SIZE(32, 32), 11, 0, 9, 1},
+ {8, UPB_SIZE(40, 48), 12, 0, 9, 1},
+ {9, UPB_SIZE(8, 8), 1, 0, 14, 1},
+ {10, UPB_SIZE(16, 16), 2, 0, 8, 1},
+ {11, UPB_SIZE(48, 64), 13, 0, 9, 1},
+ {16, UPB_SIZE(17, 17), 3, 0, 8, 1},
+ {17, UPB_SIZE(18, 18), 4, 0, 8, 1},
+ {18, UPB_SIZE(19, 19), 5, 0, 8, 1},
+ {20, UPB_SIZE(20, 20), 6, 0, 8, 1},
+ {23, UPB_SIZE(21, 21), 7, 0, 8, 1},
+ {27, UPB_SIZE(22, 22), 8, 0, 8, 1},
+ {31, UPB_SIZE(23, 23), 9, 0, 8, 1},
+ {36, UPB_SIZE(56, 80), 14, 0, 9, 1},
+ {37, UPB_SIZE(64, 96), 15, 0, 9, 1},
+ {39, UPB_SIZE(72, 112), 16, 0, 9, 1},
+ {40, UPB_SIZE(80, 128), 17, 0, 9, 1},
+ {41, UPB_SIZE(88, 144), 18, 0, 9, 1},
+ {42, UPB_SIZE(24, 24), 10, 0, 8, 1},
+ {999, UPB_SIZE(96, 160), 0, 0, 11, 3},
};
-const upb_msglayout_msginit_v1 google_protobuf_FileOptions_msginit = {
+const upb_msglayout google_protobuf_FileOptions_msginit = {
&google_protobuf_FileOptions_submsgs[0],
&google_protobuf_FileOptions__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_FileOptions), 19, 0, false, true
+ UPB_SIZE(104, 176), 19, false,
};
-google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_env *env) {
- google_protobuf_FileOptions *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_FileOptions *google_protobuf_FileOptions_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_FileOptions *msg = google_protobuf_FileOptions_new(env);
- if (upb_decode(buf, msg, &google_protobuf_FileOptions_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_FileOptions_serialize(google_protobuf_FileOptions *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_FileOptions_msginit, env, size);
-}
-upb_stringview google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions *msg) {
- return msg->java_package;
-}
-void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_stringview value) {
- msg->java_package = value;
-}
-upb_stringview google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions *msg) {
- return msg->java_outer_classname;
-}
-void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_stringview value) {
- msg->java_outer_classname = value;
-}
-google_protobuf_FileOptions_OptimizeMode google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions *msg) {
- return msg->optimize_for;
-}
-void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, google_protobuf_FileOptions_OptimizeMode value) {
- msg->optimize_for = value;
-}
-bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions *msg) {
- return msg->java_multiple_files;
-}
-void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value) {
- msg->java_multiple_files = value;
-}
-upb_stringview google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions *msg) {
- return msg->go_package;
-}
-void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_stringview value) {
- msg->go_package = value;
-}
-bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions *msg) {
- return msg->cc_generic_services;
-}
-void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) {
- msg->cc_generic_services = value;
-}
-bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions *msg) {
- return msg->java_generic_services;
-}
-void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value) {
- msg->java_generic_services = value;
-}
-bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions *msg) {
- return msg->py_generic_services;
-}
-void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value) {
- msg->py_generic_services = value;
-}
-bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) {
- return msg->java_generate_equals_and_hash;
-}
-void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value) {
- msg->java_generate_equals_and_hash = value;
-}
-bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions *msg) {
- return msg->deprecated;
-}
-void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value) {
- msg->deprecated = value;
-}
-bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions *msg) {
- return msg->java_string_check_utf8;
-}
-void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value) {
- msg->java_string_check_utf8 = value;
-}
-bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions *msg) {
- return msg->cc_enable_arenas;
-}
-void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value) {
- msg->cc_enable_arenas = value;
-}
-upb_stringview google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions *msg) {
- return msg->objc_class_prefix;
-}
-void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_stringview value) {
- msg->objc_class_prefix = value;
-}
-upb_stringview google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions *msg) {
- return msg->csharp_namespace;
-}
-void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_stringview value) {
- msg->csharp_namespace = value;
-}
-upb_stringview google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions *msg) {
- return msg->swift_prefix;
-}
-void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_stringview value) {
- msg->swift_prefix = value;
-}
-upb_stringview google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions *msg) {
- return msg->php_class_prefix;
-}
-void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_stringview value) {
- msg->php_class_prefix = value;
-}
-upb_stringview google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions *msg) {
- return msg->php_namespace;
-}
-void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_stringview value) {
- msg->php_namespace = value;
-}
-bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions *msg) {
- return msg->php_generic_services;
-}
-void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) {
- msg->php_generic_services = value;
-}
-const upb_array* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions *msg) {
- return msg->uninterpreted_option;
-}
-void google_protobuf_FileOptions_set_uninterpreted_option(google_protobuf_FileOptions *msg, upb_array* value) {
- msg->uninterpreted_option = value;
-}
-struct google_protobuf_MessageOptions {
- bool message_set_wire_format;
- bool no_standard_descriptor_accessor;
- bool deprecated;
- bool map_entry;
- upb_array* uninterpreted_option;
-};
-
-static const upb_msglayout_msginit_v1 *const google_protobuf_MessageOptions_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_MessageOptions_submsgs[1] = {
&google_protobuf_UninterpretedOption_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_MessageOptions__fields[5] = {
- {1, offsetof(google_protobuf_MessageOptions, message_set_wire_format), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {2, offsetof(google_protobuf_MessageOptions, no_standard_descriptor_accessor), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {3, offsetof(google_protobuf_MessageOptions, deprecated), 2, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {7, offsetof(google_protobuf_MessageOptions, map_entry), 3, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {999, offsetof(google_protobuf_MessageOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3},
+static const upb_msglayout_field google_protobuf_MessageOptions__fields[5] = {
+ {1, UPB_SIZE(1, 1), 1, 0, 8, 1},
+ {2, UPB_SIZE(2, 2), 2, 0, 8, 1},
+ {3, UPB_SIZE(3, 3), 3, 0, 8, 1},
+ {7, UPB_SIZE(4, 4), 4, 0, 8, 1},
+ {999, UPB_SIZE(8, 8), 0, 0, 11, 3},
};
-const upb_msglayout_msginit_v1 google_protobuf_MessageOptions_msginit = {
+const upb_msglayout google_protobuf_MessageOptions_msginit = {
&google_protobuf_MessageOptions_submsgs[0],
&google_protobuf_MessageOptions__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_MessageOptions), 5, 0, false, true
+ UPB_SIZE(12, 16), 5, false,
};
-google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_env *env) {
- google_protobuf_MessageOptions *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_MessageOptions *google_protobuf_MessageOptions_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_MessageOptions *msg = google_protobuf_MessageOptions_new(env);
- if (upb_decode(buf, msg, &google_protobuf_MessageOptions_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_MessageOptions_serialize(google_protobuf_MessageOptions *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_MessageOptions_msginit, env, size);
-}
-bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions *msg) {
- return msg->message_set_wire_format;
-}
-void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) {
- msg->message_set_wire_format = value;
-}
-bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) {
- return msg->no_standard_descriptor_accessor;
-}
-void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions *msg, bool value) {
- msg->no_standard_descriptor_accessor = value;
-}
-bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions *msg) {
- return msg->deprecated;
-}
-void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions *msg, bool value) {
- msg->deprecated = value;
-}
-bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions *msg) {
- return msg->map_entry;
-}
-void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions *msg, bool value) {
- msg->map_entry = value;
-}
-const upb_array* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions *msg) {
- return msg->uninterpreted_option;
-}
-void google_protobuf_MessageOptions_set_uninterpreted_option(google_protobuf_MessageOptions *msg, upb_array* value) {
- msg->uninterpreted_option = value;
-}
-struct google_protobuf_FieldOptions {
- google_protobuf_FieldOptions_CType ctype;
- google_protobuf_FieldOptions_JSType jstype;
- bool packed;
- bool deprecated;
- bool lazy;
- bool weak;
- upb_array* uninterpreted_option;
-};
-
-static const upb_msglayout_msginit_v1 *const google_protobuf_FieldOptions_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_FieldOptions_submsgs[1] = {
&google_protobuf_UninterpretedOption_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_FieldOptions__fields[7] = {
- {1, offsetof(google_protobuf_FieldOptions, ctype), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 14, 1},
- {2, offsetof(google_protobuf_FieldOptions, packed), 2, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {3, offsetof(google_protobuf_FieldOptions, deprecated), 3, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {5, offsetof(google_protobuf_FieldOptions, lazy), 4, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {6, offsetof(google_protobuf_FieldOptions, jstype), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 14, 1},
- {10, offsetof(google_protobuf_FieldOptions, weak), 5, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {999, offsetof(google_protobuf_FieldOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3},
+static const upb_msglayout_field google_protobuf_FieldOptions__fields[7] = {
+ {1, UPB_SIZE(8, 8), 1, 0, 14, 1},
+ {2, UPB_SIZE(24, 24), 3, 0, 8, 1},
+ {3, UPB_SIZE(25, 25), 4, 0, 8, 1},
+ {5, UPB_SIZE(26, 26), 5, 0, 8, 1},
+ {6, UPB_SIZE(16, 16), 2, 0, 14, 1},
+ {10, UPB_SIZE(27, 27), 6, 0, 8, 1},
+ {999, UPB_SIZE(28, 32), 0, 0, 11, 3},
};
-const upb_msglayout_msginit_v1 google_protobuf_FieldOptions_msginit = {
+const upb_msglayout google_protobuf_FieldOptions_msginit = {
&google_protobuf_FieldOptions_submsgs[0],
&google_protobuf_FieldOptions__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_FieldOptions), 7, 0, false, true
-};
-
-google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_env *env) {
- google_protobuf_FieldOptions *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_FieldOptions *google_protobuf_FieldOptions_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_FieldOptions *msg = google_protobuf_FieldOptions_new(env);
- if (upb_decode(buf, msg, &google_protobuf_FieldOptions_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_FieldOptions_serialize(google_protobuf_FieldOptions *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_FieldOptions_msginit, env, size);
-}
-google_protobuf_FieldOptions_CType google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions *msg) {
- return msg->ctype;
-}
-void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_CType value) {
- msg->ctype = value;
-}
-bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions *msg) {
- return msg->packed;
-}
-void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value) {
- msg->packed = value;
-}
-bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions *msg) {
- return msg->deprecated;
-}
-void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value) {
- msg->deprecated = value;
-}
-bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions *msg) {
- return msg->lazy;
-}
-void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value) {
- msg->lazy = value;
-}
-google_protobuf_FieldOptions_JSType google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions *msg) {
- return msg->jstype;
-}
-void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_JSType value) {
- msg->jstype = value;
-}
-bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions *msg) {
- return msg->weak;
-}
-void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value) {
- msg->weak = value;
-}
-const upb_array* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions *msg) {
- return msg->uninterpreted_option;
-}
-void google_protobuf_FieldOptions_set_uninterpreted_option(google_protobuf_FieldOptions *msg, upb_array* value) {
- msg->uninterpreted_option = value;
-}
-struct google_protobuf_OneofOptions {
- upb_array* uninterpreted_option;
+ UPB_SIZE(32, 40), 7, false,
};
-static const upb_msglayout_msginit_v1 *const google_protobuf_OneofOptions_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_OneofOptions_submsgs[1] = {
&google_protobuf_UninterpretedOption_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_OneofOptions__fields[1] = {
- {999, offsetof(google_protobuf_OneofOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3},
+static const upb_msglayout_field google_protobuf_OneofOptions__fields[1] = {
+ {999, UPB_SIZE(0, 0), 0, 0, 11, 3},
};
-const upb_msglayout_msginit_v1 google_protobuf_OneofOptions_msginit = {
+const upb_msglayout google_protobuf_OneofOptions_msginit = {
&google_protobuf_OneofOptions_submsgs[0],
&google_protobuf_OneofOptions__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_OneofOptions), 1, 0, false, true
+ UPB_SIZE(4, 8), 1, false,
};
-google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_env *env) {
- google_protobuf_OneofOptions *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_OneofOptions *google_protobuf_OneofOptions_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_OneofOptions *msg = google_protobuf_OneofOptions_new(env);
- if (upb_decode(buf, msg, &google_protobuf_OneofOptions_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_OneofOptions_serialize(google_protobuf_OneofOptions *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_OneofOptions_msginit, env, size);
-}
-const upb_array* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions *msg) {
- return msg->uninterpreted_option;
-}
-void google_protobuf_OneofOptions_set_uninterpreted_option(google_protobuf_OneofOptions *msg, upb_array* value) {
- msg->uninterpreted_option = value;
-}
-struct google_protobuf_EnumOptions {
- bool allow_alias;
- bool deprecated;
- upb_array* uninterpreted_option;
-};
-
-static const upb_msglayout_msginit_v1 *const google_protobuf_EnumOptions_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_EnumOptions_submsgs[1] = {
&google_protobuf_UninterpretedOption_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_EnumOptions__fields[3] = {
- {2, offsetof(google_protobuf_EnumOptions, allow_alias), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {3, offsetof(google_protobuf_EnumOptions, deprecated), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {999, offsetof(google_protobuf_EnumOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3},
+static const upb_msglayout_field google_protobuf_EnumOptions__fields[3] = {
+ {2, UPB_SIZE(1, 1), 1, 0, 8, 1},
+ {3, UPB_SIZE(2, 2), 2, 0, 8, 1},
+ {999, UPB_SIZE(4, 8), 0, 0, 11, 3},
};
-const upb_msglayout_msginit_v1 google_protobuf_EnumOptions_msginit = {
+const upb_msglayout google_protobuf_EnumOptions_msginit = {
&google_protobuf_EnumOptions_submsgs[0],
&google_protobuf_EnumOptions__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_EnumOptions), 3, 0, false, true
-};
-
-google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_env *env) {
- google_protobuf_EnumOptions *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_EnumOptions *google_protobuf_EnumOptions_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_EnumOptions *msg = google_protobuf_EnumOptions_new(env);
- if (upb_decode(buf, msg, &google_protobuf_EnumOptions_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_EnumOptions_serialize(google_protobuf_EnumOptions *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_EnumOptions_msginit, env, size);
-}
-bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions *msg) {
- return msg->allow_alias;
-}
-void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) {
- msg->allow_alias = value;
-}
-bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions *msg) {
- return msg->deprecated;
-}
-void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions *msg, bool value) {
- msg->deprecated = value;
-}
-const upb_array* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions *msg) {
- return msg->uninterpreted_option;
-}
-void google_protobuf_EnumOptions_set_uninterpreted_option(google_protobuf_EnumOptions *msg, upb_array* value) {
- msg->uninterpreted_option = value;
-}
-struct google_protobuf_EnumValueOptions {
- bool deprecated;
- upb_array* uninterpreted_option;
+ UPB_SIZE(8, 16), 3, false,
};
-static const upb_msglayout_msginit_v1 *const google_protobuf_EnumValueOptions_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_EnumValueOptions_submsgs[1] = {
&google_protobuf_UninterpretedOption_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_EnumValueOptions__fields[2] = {
- {1, offsetof(google_protobuf_EnumValueOptions, deprecated), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {999, offsetof(google_protobuf_EnumValueOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3},
+static const upb_msglayout_field google_protobuf_EnumValueOptions__fields[2] = {
+ {1, UPB_SIZE(1, 1), 1, 0, 8, 1},
+ {999, UPB_SIZE(4, 8), 0, 0, 11, 3},
};
-const upb_msglayout_msginit_v1 google_protobuf_EnumValueOptions_msginit = {
+const upb_msglayout google_protobuf_EnumValueOptions_msginit = {
&google_protobuf_EnumValueOptions_submsgs[0],
&google_protobuf_EnumValueOptions__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_EnumValueOptions), 2, 0, false, true
+ UPB_SIZE(8, 16), 2, false,
};
-google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_env *env) {
- google_protobuf_EnumValueOptions *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_EnumValueOptions *msg = google_protobuf_EnumValueOptions_new(env);
- if (upb_decode(buf, msg, &google_protobuf_EnumValueOptions_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_EnumValueOptions_serialize(google_protobuf_EnumValueOptions *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_EnumValueOptions_msginit, env, size);
-}
-bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions *msg) {
- return msg->deprecated;
-}
-void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) {
- msg->deprecated = value;
-}
-const upb_array* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions *msg) {
- return msg->uninterpreted_option;
-}
-void google_protobuf_EnumValueOptions_set_uninterpreted_option(google_protobuf_EnumValueOptions *msg, upb_array* value) {
- msg->uninterpreted_option = value;
-}
-struct google_protobuf_ServiceOptions {
- bool deprecated;
- upb_array* uninterpreted_option;
-};
-
-static const upb_msglayout_msginit_v1 *const google_protobuf_ServiceOptions_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_ServiceOptions_submsgs[1] = {
&google_protobuf_UninterpretedOption_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_ServiceOptions__fields[2] = {
- {33, offsetof(google_protobuf_ServiceOptions, deprecated), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {999, offsetof(google_protobuf_ServiceOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3},
+static const upb_msglayout_field google_protobuf_ServiceOptions__fields[2] = {
+ {33, UPB_SIZE(1, 1), 1, 0, 8, 1},
+ {999, UPB_SIZE(4, 8), 0, 0, 11, 3},
};
-const upb_msglayout_msginit_v1 google_protobuf_ServiceOptions_msginit = {
+const upb_msglayout google_protobuf_ServiceOptions_msginit = {
&google_protobuf_ServiceOptions_submsgs[0],
&google_protobuf_ServiceOptions__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_ServiceOptions), 2, 0, false, true
+ UPB_SIZE(8, 16), 2, false,
};
-google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_env *env) {
- google_protobuf_ServiceOptions *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_ServiceOptions *msg = google_protobuf_ServiceOptions_new(env);
- if (upb_decode(buf, msg, &google_protobuf_ServiceOptions_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_ServiceOptions_serialize(google_protobuf_ServiceOptions *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_ServiceOptions_msginit, env, size);
-}
-bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions *msg) {
- return msg->deprecated;
-}
-void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) {
- msg->deprecated = value;
-}
-const upb_array* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions *msg) {
- return msg->uninterpreted_option;
-}
-void google_protobuf_ServiceOptions_set_uninterpreted_option(google_protobuf_ServiceOptions *msg, upb_array* value) {
- msg->uninterpreted_option = value;
-}
-struct google_protobuf_MethodOptions {
- google_protobuf_MethodOptions_IdempotencyLevel idempotency_level;
- bool deprecated;
- upb_array* uninterpreted_option;
-};
-
-static const upb_msglayout_msginit_v1 *const google_protobuf_MethodOptions_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_MethodOptions_submsgs[1] = {
&google_protobuf_UninterpretedOption_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_MethodOptions__fields[3] = {
- {33, offsetof(google_protobuf_MethodOptions, deprecated), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 1},
- {34, offsetof(google_protobuf_MethodOptions, idempotency_level), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 14, 1},
- {999, offsetof(google_protobuf_MethodOptions, uninterpreted_option), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3},
+static const upb_msglayout_field google_protobuf_MethodOptions__fields[3] = {
+ {33, UPB_SIZE(16, 16), 2, 0, 8, 1},
+ {34, UPB_SIZE(8, 8), 1, 0, 14, 1},
+ {999, UPB_SIZE(20, 24), 0, 0, 11, 3},
};
-const upb_msglayout_msginit_v1 google_protobuf_MethodOptions_msginit = {
+const upb_msglayout google_protobuf_MethodOptions_msginit = {
&google_protobuf_MethodOptions_submsgs[0],
&google_protobuf_MethodOptions__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_MethodOptions), 3, 0, false, true
-};
-
-google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_env *env) {
- google_protobuf_MethodOptions *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_MethodOptions *google_protobuf_MethodOptions_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_MethodOptions *msg = google_protobuf_MethodOptions_new(env);
- if (upb_decode(buf, msg, &google_protobuf_MethodOptions_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_MethodOptions_serialize(google_protobuf_MethodOptions *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_MethodOptions_msginit, env, size);
-}
-bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions *msg) {
- return msg->deprecated;
-}
-void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) {
- msg->deprecated = value;
-}
-google_protobuf_MethodOptions_IdempotencyLevel google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions *msg) {
- return msg->idempotency_level;
-}
-void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions *msg, google_protobuf_MethodOptions_IdempotencyLevel value) {
- msg->idempotency_level = value;
-}
-const upb_array* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions *msg) {
- return msg->uninterpreted_option;
-}
-void google_protobuf_MethodOptions_set_uninterpreted_option(google_protobuf_MethodOptions *msg, upb_array* value) {
- msg->uninterpreted_option = value;
-}
-struct google_protobuf_UninterpretedOption {
- uint64_t positive_int_value;
- int64_t negative_int_value;
- double double_value;
- upb_stringview identifier_value;
- upb_stringview string_value;
- upb_stringview aggregate_value;
- upb_array* name;
+ UPB_SIZE(24, 32), 3, false,
};
-static const upb_msglayout_msginit_v1 *const google_protobuf_UninterpretedOption_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_UninterpretedOption_submsgs[1] = {
&google_protobuf_UninterpretedOption_NamePart_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_UninterpretedOption__fields[7] = {
- {2, offsetof(google_protobuf_UninterpretedOption, name), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3},
- {3, offsetof(google_protobuf_UninterpretedOption, identifier_value), 3, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {4, offsetof(google_protobuf_UninterpretedOption, positive_int_value), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 4, 1},
- {5, offsetof(google_protobuf_UninterpretedOption, negative_int_value), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 3, 1},
- {6, offsetof(google_protobuf_UninterpretedOption, double_value), 2, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 1, 1},
- {7, offsetof(google_protobuf_UninterpretedOption, string_value), 4, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 12, 1},
- {8, offsetof(google_protobuf_UninterpretedOption, aggregate_value), 5, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
+static const upb_msglayout_field google_protobuf_UninterpretedOption__fields[7] = {
+ {2, UPB_SIZE(56, 80), 0, 0, 11, 3},
+ {3, UPB_SIZE(32, 32), 4, 0, 9, 1},
+ {4, UPB_SIZE(8, 8), 1, 0, 4, 1},
+ {5, UPB_SIZE(16, 16), 2, 0, 3, 1},
+ {6, UPB_SIZE(24, 24), 3, 0, 1, 1},
+ {7, UPB_SIZE(40, 48), 5, 0, 12, 1},
+ {8, UPB_SIZE(48, 64), 6, 0, 9, 1},
};
-const upb_msglayout_msginit_v1 google_protobuf_UninterpretedOption_msginit = {
+const upb_msglayout google_protobuf_UninterpretedOption_msginit = {
&google_protobuf_UninterpretedOption_submsgs[0],
&google_protobuf_UninterpretedOption__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_UninterpretedOption), 7, 0, false, true
+ UPB_SIZE(64, 96), 7, false,
};
-google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_env *env) {
- google_protobuf_UninterpretedOption *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_UninterpretedOption *msg = google_protobuf_UninterpretedOption_new(env);
- if (upb_decode(buf, msg, &google_protobuf_UninterpretedOption_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_UninterpretedOption_serialize(google_protobuf_UninterpretedOption *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_UninterpretedOption_msginit, env, size);
-}
-const upb_array* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption *msg) {
- return msg->name;
-}
-void google_protobuf_UninterpretedOption_set_name(google_protobuf_UninterpretedOption *msg, upb_array* value) {
- msg->name = value;
-}
-upb_stringview google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption *msg) {
- return msg->identifier_value;
-}
-void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) {
- msg->identifier_value = value;
-}
-uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption *msg) {
- return msg->positive_int_value;
-}
-void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) {
- msg->positive_int_value = value;
-}
-int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption *msg) {
- return msg->negative_int_value;
-}
-void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) {
- msg->negative_int_value = value;
-}
-double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption *msg) {
- return msg->double_value;
-}
-void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) {
- msg->double_value = value;
-}
-upb_stringview google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption *msg) {
- return msg->string_value;
-}
-void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) {
- msg->string_value = value;
-}
-upb_stringview google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption *msg) {
- return msg->aggregate_value;
-}
-void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_stringview value) {
- msg->aggregate_value = value;
-}
-struct google_protobuf_UninterpretedOption_NamePart {
- bool is_extension;
- upb_stringview name_part;
-};
-
-static const upb_msglayout_fieldinit_v1 google_protobuf_UninterpretedOption_NamePart__fields[2] = {
- {1, offsetof(google_protobuf_UninterpretedOption_NamePart, name_part), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 2},
- {2, offsetof(google_protobuf_UninterpretedOption_NamePart, is_extension), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 8, 2},
+static const upb_msglayout_field google_protobuf_UninterpretedOption_NamePart__fields[2] = {
+ {1, UPB_SIZE(8, 16), 2, 0, 9, 2},
+ {2, UPB_SIZE(1, 1), 1, 0, 8, 2},
};
-const upb_msglayout_msginit_v1 google_protobuf_UninterpretedOption_NamePart_msginit = {
+const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit = {
NULL,
&google_protobuf_UninterpretedOption_NamePart__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_UninterpretedOption_NamePart), 2, 0, false, true
-};
-
-google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_new(upb_env *env) {
- google_protobuf_UninterpretedOption_NamePart *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_UninterpretedOption_NamePart *msg = google_protobuf_UninterpretedOption_NamePart_new(env);
- if (upb_decode(buf, msg, &google_protobuf_UninterpretedOption_NamePart_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_UninterpretedOption_NamePart_serialize(google_protobuf_UninterpretedOption_NamePart *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, env, size);
-}
-upb_stringview google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) {
- return msg->name_part;
-}
-void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_stringview value) {
- msg->name_part = value;
-}
-bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) {
- return msg->is_extension;
-}
-void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value) {
- msg->is_extension = value;
-}
-struct google_protobuf_SourceCodeInfo {
- upb_array* location;
+ UPB_SIZE(16, 32), 2, false,
};
-static const upb_msglayout_msginit_v1 *const google_protobuf_SourceCodeInfo_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_SourceCodeInfo_submsgs[1] = {
&google_protobuf_SourceCodeInfo_Location_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_SourceCodeInfo__fields[1] = {
- {1, offsetof(google_protobuf_SourceCodeInfo, location), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3},
+static const upb_msglayout_field google_protobuf_SourceCodeInfo__fields[1] = {
+ {1, UPB_SIZE(0, 0), 0, 0, 11, 3},
};
-const upb_msglayout_msginit_v1 google_protobuf_SourceCodeInfo_msginit = {
+const upb_msglayout google_protobuf_SourceCodeInfo_msginit = {
&google_protobuf_SourceCodeInfo_submsgs[0],
&google_protobuf_SourceCodeInfo__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_SourceCodeInfo), 1, 0, false, true
-};
-
-google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_env *env) {
- google_protobuf_SourceCodeInfo *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_SourceCodeInfo *msg = google_protobuf_SourceCodeInfo_new(env);
- if (upb_decode(buf, msg, &google_protobuf_SourceCodeInfo_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_SourceCodeInfo_serialize(google_protobuf_SourceCodeInfo *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_SourceCodeInfo_msginit, env, size);
-}
-const upb_array* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo *msg) {
- return msg->location;
-}
-void google_protobuf_SourceCodeInfo_set_location(google_protobuf_SourceCodeInfo *msg, upb_array* value) {
- msg->location = value;
-}
-struct google_protobuf_SourceCodeInfo_Location {
- upb_stringview leading_comments;
- upb_stringview trailing_comments;
- upb_array* path;
- upb_array* span;
- upb_array* leading_detached_comments;
+ UPB_SIZE(4, 8), 1, false,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_SourceCodeInfo_Location__fields[5] = {
- {1, offsetof(google_protobuf_SourceCodeInfo_Location, path), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 3},
- {2, offsetof(google_protobuf_SourceCodeInfo_Location, span), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 3},
- {3, offsetof(google_protobuf_SourceCodeInfo_Location, leading_comments), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {4, offsetof(google_protobuf_SourceCodeInfo_Location, trailing_comments), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {6, offsetof(google_protobuf_SourceCodeInfo_Location, leading_detached_comments), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 3},
+static const upb_msglayout_field google_protobuf_SourceCodeInfo_Location__fields[5] = {
+ {1, UPB_SIZE(24, 48), 0, 0, 5, 3},
+ {2, UPB_SIZE(28, 56), 0, 0, 5, 3},
+ {3, UPB_SIZE(8, 16), 1, 0, 9, 1},
+ {4, UPB_SIZE(16, 32), 2, 0, 9, 1},
+ {6, UPB_SIZE(32, 64), 0, 0, 9, 3},
};
-const upb_msglayout_msginit_v1 google_protobuf_SourceCodeInfo_Location_msginit = {
+const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit = {
NULL,
&google_protobuf_SourceCodeInfo_Location__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_SourceCodeInfo_Location), 5, 0, false, true
+ UPB_SIZE(40, 80), 5, false,
};
-google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_env *env) {
- google_protobuf_SourceCodeInfo_Location *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_SourceCodeInfo_Location *msg = google_protobuf_SourceCodeInfo_Location_new(env);
- if (upb_decode(buf, msg, &google_protobuf_SourceCodeInfo_Location_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_SourceCodeInfo_Location_serialize(google_protobuf_SourceCodeInfo_Location *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_SourceCodeInfo_Location_msginit, env, size);
-}
-const upb_array* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location *msg) {
- return msg->path;
-}
-void google_protobuf_SourceCodeInfo_Location_set_path(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) {
- msg->path = value;
-}
-const upb_array* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location *msg) {
- return msg->span;
-}
-void google_protobuf_SourceCodeInfo_Location_set_span(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) {
- msg->span = value;
-}
-upb_stringview google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) {
- return msg->leading_comments;
-}
-void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_stringview value) {
- msg->leading_comments = value;
-}
-upb_stringview google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) {
- return msg->trailing_comments;
-}
-void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_stringview value) {
- msg->trailing_comments = value;
-}
-const upb_array* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location *msg) {
- return msg->leading_detached_comments;
-}
-void google_protobuf_SourceCodeInfo_Location_set_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_array* value) {
- msg->leading_detached_comments = value;
-}
-struct google_protobuf_GeneratedCodeInfo {
- upb_array* annotation;
-};
-
-static const upb_msglayout_msginit_v1 *const google_protobuf_GeneratedCodeInfo_submsgs[1] = {
+static const upb_msglayout *const google_protobuf_GeneratedCodeInfo_submsgs[1] = {
&google_protobuf_GeneratedCodeInfo_Annotation_msginit,
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_GeneratedCodeInfo__fields[1] = {
- {1, offsetof(google_protobuf_GeneratedCodeInfo, annotation), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, 0, 11, 3},
+static const upb_msglayout_field google_protobuf_GeneratedCodeInfo__fields[1] = {
+ {1, UPB_SIZE(0, 0), 0, 0, 11, 3},
};
-const upb_msglayout_msginit_v1 google_protobuf_GeneratedCodeInfo_msginit = {
+const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit = {
&google_protobuf_GeneratedCodeInfo_submsgs[0],
&google_protobuf_GeneratedCodeInfo__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_GeneratedCodeInfo), 1, 0, false, true
+ UPB_SIZE(4, 8), 1, false,
};
-google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_new(upb_env *env) {
- google_protobuf_GeneratedCodeInfo *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_GeneratedCodeInfo *msg = google_protobuf_GeneratedCodeInfo_new(env);
- if (upb_decode(buf, msg, &google_protobuf_GeneratedCodeInfo_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_GeneratedCodeInfo_serialize(google_protobuf_GeneratedCodeInfo *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, env, size);
-}
-const upb_array* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo *msg) {
- return msg->annotation;
-}
-void google_protobuf_GeneratedCodeInfo_set_annotation(google_protobuf_GeneratedCodeInfo *msg, upb_array* value) {
- msg->annotation = value;
-}
-struct google_protobuf_GeneratedCodeInfo_Annotation {
- int32_t begin;
- int32_t end;
- upb_stringview source_file;
- upb_array* path;
+static const upb_msglayout_field google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = {
+ {1, UPB_SIZE(24, 32), 0, 0, 5, 3},
+ {2, UPB_SIZE(16, 16), 3, 0, 9, 1},
+ {3, UPB_SIZE(4, 4), 1, 0, 5, 1},
+ {4, UPB_SIZE(8, 8), 2, 0, 5, 1},
};
-static const upb_msglayout_fieldinit_v1 google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = {
- {1, offsetof(google_protobuf_GeneratedCodeInfo_Annotation, path), UPB_NO_HASBIT, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 3},
- {2, offsetof(google_protobuf_GeneratedCodeInfo_Annotation, source_file), 2, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 9, 1},
- {3, offsetof(google_protobuf_GeneratedCodeInfo_Annotation, begin), 0, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1},
- {4, offsetof(google_protobuf_GeneratedCodeInfo_Annotation, end), 1, UPB_NOT_IN_ONEOF, UPB_NO_SUBMSG, 5, 1},
-};
-
-const upb_msglayout_msginit_v1 google_protobuf_GeneratedCodeInfo_Annotation_msginit = {
+const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit = {
NULL,
&google_protobuf_GeneratedCodeInfo_Annotation__fields[0],
- NULL,
- NULL, /* TODO. default_msg */
- UPB_ALIGNED_SIZEOF(google_protobuf_GeneratedCodeInfo_Annotation), 4, 0, false, true
+ UPB_SIZE(32, 48), 4, false,
};
-google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_new(upb_env *env) {
- google_protobuf_GeneratedCodeInfo_Annotation *msg = upb_env_malloc(env, sizeof(*msg));
- memset(msg, 0, sizeof(*msg)); /* TODO: defaults */
- return msg;
-}
-google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_parsenew(upb_stringview buf, upb_env *env) {
- google_protobuf_GeneratedCodeInfo_Annotation *msg = google_protobuf_GeneratedCodeInfo_Annotation_new(env);
- if (upb_decode(buf, msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, env)) {
- return msg;
- } else {
- return NULL;
- }
-}
-char *google_protobuf_GeneratedCodeInfo_Annotation_serialize(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_env *env, size_t *size) {
- return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, env, size);
-}
-const upb_array* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation *msg) {
- return msg->path;
-}
-void google_protobuf_GeneratedCodeInfo_Annotation_set_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_array* value) {
- msg->path = value;
-}
-upb_stringview google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) {
- return msg->source_file;
-}
-void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_stringview value) {
- msg->source_file = value;
-}
-int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) {
- return msg->begin;
-}
-void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) {
- msg->begin = value;
-}
-int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) {
- return msg->end;
-}
-void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) {
- msg->end = value;
-}
+
/* Maps descriptor type -> upb field type. */
@@ -1926,7 +524,6 @@ const uint8_t upb_desctype_to_fieldtype[] = {
/* Data pertaining to the parse. */
typedef struct {
- upb_env *env;
/* Current decoding pointer. Points to the beginning of a field until we
* have finished decoding the whole field. */
const char *ptr;
@@ -1939,7 +536,7 @@ typedef struct {
/* These members are unset for an unknown group frame. */
char *msg;
- const upb_msglayout_msginit_v1 *m;
+ const upb_msglayout *m;
} upb_decframe;
#define CHK(x) if (!(x)) { return false; }
@@ -1948,7 +545,7 @@ static bool upb_skip_unknowngroup(upb_decstate *d, int field_number,
const char *limit);
static bool upb_decode_message(upb_decstate *d, const char *limit,
int group_number, char *msg,
- const upb_msglayout_msginit_v1 *l);
+ const upb_msglayout *l);
static bool upb_decode_varint(const char **ptr, const char *limit,
uint64_t *val) {
@@ -2029,9 +626,7 @@ static void upb_set32(void *msg, size_t ofs, uint32_t val) {
static bool upb_append_unknown(upb_decstate *d, upb_decframe *frame,
const char *start) {
- UPB_UNUSED(d);
- UPB_UNUSED(frame);
- UPB_UNUSED(start);
+ upb_msg_addunknown(frame->msg, start, d->ptr - start);
return true;
}
@@ -2070,6 +665,7 @@ static bool upb_array_grow(upb_array *arr, size_t elements) {
size_t new_bytes;
size_t old_bytes;
void *new_data;
+ upb_alloc *alloc = upb_arena_alloc(arr->arena);
while (new_size < needed) {
new_size *= 2;
@@ -2077,7 +673,7 @@ static bool upb_array_grow(upb_array *arr, size_t elements) {
old_bytes = arr->len * arr->element_size;
new_bytes = new_size * arr->element_size;
- new_data = upb_realloc(arr->alloc, arr->data, old_bytes, new_bytes);
+ new_data = upb_realloc(alloc, arr->data, old_bytes, new_bytes);
CHK(new_data);
arr->data = new_data;
@@ -2099,23 +695,21 @@ static void *upb_array_add(upb_array *arr, size_t elements) {
}
static upb_array *upb_getarr(upb_decframe *frame,
- const upb_msglayout_fieldinit_v1 *field) {
+ const upb_msglayout_field *field) {
UPB_ASSERT(field->label == UPB_LABEL_REPEATED);
return *(upb_array**)&frame->msg[field->offset];
}
-static upb_array *upb_getorcreatearr(upb_decstate *d,
- upb_decframe *frame,
- const upb_msglayout_fieldinit_v1 *field) {
+static upb_array *upb_getorcreatearr(upb_decframe *frame,
+ const upb_msglayout_field *field) {
upb_array *arr = upb_getarr(frame, field);
if (!arr) {
- arr = upb_env_malloc(d->env, sizeof(*arr));
+ upb_fieldtype_t type = upb_desctype_to_fieldtype[field->descriptortype];
+ arr = upb_array_new(type, upb_msg_arena(frame->msg));
if (!arr) {
return NULL;
}
- upb_array_init(arr, upb_desctype_to_fieldtype[field->descriptortype],
- upb_arena_alloc(upb_env_arena(d->env)));
*(upb_array**)&frame->msg[field->offset] = arr;
}
@@ -2123,26 +717,25 @@ static upb_array *upb_getorcreatearr(upb_decstate *d,
}
static void upb_sethasbit(upb_decframe *frame,
- const upb_msglayout_fieldinit_v1 *field) {
- UPB_ASSERT(field->hasbit != UPB_NO_HASBIT);
- frame->msg[field->hasbit / 8] |= (1 << (field->hasbit % 8));
+ const upb_msglayout_field *field) {
+ int32_t hasbit = field->presence;
+ UPB_ASSERT(field->presence > 0);
+ frame->msg[hasbit / 8] |= (1 << (hasbit % 8));
}
static void upb_setoneofcase(upb_decframe *frame,
- const upb_msglayout_fieldinit_v1 *field) {
- UPB_ASSERT(field->oneof_index != UPB_NOT_IN_ONEOF);
- upb_set32(frame->msg, frame->m->oneofs[field->oneof_index].case_offset,
- field->number);
+ const upb_msglayout_field *field) {
+ UPB_ASSERT(field->presence < 0);
+ upb_set32(frame->msg, ~field->presence, field->number);
}
-static char *upb_decode_prepareslot(upb_decstate *d,
- upb_decframe *frame,
- const upb_msglayout_fieldinit_v1 *field) {
+static char *upb_decode_prepareslot(upb_decframe *frame,
+ const upb_msglayout_field *field) {
char *field_mem = frame->msg + field->offset;
upb_array *arr;
if (field->label == UPB_LABEL_REPEATED) {
- arr = upb_getorcreatearr(d, frame, field);
+ arr = upb_getorcreatearr(frame, field);
field_mem = upb_array_reserve(arr, 1);
}
@@ -2150,36 +743,32 @@ static char *upb_decode_prepareslot(upb_decstate *d,
}
static void upb_decode_setpresent(upb_decframe *frame,
- const upb_msglayout_fieldinit_v1 *field) {
+ const upb_msglayout_field *field) {
if (field->label == UPB_LABEL_REPEATED) {
upb_array *arr = upb_getarr(frame, field);
UPB_ASSERT(arr->len < arr->size);
arr->len++;
- } else if (field->oneof_index != UPB_NOT_IN_ONEOF) {
+ } else if (field->presence < 0) {
upb_setoneofcase(frame, field);
- } else if (field->hasbit != UPB_NO_HASBIT) {
+ } else if (field->presence > 0) {
upb_sethasbit(frame, field);
}
}
-static bool upb_decode_submsg(upb_decstate *d,
- upb_decframe *frame,
+static bool upb_decode_submsg(upb_decstate *d, upb_decframe *frame,
const char *limit,
- const upb_msglayout_fieldinit_v1 *field,
+ const upb_msglayout_field *field,
int group_number) {
- char *submsg_slot = upb_decode_prepareslot(d, frame, field);
- char *submsg = *(void**)submsg_slot;
- const upb_msglayout_msginit_v1 *subm;
+ char *submsg_slot = upb_decode_prepareslot(frame, field);
+ char *submsg = *(void **)submsg_slot;
+ const upb_msglayout *subm;
- UPB_ASSERT(field->submsg_index != UPB_NO_SUBMSG);
subm = frame->m->submsgs[field->submsg_index];
UPB_ASSERT(subm);
if (!submsg) {
- submsg = upb_env_malloc(d->env, upb_msg_sizeof((upb_msglayout *)subm));
+ submsg = upb_msg_new(subm, upb_msg_arena(frame->msg));
CHK(submsg);
- submsg = upb_msg_init(
- submsg, (upb_msglayout*)subm, upb_arena_alloc(upb_env_arena(d->env)));
*(void**)submsg_slot = submsg;
}
@@ -2190,11 +779,11 @@ static bool upb_decode_submsg(upb_decstate *d,
static bool upb_decode_varintfield(upb_decstate *d, upb_decframe *frame,
const char *field_start,
- const upb_msglayout_fieldinit_v1 *field) {
+ const upb_msglayout_field *field) {
uint64_t val;
void *field_mem;
- field_mem = upb_decode_prepareslot(d, frame, field);
+ field_mem = upb_decode_prepareslot(frame, field);
CHK(field_mem);
CHK(upb_decode_varint(&d->ptr, frame->limit, &val));
@@ -2235,11 +824,11 @@ static bool upb_decode_varintfield(upb_decstate *d, upb_decframe *frame,
static bool upb_decode_64bitfield(upb_decstate *d, upb_decframe *frame,
const char *field_start,
- const upb_msglayout_fieldinit_v1 *field) {
+ const upb_msglayout_field *field) {
void *field_mem;
uint64_t val;
- field_mem = upb_decode_prepareslot(d, frame, field);
+ field_mem = upb_decode_prepareslot(frame, field);
CHK(field_mem);
CHK(upb_decode_64bit(&d->ptr, frame->limit, &val));
@@ -2259,11 +848,11 @@ static bool upb_decode_64bitfield(upb_decstate *d, upb_decframe *frame,
static bool upb_decode_32bitfield(upb_decstate *d, upb_decframe *frame,
const char *field_start,
- const upb_msglayout_fieldinit_v1 *field) {
+ const upb_msglayout_field *field) {
void *field_mem;
uint32_t val;
- field_mem = upb_decode_prepareslot(d, frame, field);
+ field_mem = upb_decode_prepareslot(frame, field);
CHK(field_mem);
CHK(upb_decode_32bit(&d->ptr, frame->limit, &val));
@@ -2295,9 +884,9 @@ static bool upb_decode_fixedpacked(upb_array *arr, upb_stringview data,
static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame,
const char *field_start,
- const upb_msglayout_fieldinit_v1 *field,
+ const upb_msglayout_field *field,
upb_stringview val) {
- upb_array *arr = upb_getorcreatearr(d, frame, field);
+ upb_array *arr = upb_getorcreatearr(frame, field);
#define VARINT_CASE(ctype, decode) { \
const char *ptr = val.data; \
@@ -2346,7 +935,7 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame,
case UPB_DESCRIPTOR_TYPE_SINT64:
VARINT_CASE(int64_t, upb_zzdecode_64);
case UPB_DESCRIPTOR_TYPE_MESSAGE: {
- const upb_msglayout_msginit_v1 *subm;
+ const upb_msglayout *subm;
char *submsg;
void *field_mem;
@@ -2354,14 +943,11 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame,
d->ptr -= val.size;
/* Create elemente message. */
- UPB_ASSERT(field->submsg_index != UPB_NO_SUBMSG);
subm = frame->m->submsgs[field->submsg_index];
UPB_ASSERT(subm);
- submsg = upb_env_malloc(d->env, upb_msg_sizeof((upb_msglayout *)subm));
+ submsg = upb_msg_new(subm, upb_msg_arena(frame->msg));
CHK(submsg);
- submsg = upb_msg_init(submsg, (upb_msglayout*)subm,
- upb_arena_alloc(upb_env_arena(d->env)));
field_mem = upb_array_add(arr, 1);
CHK(field_mem);
@@ -2379,7 +965,7 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame,
static bool upb_decode_delimitedfield(upb_decstate *d, upb_decframe *frame,
const char *field_start,
- const upb_msglayout_fieldinit_v1 *field) {
+ const upb_msglayout_field *field) {
upb_stringview val;
CHK(upb_decode_string(&d->ptr, frame->limit, &val));
@@ -2390,7 +976,7 @@ static bool upb_decode_delimitedfield(upb_decstate *d, upb_decframe *frame,
switch ((upb_descriptortype_t)field->descriptortype) {
case UPB_DESCRIPTOR_TYPE_STRING:
case UPB_DESCRIPTOR_TYPE_BYTES: {
- void *field_mem = upb_decode_prepareslot(d, frame, field);
+ void *field_mem = upb_decode_prepareslot(frame, field);
CHK(field_mem);
memcpy(field_mem, &val, sizeof(val));
break;
@@ -2409,8 +995,8 @@ static bool upb_decode_delimitedfield(upb_decstate *d, upb_decframe *frame,
}
}
-static const upb_msglayout_fieldinit_v1 *upb_find_field(
- const upb_msglayout_msginit_v1 *l, uint32_t field_number) {
+static const upb_msglayout_field *upb_find_field(const upb_msglayout *l,
+ uint32_t field_number) {
/* Lots of optimization opportunities here. */
int i;
for (i = 0; i < l->field_count; i++) {
@@ -2426,7 +1012,7 @@ static bool upb_decode_field(upb_decstate *d, upb_decframe *frame) {
int field_number;
int wire_type;
const char *field_start = d->ptr;
- const upb_msglayout_fieldinit_v1 *field;
+ const upb_msglayout_field *field;
CHK(upb_decode_tag(&d->ptr, frame->limit, &field_number, &wire_type));
field = upb_find_field(frame->m, field_number);
@@ -2453,7 +1039,9 @@ static bool upb_decode_field(upb_decstate *d, upb_decframe *frame) {
}
} else {
CHK(field_number != 0);
- return upb_skip_unknownfielddata(d, frame, field_number, wire_type);
+ CHK(upb_skip_unknownfielddata(d, frame, field_number, wire_type));
+ CHK(upb_append_unknown(d, frame, field_start));
+ return true;
}
}
@@ -2478,7 +1066,7 @@ static bool upb_skip_unknowngroup(upb_decstate *d, int field_number,
static bool upb_decode_message(upb_decstate *d, const char *limit,
int group_number, char *msg,
- const upb_msglayout_msginit_v1 *l) {
+ const upb_msglayout *l) {
upb_decframe frame;
frame.group_number = group_number;
frame.limit = limit;
@@ -2492,11 +1080,9 @@ static bool upb_decode_message(upb_decstate *d, const char *limit,
return true;
}
-bool upb_decode(upb_stringview buf, void *msg,
- const upb_msglayout_msginit_v1 *l, upb_env *env) {
+bool upb_decode(upb_stringview buf, void *msg, const upb_msglayout *l) {
upb_decstate state;
state.ptr = buf.data;
- state.env = env;
return upb_decode_message(&state, buf.data + buf.size, 0, msg, l);
}
@@ -2866,6 +1452,45 @@ static bool assign_msg_indices(upb_msgdef *m, upb_status *s) {
return true;
}
+static void assign_msg_wellknowntype(upb_msgdef *m) {
+ const char *name = upb_msgdef_fullname(m);
+ if (name == NULL) {
+ m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED;
+ return;
+ }
+ if (!strcmp(name, "google.protobuf.Duration")) {
+ m->well_known_type = UPB_WELLKNOWN_DURATION;
+ } else if (!strcmp(name, "google.protobuf.Timestamp")) {
+ m->well_known_type = UPB_WELLKNOWN_TIMESTAMP;
+ } else if (!strcmp(name, "google.protobuf.DoubleValue")) {
+ m->well_known_type = UPB_WELLKNOWN_DOUBLEVALUE;
+ } else if (!strcmp(name, "google.protobuf.FloatValue")) {
+ m->well_known_type = UPB_WELLKNOWN_FLOATVALUE;
+ } else if (!strcmp(name, "google.protobuf.Int64Value")) {
+ m->well_known_type = UPB_WELLKNOWN_INT64VALUE;
+ } else if (!strcmp(name, "google.protobuf.UInt64Value")) {
+ m->well_known_type = UPB_WELLKNOWN_UINT64VALUE;
+ } else if (!strcmp(name, "google.protobuf.Int32Value")) {
+ m->well_known_type = UPB_WELLKNOWN_INT32VALUE;
+ } else if (!strcmp(name, "google.protobuf.UInt32Value")) {
+ m->well_known_type = UPB_WELLKNOWN_UINT32VALUE;
+ } else if (!strcmp(name, "google.protobuf.BoolValue")) {
+ m->well_known_type = UPB_WELLKNOWN_BOOLVALUE;
+ } else if (!strcmp(name, "google.protobuf.StringValue")) {
+ m->well_known_type = UPB_WELLKNOWN_STRINGVALUE;
+ } else if (!strcmp(name, "google.protobuf.BytesValue")) {
+ m->well_known_type = UPB_WELLKNOWN_BYTESVALUE;
+ } else if (!strcmp(name, "google.protobuf.Value")) {
+ m->well_known_type = UPB_WELLKNOWN_VALUE;
+ } else if (!strcmp(name, "google.protobuf.ListValue")) {
+ m->well_known_type = UPB_WELLKNOWN_LISTVALUE;
+ } else if (!strcmp(name, "google.protobuf.Struct")) {
+ m->well_known_type = UPB_WELLKNOWN_STRUCT;
+ } else {
+ m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED;
+ }
+}
+
bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s) {
size_t i;
@@ -2902,6 +1527,8 @@ bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s) {
if (!assign_msg_indices(m, s)) {
goto err;
}
+ assign_msg_wellknowntype(m);
+ /* m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED; */
} else if (e) {
upb_inttable_compact(&e->iton);
}
@@ -4094,6 +2721,16 @@ bool upb_msgdef_mapentry(const upb_msgdef *m) {
return m->map_entry;
}
+upb_wellknowntype_t upb_msgdef_wellknowntype(const upb_msgdef *m) {
+ return m->well_known_type;
+}
+
+bool upb_msgdef_isnumberwrapper(const upb_msgdef *m) {
+ upb_wellknowntype_t type = upb_msgdef_wellknowntype(m);
+ return type >= UPB_WELLKNOWN_DOUBLEVALUE &&
+ type <= UPB_WELLKNOWN_UINT32VALUE;
+}
+
void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m) {
upb_inttable_begin(iter, &m->itof);
}
@@ -4908,7 +3545,7 @@ static uint32_t upb_zzencode_32(int32_t n) { return (n << 1) ^ (n >> 31); }
static uint64_t upb_zzencode_64(int64_t n) { return (n << 1) ^ (n >> 63); }
typedef struct {
- upb_env *env;
+ upb_alloc *alloc;
char *buf, *ptr, *limit;
} upb_encstate;
@@ -4923,7 +3560,7 @@ static size_t upb_roundup_pow2(size_t bytes) {
static bool upb_encode_growbuffer(upb_encstate *e, size_t bytes) {
size_t old_size = e->limit - e->buf;
size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr));
- char *new_buf = upb_env_realloc(e->env, e->buf, old_size, new_size);
+ char *new_buf = upb_realloc(e->alloc, e->buf, old_size, new_size);
CHK(new_buf);
/* We want previous data at the end, realloc() put it at the beginning. */
@@ -4987,17 +3624,17 @@ static bool upb_put_float(upb_encstate *e, float d) {
return upb_put_fixed32(e, u32);
}
-static uint32_t upb_readcase(const char *msg, const upb_msglayout_msginit_v1 *m,
- int oneof_index) {
+static uint32_t upb_readcase(const char *msg, const upb_msglayout_field *f) {
uint32_t ret;
- memcpy(&ret, msg + m->oneofs[oneof_index].case_offset, sizeof(ret));
+ uint32_t offset = ~f->presence;
+ memcpy(&ret, msg + offset, sizeof(ret));
return ret;
}
-static bool upb_readhasbit(const char *msg,
- const upb_msglayout_fieldinit_v1 *f) {
- UPB_ASSERT(f->hasbit != UPB_NO_HASBIT);
- return msg[f->hasbit / 8] & (1 << (f->hasbit % 8));
+static bool upb_readhasbit(const char *msg, const upb_msglayout_field *f) {
+ uint32_t hasbit = f->presence;
+ UPB_ASSERT(f->presence > 0);
+ return msg[hasbit / 8] & (1 << (hasbit % 8));
}
static bool upb_put_tag(upb_encstate *e, int field_number, int wire_type) {
@@ -5011,12 +3648,11 @@ static bool upb_put_fixedarray(upb_encstate *e, const upb_array *arr,
}
bool upb_encode_message(upb_encstate *e, const char *msg,
- const upb_msglayout_msginit_v1 *m,
- size_t *size);
+ const upb_msglayout *m, size_t *size);
static bool upb_encode_array(upb_encstate *e, const char *field_mem,
- const upb_msglayout_msginit_v1 *m,
- const upb_msglayout_fieldinit_v1 *f) {
+ const upb_msglayout *m,
+ const upb_msglayout_field *f) {
const upb_array *arr = *(const upb_array**)field_mem;
if (arr == NULL || arr->len == 0) {
@@ -5082,7 +3718,7 @@ do { ; } while(0)
case UPB_DESCRIPTOR_TYPE_GROUP: {
void **start = arr->data;
void **ptr = start + arr->len;
- const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index];
+ const upb_msglayout *subm = m->submsgs[f->submsg_index];
do {
size_t size;
ptr--;
@@ -5095,7 +3731,7 @@ do { ; } while(0)
case UPB_DESCRIPTOR_TYPE_MESSAGE: {
void **start = arr->data;
void **ptr = start + arr->len;
- const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index];
+ const upb_msglayout *subm = m->submsgs[f->submsg_index];
do {
size_t size;
ptr--;
@@ -5115,11 +3751,9 @@ do { ; } while(0)
}
static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem,
- const upb_msglayout_msginit_v1 *m,
- const upb_msglayout_fieldinit_v1 *f,
- bool is_proto3) {
- bool skip_zero_value = is_proto3 && f->oneof_index == UPB_NOT_IN_ONEOF;
-
+ const upb_msglayout *m,
+ const upb_msglayout_field *f,
+ bool skip_zero_value) {
#define CASE(ctype, type, wire_type, encodeval) do { \
ctype val = *(ctype*)field_mem; \
if (skip_zero_value && val == 0) { \
@@ -5166,9 +3800,9 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem,
}
case UPB_DESCRIPTOR_TYPE_GROUP: {
size_t size;
- void *submsg = *(void**)field_mem;
- const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index];
- if (skip_zero_value && submsg == NULL) {
+ void *submsg = *(void **)field_mem;
+ const upb_msglayout *subm = m->submsgs[f->submsg_index];
+ if (submsg == NULL) {
return true;
}
return upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) &&
@@ -5177,9 +3811,9 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem,
}
case UPB_DESCRIPTOR_TYPE_MESSAGE: {
size_t size;
- void *submsg = *(void**)field_mem;
- const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index];
- if (skip_zero_value && submsg == NULL) {
+ void *submsg = *(void **)field_mem;
+ const upb_msglayout *subm = m->submsgs[f->submsg_index];
+ if (submsg == NULL) {
return true;
}
return upb_encode_message(e, submsg, subm, &size) &&
@@ -5191,55 +3825,52 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem,
UPB_UNREACHABLE();
}
-bool upb_encode_hasscalarfield(const char *msg,
- const upb_msglayout_msginit_v1 *m,
- const upb_msglayout_fieldinit_v1 *f) {
- if (f->oneof_index != UPB_NOT_IN_ONEOF) {
- return upb_readcase(msg, m, f->oneof_index) == f->number;
- } else if (m->is_proto2) {
- return upb_readhasbit(msg, f);
- } else {
- /* For proto3, we'll test for the field being empty later. */
- return true;
- }
-}
-
-bool upb_encode_message(upb_encstate* e, const char *msg,
- const upb_msglayout_msginit_v1 *m,
- size_t *size) {
+bool upb_encode_message(upb_encstate *e, const char *msg,
+ const upb_msglayout *m, size_t *size) {
int i;
size_t pre_len = e->limit - e->ptr;
-
- if (msg == NULL) {
- return true;
- }
+ const char *unknown;
+ size_t unknown_size;
for (i = m->field_count - 1; i >= 0; i--) {
- const upb_msglayout_fieldinit_v1 *f = &m->fields[i];
+ const upb_msglayout_field *f = &m->fields[i];
if (f->label == UPB_LABEL_REPEATED) {
CHK(upb_encode_array(e, msg + f->offset, m, f));
} else {
- if (upb_encode_hasscalarfield(msg, m, f)) {
- if (f->oneof_index == UPB_NOT_IN_ONEOF) {
- CHK(upb_encode_scalarfield(e, msg + f->offset, m, f, !m->is_proto2));
- } else {
- const upb_msglayout_oneofinit_v1 *o = &m->oneofs[f->oneof_index];
- CHK(upb_encode_scalarfield(e, msg + o->data_offset,
- m, f, !m->is_proto2));
+ bool skip_empty = false;
+ if (f->presence == 0) {
+ /* Proto3 presence. */
+ skip_empty = true;
+ } else if (f->presence > 0) {
+ /* Proto2 presence: hasbit. */
+ if (!upb_readhasbit(msg, f)) {
+ continue;
+ }
+ } else {
+ /* Field is in a oneof. */
+ if (upb_readcase(msg, f) != f->number) {
+ continue;
}
}
+ CHK(upb_encode_scalarfield(e, msg + f->offset, m, f, skip_empty));
}
}
+ unknown = upb_msg_getunknown(msg, &unknown_size);
+
+ if (unknown) {
+ upb_put_bytes(e, unknown, unknown_size);
+ }
+
*size = (e->limit - e->ptr) - pre_len;
return true;
}
-char *upb_encode(const void *msg, const upb_msglayout_msginit_v1 *m,
- upb_env *env, size_t *size) {
+char *upb_encode(const void *msg, const upb_msglayout *m, upb_arena *arena,
+ size_t *size) {
upb_encstate e;
- e.env = env;
+ e.alloc = upb_arena_alloc(arena);
e.buf = NULL;
e.limit = NULL;
e.ptr = NULL;
@@ -5964,29 +4595,108 @@ bool upb_byteshandler_setendstr(upb_byteshandler *h,
}
-static bool is_power_of_two(size_t val) {
- return (val & (val - 1)) == 0;
-}
+/** Handlers for upb_msg ******************************************************/
-/* Align up to the given power of 2. */
-static size_t align_up(size_t val, size_t align) {
- UPB_ASSERT(is_power_of_two(align));
- return (val + align - 1) & ~(align - 1);
+typedef struct {
+ size_t offset;
+ int32_t hasbit;
+} upb_msg_handlerdata;
+
+/* Fallback implementation if the handler is not specialized by the producer. */
+#define MSG_WRITER(type, ctype) \
+ bool upb_msg_set ## type (void *c, const void *hd, ctype val) { \
+ uint8_t *m = c; \
+ const upb_msg_handlerdata *d = hd; \
+ if (d->hasbit > 0) \
+ *(uint8_t*)&m[d->hasbit / 8] |= 1 << (d->hasbit % 8); \
+ *(ctype*)&m[d->offset] = val; \
+ return true; \
+ } \
+
+MSG_WRITER(double, double)
+MSG_WRITER(float, float)
+MSG_WRITER(int32, int32_t)
+MSG_WRITER(int64, int64_t)
+MSG_WRITER(uint32, uint32_t)
+MSG_WRITER(uint64, uint64_t)
+MSG_WRITER(bool, bool)
+
+bool upb_msg_setscalarhandler(upb_handlers *h, const upb_fielddef *f,
+ size_t offset, int32_t hasbit) {
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ bool ok;
+
+ upb_msg_handlerdata *d = upb_gmalloc(sizeof(*d));
+ if (!d) return false;
+ d->offset = offset;
+ d->hasbit = hasbit;
+
+ upb_handlerattr_sethandlerdata(&attr, d);
+ upb_handlerattr_setalwaysok(&attr, true);
+ upb_handlers_addcleanup(h, d, upb_gfree);
+
+#define TYPE(u, l) \
+ case UPB_TYPE_##u: \
+ ok = upb_handlers_set##l(h, f, upb_msg_set##l, &attr); break;
+
+ ok = false;
+
+ switch (upb_fielddef_type(f)) {
+ TYPE(INT64, int64);
+ TYPE(INT32, int32);
+ TYPE(ENUM, int32);
+ TYPE(UINT64, uint64);
+ TYPE(UINT32, uint32);
+ TYPE(DOUBLE, double);
+ TYPE(FLOAT, float);
+ TYPE(BOOL, bool);
+ default: UPB_ASSERT(false); break;
+ }
+#undef TYPE
+
+ upb_handlerattr_uninit(&attr);
+ return ok;
}
-static size_t div_round_up(size_t n, size_t d) {
- return (n + d - 1) / d;
+bool upb_msg_getscalarhandlerdata(const upb_handlers *h,
+ upb_selector_t s,
+ upb_fieldtype_t *type,
+ size_t *offset,
+ int32_t *hasbit) {
+ const upb_msg_handlerdata *d;
+ upb_func *f = upb_handlers_gethandler(h, s);
+
+ if ((upb_int64_handlerfunc*)f == upb_msg_setint64) {
+ *type = UPB_TYPE_INT64;
+ } else if ((upb_int32_handlerfunc*)f == upb_msg_setint32) {
+ *type = UPB_TYPE_INT32;
+ } else if ((upb_uint64_handlerfunc*)f == upb_msg_setuint64) {
+ *type = UPB_TYPE_UINT64;
+ } else if ((upb_uint32_handlerfunc*)f == upb_msg_setuint32) {
+ *type = UPB_TYPE_UINT32;
+ } else if ((upb_double_handlerfunc*)f == upb_msg_setdouble) {
+ *type = UPB_TYPE_DOUBLE;
+ } else if ((upb_float_handlerfunc*)f == upb_msg_setfloat) {
+ *type = UPB_TYPE_FLOAT;
+ } else if ((upb_bool_handlerfunc*)f == upb_msg_setbool) {
+ *type = UPB_TYPE_BOOL;
+ } else {
+ return false;
+ }
+
+ d = upb_handlers_gethandlerdata(h, s);
+ *offset = d->offset;
+ *hasbit = d->hasbit;
+ return true;
}
+
bool upb_fieldtype_mapkeyok(upb_fieldtype_t type) {
return type == UPB_TYPE_BOOL || type == UPB_TYPE_INT32 ||
type == UPB_TYPE_UINT32 || type == UPB_TYPE_INT64 ||
type == UPB_TYPE_UINT64 || type == UPB_TYPE_STRING;
}
-void *upb_array_pack(const upb_array *arr, void *p, size_t *ofs, size_t size);
-void *upb_map_pack(const upb_map *map, void *p, size_t *ofs, size_t size);
-
#define PTR_AT(msg, ofs, type) (type*)((char*)msg + ofs)
#define VOIDPTR_AT(msg, ofs) PTR_AT(msg, ofs, void)
#define ENCODE_MAX_NESTING 64
@@ -6035,7 +4745,7 @@ static size_t upb_msgval_sizeof(upb_fieldtype_t type) {
UPB_UNREACHABLE();
}
-static uint8_t upb_msg_fieldsize(const upb_msglayout_fieldinit_v1 *field) {
+static uint8_t upb_msg_fieldsize(const upb_msglayout_field *field) {
if (field->label == UPB_LABEL_REPEATED) {
return sizeof(void*);
} else {
@@ -6043,14 +4753,6 @@ static uint8_t upb_msg_fieldsize(const upb_msglayout_fieldinit_v1 *field) {
}
}
-static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) {
- if (upb_fielddef_isseq(f)) {
- return sizeof(void*);
- } else {
- return upb_msgval_sizeof(upb_fielddef_type(f));
- }
-}
-
/* TODO(haberman): this is broken right now because upb_msgval can contain
* a char* / size_t pair, which is too big for a upb_value. To fix this
* we'll probably need to dynamically allocate a upb_msgval and store a
@@ -6086,525 +4788,6 @@ static upb_ctype_t upb_fieldtotabtype(upb_fieldtype_t type) {
}
}
-static upb_msgval upb_msgval_fromdefault(const upb_fielddef *f) {
- switch (upb_fielddef_type(f)) {
- case UPB_TYPE_FLOAT:
- return upb_msgval_float(upb_fielddef_defaultfloat(f));
- case UPB_TYPE_DOUBLE:
- return upb_msgval_double(upb_fielddef_defaultdouble(f));
- case UPB_TYPE_BOOL:
- return upb_msgval_bool(upb_fielddef_defaultbool(f));
- case UPB_TYPE_STRING:
- case UPB_TYPE_BYTES: {
- size_t len;
- const char *ptr = upb_fielddef_defaultstr(f, &len);
- return upb_msgval_makestr(ptr, len);
- }
- case UPB_TYPE_MESSAGE:
- return upb_msgval_msg(NULL);
- case UPB_TYPE_ENUM:
- case UPB_TYPE_INT32:
- return upb_msgval_int32(upb_fielddef_defaultint32(f));
- case UPB_TYPE_UINT32:
- return upb_msgval_uint32(upb_fielddef_defaultuint32(f));
- case UPB_TYPE_INT64:
- return upb_msgval_int64(upb_fielddef_defaultint64(f));
- case UPB_TYPE_UINT64:
- return upb_msgval_uint64(upb_fielddef_defaultuint64(f));
- default:
- UPB_ASSERT(false);
- return upb_msgval_msg(NULL);
- }
-}
-
-
-/** upb_msglayout *************************************************************/
-
-struct upb_msglayout {
- struct upb_msglayout_msginit_v1 data;
-};
-
-static void upb_msglayout_free(upb_msglayout *l) {
- upb_gfree(l->data.default_msg);
- upb_gfree(l);
-}
-
-static size_t upb_msglayout_place(upb_msglayout *l, size_t size) {
- size_t ret;
-
- l->data.size = align_up(l->data.size, size);
- ret = l->data.size;
- l->data.size += size;
- return ret;
-}
-
-static uint32_t upb_msglayout_offset(const upb_msglayout *l,
- const upb_fielddef *f) {
- return l->data.fields[upb_fielddef_index(f)].offset;
-}
-
-static uint32_t upb_msglayout_hasbit(const upb_msglayout *l,
- const upb_fielddef *f) {
- return l->data.fields[upb_fielddef_index(f)].hasbit;
-}
-
-static bool upb_msglayout_initdefault(upb_msglayout *l, const upb_msgdef *m) {
- upb_msg_field_iter it;
-
- if (upb_msgdef_syntax(m) == UPB_SYNTAX_PROTO2 && l->data.size) {
- /* Allocate default message and set default values in it. */
- l->data.default_msg = upb_gmalloc(l->data.size);
- if (!l->data.default_msg) {
- return false;
- }
-
- memset(l->data.default_msg, 0, l->data.size);
-
- for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it);
- upb_msg_field_next(&it)) {
- const upb_fielddef* f = upb_msg_iter_field(&it);
-
- if (upb_fielddef_containingoneof(f)) {
- continue;
- }
-
- /* TODO(haberman): handle strings. */
- if (!upb_fielddef_isstring(f) &&
- !upb_fielddef_issubmsg(f) &&
- !upb_fielddef_isseq(f)) {
- upb_msg_set(l->data.default_msg,
- upb_fielddef_index(f),
- upb_msgval_fromdefault(f),
- l);
- }
- }
- }
-
- return true;
-}
-
-static bool upb_msglayout_init(const upb_msgdef *m,
- upb_msglayout *l,
- upb_msgfactory *factory) {
- upb_msg_field_iter it;
- upb_msg_oneof_iter oit;
- size_t hasbit;
- size_t submsg_count = 0;
- const upb_msglayout_msginit_v1 **submsgs;
- upb_msglayout_fieldinit_v1 *fields;
- upb_msglayout_oneofinit_v1 *oneofs;
-
- for (upb_msg_field_begin(&it, m);
- !upb_msg_field_done(&it);
- upb_msg_field_next(&it)) {
- const upb_fielddef* f = upb_msg_iter_field(&it);
- if (upb_fielddef_issubmsg(f)) {
- submsg_count++;
- }
- }
-
- memset(l, 0, sizeof(*l));
-
- fields = upb_gmalloc(upb_msgdef_numfields(m) * sizeof(*fields));
- submsgs = upb_gmalloc(submsg_count * sizeof(*submsgs));
- oneofs = upb_gmalloc(upb_msgdef_numoneofs(m) * sizeof(*oneofs));
-
- if ((!fields && upb_msgdef_numfields(m)) ||
- (!submsgs && submsg_count) ||
- (!oneofs && upb_msgdef_numoneofs(m))) {
- /* OOM. */
- upb_gfree(fields);
- upb_gfree(submsgs);
- upb_gfree(oneofs);
- return false;
- }
-
- l->data.field_count = upb_msgdef_numfields(m);
- l->data.oneof_count = upb_msgdef_numoneofs(m);
- l->data.fields = fields;
- l->data.submsgs = submsgs;
- l->data.oneofs = oneofs;
- l->data.is_proto2 = (upb_msgdef_syntax(m) == UPB_SYNTAX_PROTO2);
-
- /* Allocate data offsets in three stages:
- *
- * 1. hasbits.
- * 2. regular fields.
- * 3. oneof fields.
- *
- * OPT: There is a lot of room for optimization here to minimize the size.
- */
-
- /* Allocate hasbits and set basic field attributes. */
- submsg_count = 0;
- for (upb_msg_field_begin(&it, m), hasbit = 0;
- !upb_msg_field_done(&it);
- upb_msg_field_next(&it)) {
- const upb_fielddef* f = upb_msg_iter_field(&it);
- upb_msglayout_fieldinit_v1 *field = &fields[upb_fielddef_index(f)];
-
- field->number = upb_fielddef_number(f);
- field->descriptortype = upb_fielddef_descriptortype(f);
- field->label = upb_fielddef_label(f);
-
- if (upb_fielddef_containingoneof(f)) {
- field->oneof_index = upb_oneofdef_index(upb_fielddef_containingoneof(f));
- } else {
- field->oneof_index = UPB_NOT_IN_ONEOF;
- }
-
- if (upb_fielddef_issubmsg(f)) {
- const upb_msglayout *sub_layout =
- upb_msgfactory_getlayout(factory, upb_fielddef_msgsubdef(f));
- field->submsg_index = submsg_count++;
- submsgs[field->submsg_index] = &sub_layout->data;
- } else {
- field->submsg_index = UPB_NO_SUBMSG;
- }
-
- if (upb_fielddef_haspresence(f) && !upb_fielddef_containingoneof(f)) {
- field->hasbit = hasbit++;
- } else {
- field->hasbit = UPB_NO_HASBIT;
- }
- }
-
- /* Account for space used by hasbits. */
- l->data.size = div_round_up(hasbit, 8);
-
- /* Allocate non-oneof fields. */
- for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it);
- upb_msg_field_next(&it)) {
- const upb_fielddef* f = upb_msg_iter_field(&it);
- size_t field_size = upb_msg_fielddefsize(f);
- size_t index = upb_fielddef_index(f);
-
- if (upb_fielddef_containingoneof(f)) {
- /* Oneofs are handled separately below. */
- continue;
- }
-
- fields[index].offset = upb_msglayout_place(l, field_size);
- }
-
- /* Allocate oneof fields. Each oneof field consists of a uint32 for the case
- * and space for the actual data. */
- for (upb_msg_oneof_begin(&oit, m); !upb_msg_oneof_done(&oit);
- upb_msg_oneof_next(&oit)) {
- const upb_oneofdef* o = upb_msg_iter_oneof(&oit);
- upb_oneof_iter fit;
-
- size_t case_size = sizeof(uint32_t); /* Could potentially optimize this. */
- upb_msglayout_oneofinit_v1 *oneof = &oneofs[upb_oneofdef_index(o)];
- size_t field_size = 0;
-
- /* Calculate field size: the max of all field sizes. */
- for (upb_oneof_begin(&fit, o);
- !upb_oneof_done(&fit);
- upb_oneof_next(&fit)) {
- const upb_fielddef* f = upb_oneof_iter_field(&fit);
- field_size = UPB_MAX(field_size, upb_msg_fielddefsize(f));
- }
-
- /* Align and allocate case offset. */
- oneof->case_offset = upb_msglayout_place(l, case_size);
- oneof->data_offset = upb_msglayout_place(l, field_size);
- }
-
- /* Size of the entire structure should be a multiple of its greatest
- * alignment. TODO: track overall alignment for real? */
- l->data.size = align_up(l->data.size, 8);
-
- return upb_msglayout_initdefault(l, m);
-}
-
-
-/** upb_msgfactory ************************************************************/
-
-struct upb_msgfactory {
- const upb_symtab *symtab; /* We own a ref. */
- upb_inttable layouts;
- upb_inttable mergehandlers;
-};
-
-upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab) {
- upb_msgfactory *ret = upb_gmalloc(sizeof(*ret));
-
- ret->symtab = symtab;
- upb_inttable_init(&ret->layouts, UPB_CTYPE_PTR);
- upb_inttable_init(&ret->mergehandlers, UPB_CTYPE_CONSTPTR);
-
- return ret;
-}
-
-void upb_msgfactory_free(upb_msgfactory *f) {
- upb_inttable_iter i;
- upb_inttable_begin(&i, &f->layouts);
- for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
- upb_msglayout *l = upb_value_getptr(upb_inttable_iter_value(&i));
- upb_msglayout_free(l);
- }
-
- upb_inttable_begin(&i, &f->mergehandlers);
- for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
- const upb_handlers *h = upb_value_getconstptr(upb_inttable_iter_value(&i));
- upb_handlers_unref(h, f);
- }
-
- upb_inttable_uninit(&f->layouts);
- upb_inttable_uninit(&f->mergehandlers);
- upb_gfree(f);
-}
-
-const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f) {
- return f->symtab;
-}
-
-const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f,
- const upb_msgdef *m) {
- upb_value v;
- UPB_ASSERT(upb_symtab_lookupmsg(f->symtab, upb_msgdef_fullname(m)) == m);
- UPB_ASSERT(!upb_msgdef_mapentry(m));
-
- if (upb_inttable_lookupptr(&f->layouts, m, &v)) {
- UPB_ASSERT(upb_value_getptr(v));
- return upb_value_getptr(v);
- } else {
- /* In case of circular dependency, layout has to be inserted first. */
- upb_msglayout *l = upb_gmalloc(sizeof(*l));
- upb_msgfactory *mutable_f = (void*)f;
- upb_inttable_insertptr(&mutable_f->layouts, m, upb_value_ptr(l));
- UPB_ASSERT(l);
- if (!upb_msglayout_init(m, l, f)) {
- upb_msglayout_free(l);
- }
- return l;
- }
-}
-
-/* Our handlers that we don't expose externally. */
-
-void *upb_msg_startstr(void *msg, const void *hd, size_t size_hint) {
- uint32_t ofs = (uintptr_t)hd;
- upb_alloc *alloc = upb_msg_alloc(msg);
- upb_msgval val;
- UPB_UNUSED(size_hint);
-
- val = upb_msgval_read(msg, ofs, upb_msgval_sizeof(UPB_TYPE_STRING));
-
- upb_free(alloc, (void*)val.str.data);
- val.str.data = NULL;
- val.str.size = 0;
-
- upb_msgval_write(msg, ofs, val, upb_msgval_sizeof(UPB_TYPE_STRING));
- return msg;
-}
-
-size_t upb_msg_str(void *msg, const void *hd, const char *ptr, size_t size,
- const upb_bufhandle *handle) {
- uint32_t ofs = (uintptr_t)hd;
- upb_alloc *alloc = upb_msg_alloc(msg);
- upb_msgval val;
- size_t newsize;
- UPB_UNUSED(handle);
-
- val = upb_msgval_read(msg, ofs, upb_msgval_sizeof(UPB_TYPE_STRING));
-
- newsize = val.str.size + size;
- val.str.data = upb_realloc(alloc, (void*)val.str.data, val.str.size, newsize);
-
- if (!val.str.data) {
- return false;
- }
-
- memcpy((char*)val.str.data + val.str.size, ptr, size);
- val.str.size = newsize;
- upb_msgval_write(msg, ofs, val, upb_msgval_sizeof(UPB_TYPE_STRING));
- return size;
-}
-
-static void callback(const void *closure, upb_handlers *h) {
- upb_msgfactory *factory = (upb_msgfactory*)closure;
- const upb_msgdef *md = upb_handlers_msgdef(h);
- const upb_msglayout* layout = upb_msgfactory_getlayout(factory, md);
- upb_msg_field_iter i;
- UPB_UNUSED(factory);
-
- for(upb_msg_field_begin(&i, md);
- !upb_msg_field_done(&i);
- upb_msg_field_next(&i)) {
- const upb_fielddef *f = upb_msg_iter_field(&i);
- size_t offset = upb_msglayout_offset(layout, f);
- upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
- upb_handlerattr_sethandlerdata(&attr, (void*)offset);
-
- if (upb_fielddef_isseq(f)) {
- } else if (upb_fielddef_isstring(f)) {
- upb_handlers_setstartstr(h, f, upb_msg_startstr, &attr);
- upb_handlers_setstring(h, f, upb_msg_str, &attr);
- } else {
- upb_msg_setscalarhandler(
- h, f, offset, upb_msglayout_hasbit(layout, f));
- }
- }
-}
-
-const upb_handlers *upb_msgfactory_getmergehandlers(upb_msgfactory *f,
- const upb_msgdef *m) {
- upb_msgfactory *mutable_f = (void*)f;
-
- /* TODO(haberman): properly cache these. */
- const upb_handlers *ret = upb_handlers_newfrozen(m, f, callback, f);
- upb_inttable_push(&mutable_f->mergehandlers, upb_value_constptr(ret));
-
- return ret;
-}
-
-const upb_visitorplan *upb_msgfactory_getvisitorplan(upb_msgfactory *f,
- const upb_handlers *h) {
- const upb_msgdef *md = upb_handlers_msgdef(h);
- return (const upb_visitorplan*)upb_msgfactory_getlayout(f, md);
-}
-
-
-/** upb_visitor ***************************************************************/
-
-struct upb_visitor {
- const upb_msglayout *layout;
- upb_sink *sink;
-};
-
-static upb_selector_t getsel2(const upb_fielddef *f, upb_handlertype_t type) {
- upb_selector_t ret;
- bool ok = upb_handlers_getselector(f, type, &ret);
- UPB_ASSERT(ok);
- return ret;
-}
-
-static bool upb_visitor_hasfield(const upb_msg *msg, const upb_fielddef *f,
- const upb_msglayout *layout) {
- int field_index = upb_fielddef_index(f);
- if (upb_fielddef_isseq(f)) {
- return upb_msgval_getarr(upb_msg_get(msg, field_index, layout)) != NULL;
- } else if (upb_msgdef_syntax(upb_fielddef_containingtype(f)) ==
- UPB_SYNTAX_PROTO2) {
- return upb_msg_has(msg, field_index, layout);
- } else {
- upb_msgval val = upb_msg_get(msg, field_index, layout);
- switch (upb_fielddef_type(f)) {
- case UPB_TYPE_FLOAT:
- return upb_msgval_getfloat(val) != 0;
- case UPB_TYPE_DOUBLE:
- return upb_msgval_getdouble(val) != 0;
- case UPB_TYPE_BOOL:
- return upb_msgval_getbool(val);
- case UPB_TYPE_ENUM:
- case UPB_TYPE_INT32:
- return upb_msgval_getint32(val) != 0;
- case UPB_TYPE_UINT32:
- return upb_msgval_getuint32(val) != 0;
- case UPB_TYPE_INT64:
- return upb_msgval_getint64(val) != 0;
- case UPB_TYPE_UINT64:
- return upb_msgval_getuint64(val) != 0;
- case UPB_TYPE_STRING:
- case UPB_TYPE_BYTES:
- return upb_msgval_getstr(val).size > 0;
- case UPB_TYPE_MESSAGE:
- return upb_msgval_getmsg(val) != NULL;
- }
- UPB_UNREACHABLE();
- }
-}
-
-static bool upb_visitor_visitmsg2(const upb_msg *msg,
- const upb_msglayout *layout, upb_sink *sink,
- int depth) {
- const upb_msgdef *md = upb_handlers_msgdef(sink->handlers);
- upb_msg_field_iter i;
- upb_status status;
-
- upb_sink_startmsg(sink);
-
- /* Protect against cycles (possible because users may freely reassign message
- * and repeated fields) by imposing a maximum recursion depth. */
- if (depth > ENCODE_MAX_NESTING) {
- return false;
- }
-
- for (upb_msg_field_begin(&i, md);
- !upb_msg_field_done(&i);
- upb_msg_field_next(&i)) {
- upb_fielddef *f = upb_msg_iter_field(&i);
- upb_msgval val;
-
- if (!upb_visitor_hasfield(msg, f, layout)) {
- continue;
- }
-
- val = upb_msg_get(msg, upb_fielddef_index(f), layout);
-
- if (upb_fielddef_isseq(f)) {
- const upb_array *arr = upb_msgval_getarr(val);
- UPB_ASSERT(arr);
- /* TODO: putary(ary, f, sink, depth);*/
- } else if (upb_fielddef_issubmsg(f)) {
- const upb_map *map = upb_msgval_getmap(val);
- UPB_ASSERT(map);
- /* TODO: putmap(map, f, sink, depth);*/
- } else if (upb_fielddef_isstring(f)) {
- /* TODO putstr(); */
- } else {
- upb_selector_t sel = getsel2(f, upb_handlers_getprimitivehandlertype(f));
- UPB_ASSERT(upb_fielddef_isprimitive(f));
-
- switch (upb_fielddef_type(f)) {
- case UPB_TYPE_FLOAT:
- CHECK_TRUE(upb_sink_putfloat(sink, sel, upb_msgval_getfloat(val)));
- break;
- case UPB_TYPE_DOUBLE:
- CHECK_TRUE(upb_sink_putdouble(sink, sel, upb_msgval_getdouble(val)));
- break;
- case UPB_TYPE_BOOL:
- CHECK_TRUE(upb_sink_putbool(sink, sel, upb_msgval_getbool(val)));
- break;
- case UPB_TYPE_ENUM:
- case UPB_TYPE_INT32:
- CHECK_TRUE(upb_sink_putint32(sink, sel, upb_msgval_getint32(val)));
- break;
- case UPB_TYPE_UINT32:
- CHECK_TRUE(upb_sink_putuint32(sink, sel, upb_msgval_getuint32(val)));
- break;
- case UPB_TYPE_INT64:
- CHECK_TRUE(upb_sink_putint64(sink, sel, upb_msgval_getint64(val)));
- break;
- case UPB_TYPE_UINT64:
- CHECK_TRUE(upb_sink_putuint64(sink, sel, upb_msgval_getuint64(val)));
- break;
- case UPB_TYPE_STRING:
- case UPB_TYPE_BYTES:
- case UPB_TYPE_MESSAGE:
- UPB_UNREACHABLE();
- }
- }
- }
-
- upb_sink_endmsg(sink, &status);
- return true;
-}
-
-upb_visitor *upb_visitor_create(upb_env *e, const upb_visitorplan *vp,
- upb_sink *output) {
- upb_visitor *visitor = upb_env_malloc(e, sizeof(*visitor));
- visitor->layout = (const upb_msglayout*)vp;
- visitor->sink = output;
- return visitor;
-}
-
-bool upb_visitor_visitmsg(upb_visitor *visitor, const upb_msg *msg) {
- return upb_visitor_visitmsg2(msg, visitor->layout, visitor->sink, 0);
-}
-
/** upb_msg *******************************************************************/
@@ -6619,8 +4802,12 @@ bool upb_visitor_visitmsg(upb_visitor *visitor, const upb_msg *msg) {
/* Used when a message is not extendable. */
typedef struct {
- /* TODO(haberman): add unknown fields. */
- upb_alloc *alloc;
+ /* TODO(haberman): use pointer tagging so we we are slim when known unknown
+ * fields are not present. */
+ upb_arena *arena;
+ char *unknown;
+ size_t unknown_len;
+ size_t unknown_size;
} upb_msg_internal;
/* Used when a message is extendable. */
@@ -6630,7 +4817,7 @@ typedef struct {
} upb_msg_internal_withext;
static int upb_msg_internalsize(const upb_msglayout *l) {
- return sizeof(upb_msg_internal) - l->data.extendable * sizeof(void*);
+ return sizeof(upb_msg_internal) - l->extendable * sizeof(void *);
}
static upb_msg_internal *upb_msg_getinternal(upb_msg *msg) {
@@ -6643,123 +4830,112 @@ static const upb_msg_internal *upb_msg_getinternal_const(const upb_msg *msg) {
static upb_msg_internal_withext *upb_msg_getinternalwithext(
upb_msg *msg, const upb_msglayout *l) {
- UPB_ASSERT(l->data.extendable);
+ UPB_ASSERT(l->extendable);
return VOIDPTR_AT(msg, -sizeof(upb_msg_internal_withext));
}
-static const upb_msglayout_fieldinit_v1 *upb_msg_checkfield(
- int field_index, const upb_msglayout *l) {
- UPB_ASSERT(field_index >= 0 && field_index < l->data.field_count);
- return &l->data.fields[field_index];
+void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len) {
+ upb_msg_internal* in = upb_msg_getinternal(msg);
+ if (len > in->unknown_size - in->unknown_len) {
+ upb_alloc *alloc = upb_arena_alloc(in->arena);
+ size_t need = in->unknown_size + len;
+ size_t newsize = UPB_MAX(in->unknown_size * 2, need);
+ in->unknown = upb_realloc(alloc, in->unknown, in->unknown_size, newsize);
+ in->unknown_size = newsize;
+ }
+ memcpy(in->unknown + in->unknown_len, data, len);
+ in->unknown_len += len;
+}
+
+const char *upb_msg_getunknown(const upb_msg *msg, size_t *len) {
+ const upb_msg_internal* in = upb_msg_getinternal_const(msg);
+ *len = in->unknown_len;
+ return in->unknown;
+}
+
+static const upb_msglayout_field *upb_msg_checkfield(int field_index,
+ const upb_msglayout *l) {
+ UPB_ASSERT(field_index >= 0 && field_index < l->field_count);
+ return &l->fields[field_index];
}
-static bool upb_msg_inoneof(const upb_msglayout_fieldinit_v1 *field) {
- return field->oneof_index != UPB_NOT_IN_ONEOF;
+static bool upb_msg_inoneof(const upb_msglayout_field *field) {
+ return field->presence < 0;
}
static uint32_t *upb_msg_oneofcase(const upb_msg *msg, int field_index,
const upb_msglayout *l) {
- const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l);
+ const upb_msglayout_field *field = upb_msg_checkfield(field_index, l);
UPB_ASSERT(upb_msg_inoneof(field));
- return PTR_AT(msg, l->data.oneofs[field->oneof_index].case_offset, uint32_t);
+ return PTR_AT(msg, ~field->presence, uint32_t);
}
-size_t upb_msg_sizeof(const upb_msglayout *l) {
- return l->data.size + upb_msg_internalsize(l);
+static size_t upb_msg_sizeof(const upb_msglayout *l) {
+ return l->size + upb_msg_internalsize(l);
}
-upb_msg *upb_msg_init(void *mem, const upb_msglayout *l, upb_alloc *a) {
- upb_msg *msg = VOIDPTR_AT(mem, upb_msg_internalsize(l));
+upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a) {
+ upb_alloc *alloc = upb_arena_alloc(a);
+ void *mem = upb_malloc(alloc, upb_msg_sizeof(l));
+ upb_msg_internal *in;
+ upb_msg *msg;
- /* Initialize normal members. */
- if (l->data.default_msg) {
- memcpy(msg, l->data.default_msg, l->data.size);
- } else {
- memset(msg, 0, l->data.size);
+ if (!mem) {
+ return NULL;
}
+ msg = VOIDPTR_AT(mem, upb_msg_internalsize(l));
+
+ /* Initialize normal members. */
+ memset(msg, 0, l->size);
+
/* Initialize internal members. */
- upb_msg_getinternal(msg)->alloc = a;
+ in = upb_msg_getinternal(msg);
+ in->arena = a;
+ in->unknown = NULL;
+ in->unknown_len = 0;
+ in->unknown_size = 0;
- if (l->data.extendable) {
+ if (l->extendable) {
upb_msg_getinternalwithext(msg, l)->extdict = NULL;
}
return msg;
}
-void *upb_msg_uninit(upb_msg *msg, const upb_msglayout *l) {
- if (l->data.extendable) {
- upb_inttable *ext_dict = upb_msg_getinternalwithext(msg, l)->extdict;
- if (ext_dict) {
- upb_inttable_uninit2(ext_dict, upb_msg_alloc(msg));
- upb_free(upb_msg_alloc(msg), ext_dict);
- }
- }
-
- return VOIDPTR_AT(msg, -upb_msg_internalsize(l));
-}
-
-upb_msg *upb_msg_new(const upb_msglayout *l, upb_alloc *a) {
- void *mem = upb_malloc(a, upb_msg_sizeof(l));
- return mem ? upb_msg_init(mem, l, a) : NULL;
-}
-
-void upb_msg_free(upb_msg *msg, const upb_msglayout *l) {
- upb_free(upb_msg_alloc(msg), upb_msg_uninit(msg, l));
-}
-
-upb_alloc *upb_msg_alloc(const upb_msg *msg) {
- return upb_msg_getinternal_const(msg)->alloc;
+upb_arena *upb_msg_arena(const upb_msg *msg) {
+ return upb_msg_getinternal_const(msg)->arena;
}
bool upb_msg_has(const upb_msg *msg,
int field_index,
const upb_msglayout *l) {
- const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l);
+ const upb_msglayout_field *field = upb_msg_checkfield(field_index, l);
- UPB_ASSERT(l->data.is_proto2);
+ UPB_ASSERT(field->presence);
if (upb_msg_inoneof(field)) {
/* Oneofs are set when the oneof number is set to this field. */
return *upb_msg_oneofcase(msg, field_index, l) == field->number;
} else {
/* Other fields are set when their hasbit is set. */
- uint32_t hasbit = l->data.fields[field_index].hasbit;
+ uint32_t hasbit = field->presence;
return DEREF(msg, hasbit / 8, char) | (1 << (hasbit % 8));
}
}
upb_msgval upb_msg_get(const upb_msg *msg, int field_index,
const upb_msglayout *l) {
- const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l);
+ const upb_msglayout_field *field = upb_msg_checkfield(field_index, l);
int size = upb_msg_fieldsize(field);
-
- if (upb_msg_inoneof(field)) {
- if (*upb_msg_oneofcase(msg, field_index, l) == field->number) {
- size_t ofs = l->data.oneofs[field->oneof_index].data_offset;
- return upb_msgval_read(msg, ofs, size);
- } else {
- /* Return default. */
- return upb_msgval_read(l->data.default_msg, field->offset, size);
- }
- } else {
- return upb_msgval_read(msg, field->offset, size);
- }
+ return upb_msgval_read(msg, field->offset, size);
}
void upb_msg_set(upb_msg *msg, int field_index, upb_msgval val,
const upb_msglayout *l) {
- const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l);
+ const upb_msglayout_field *field = upb_msg_checkfield(field_index, l);
int size = upb_msg_fieldsize(field);
-
- if (upb_msg_inoneof(field)) {
- size_t ofs = l->data.oneofs[field->oneof_index].data_offset;
- *upb_msg_oneofcase(msg, field_index, l) = field->number;
- upb_msgval_write(msg, ofs, val, size);
- } else {
- upb_msgval_write(msg, field->offset, val, size);
- }
+ upb_msgval_write(msg, field->offset, val, size);
}
@@ -6767,37 +4943,22 @@ void upb_msg_set(upb_msg *msg, int field_index, upb_msgval val,
#define DEREF_ARR(arr, i, type) ((type*)arr->data)[i]
-size_t upb_array_sizeof(upb_fieldtype_t type) {
- UPB_UNUSED(type);
- return sizeof(upb_array);
-}
+upb_array *upb_array_new(upb_fieldtype_t type, upb_arena *a) {
+ upb_alloc *alloc = upb_arena_alloc(a);
+ upb_array *ret = upb_malloc(alloc, sizeof(upb_array));
-void upb_array_init(upb_array *arr, upb_fieldtype_t type, upb_alloc *alloc) {
- arr->type = type;
- arr->data = NULL;
- arr->len = 0;
- arr->size = 0;
- arr->element_size = upb_msgval_sizeof(type);
- arr->alloc = alloc;
-}
-
-void upb_array_uninit(upb_array *arr) {
- upb_free(arr->alloc, arr->data);
-}
-
-upb_array *upb_array_new(upb_fieldtype_t type, upb_alloc *a) {
- upb_array *ret = upb_malloc(a, upb_array_sizeof(type));
-
- if (ret) {
- upb_array_init(ret, type, a);
+ if (!ret) {
+ return NULL;
}
- return ret;
-}
+ ret->type = type;
+ ret->data = NULL;
+ ret->len = 0;
+ ret->size = 0;
+ ret->element_size = upb_msgval_sizeof(type);
+ ret->arena = a;
-void upb_array_free(upb_array *arr) {
- upb_array_uninit(arr);
- upb_free(arr->alloc, arr);
+ return ret;
}
size_t upb_array_size(const upb_array *arr) {
@@ -6824,8 +4985,9 @@ bool upb_array_set(upb_array *arr, size_t i, upb_msgval val) {
size_t new_size = UPB_MAX(arr->size * 2, 8);
size_t new_bytes = new_size * arr->element_size;
size_t old_bytes = arr->size * arr->element_size;
+ upb_alloc *alloc = upb_arena_alloc(arr->arena);
upb_msgval *new_data =
- upb_realloc(arr->alloc, arr->data, old_bytes, new_bytes);
+ upb_realloc(alloc, arr->data, old_bytes, new_bytes);
if (!new_data) {
return false;
@@ -6851,7 +5013,7 @@ struct upb_map {
/* We may want to optimize this to use inttable where possible, for greater
* efficiency and lower memory footprint. */
upb_strtable strtab;
- upb_alloc *alloc;
+ upb_arena *arena;
};
static void upb_map_tokey(upb_fieldtype_t type, upb_msgval *key,
@@ -6902,52 +5064,28 @@ static upb_msgval upb_map_fromkey(upb_fieldtype_t type, const char *key,
UPB_UNREACHABLE();
}
-size_t upb_map_sizeof(upb_fieldtype_t ktype, upb_fieldtype_t vtype) {
- /* Size does not currently depend on key/value type. */
- UPB_UNUSED(ktype);
- UPB_UNUSED(vtype);
- return sizeof(upb_map);
-}
-
-bool upb_map_init(upb_map *map, upb_fieldtype_t ktype, upb_fieldtype_t vtype,
- upb_alloc *a) {
- upb_ctype_t vtabtype = upb_fieldtotabtype(vtype);
- UPB_ASSERT(upb_fieldtype_mapkeyok(ktype));
- map->key_type = ktype;
- map->val_type = vtype;
- map->alloc = a;
-
- if (!upb_strtable_init2(&map->strtab, vtabtype, a)) {
- return false;
- }
-
- return true;
-}
-
-void upb_map_uninit(upb_map *map) {
- upb_strtable_uninit2(&map->strtab, map->alloc);
-}
-
upb_map *upb_map_new(upb_fieldtype_t ktype, upb_fieldtype_t vtype,
- upb_alloc *a) {
- upb_map *map = upb_malloc(a, upb_map_sizeof(ktype, vtype));
+ upb_arena *a) {
+ upb_ctype_t vtabtype = upb_fieldtotabtype(vtype);
+ upb_alloc *alloc = upb_arena_alloc(a);
+ upb_map *map = upb_malloc(alloc, sizeof(upb_map));
if (!map) {
return NULL;
}
- if (!upb_map_init(map, ktype, vtype, a)) {
+ UPB_ASSERT(upb_fieldtype_mapkeyok(ktype));
+ map->key_type = ktype;
+ map->val_type = vtype;
+ map->arena = a;
+
+ if (!upb_strtable_init2(&map->strtab, vtabtype, alloc)) {
return NULL;
}
return map;
}
-void upb_map_free(upb_map *map) {
- upb_map_uninit(map);
- upb_free(map->alloc, map);
-}
-
size_t upb_map_size(const upb_map *map) {
return upb_strtable_count(&map->strtab);
}
@@ -6981,7 +5119,7 @@ bool upb_map_set(upb_map *map, upb_msgval key, upb_msgval val,
size_t key_len;
upb_value tabval = upb_toval(val);
upb_value removedtabval;
- upb_alloc *a = map->alloc;
+ upb_alloc *a = upb_arena_alloc(map->arena);
upb_map_tokey(map->key_type, &key, &key_str, &key_len);
@@ -6997,7 +5135,7 @@ bool upb_map_set(upb_map *map, upb_msgval key, upb_msgval val,
bool upb_map_del(upb_map *map, upb_msgval key) {
const char *key_str;
size_t key_len;
- upb_alloc *a = map->alloc;
+ upb_alloc *a = upb_arena_alloc(map->arena);
upb_map_tokey(map->key_type, &key, &key_str, &key_len);
return upb_strtable_remove3(&map->strtab, key_str, key_len, NULL, a);
@@ -7061,100 +5199,258 @@ bool upb_mapiter_isequal(const upb_mapiter *i1, const upb_mapiter *i2) {
}
-/** Handlers for upb_msg ******************************************************/
+static bool is_power_of_two(size_t val) {
+ return (val & (val - 1)) == 0;
+}
-typedef struct {
- size_t offset;
- int32_t hasbit;
-} upb_msg_handlerdata;
+/* Align up to the given power of 2. */
+static size_t align_up(size_t val, size_t align) {
+ UPB_ASSERT(is_power_of_two(align));
+ return (val + align - 1) & ~(align - 1);
+}
-/* Fallback implementation if the handler is not specialized by the producer. */
-#define MSG_WRITER(type, ctype) \
- bool upb_msg_set ## type (void *c, const void *hd, ctype val) { \
- uint8_t *m = c; \
- const upb_msg_handlerdata *d = hd; \
- if (d->hasbit > 0) \
- *(uint8_t*)&m[d->hasbit / 8] |= 1 << (d->hasbit % 8); \
- *(ctype*)&m[d->offset] = val; \
- return true; \
- } \
+static size_t div_round_up(size_t n, size_t d) {
+ return (n + d - 1) / d;
+}
-MSG_WRITER(double, double)
-MSG_WRITER(float, float)
-MSG_WRITER(int32, int32_t)
-MSG_WRITER(int64, int64_t)
-MSG_WRITER(uint32, uint32_t)
-MSG_WRITER(uint64, uint64_t)
-MSG_WRITER(bool, bool)
+static size_t upb_msgval_sizeof2(upb_fieldtype_t type) {
+ switch (type) {
+ case UPB_TYPE_DOUBLE:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT64:
+ return 8;
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_FLOAT:
+ return 4;
+ case UPB_TYPE_BOOL:
+ return 1;
+ case UPB_TYPE_MESSAGE:
+ return sizeof(void*);
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_STRING:
+ return sizeof(upb_stringview);
+ }
+ UPB_UNREACHABLE();
+}
-bool upb_msg_setscalarhandler(upb_handlers *h, const upb_fielddef *f,
- size_t offset, int32_t hasbit) {
- upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
- bool ok;
+static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) {
+ if (upb_fielddef_isseq(f)) {
+ return sizeof(void*);
+ } else {
+ return upb_msgval_sizeof2(upb_fielddef_type(f));
+ }
+}
- upb_msg_handlerdata *d = upb_gmalloc(sizeof(*d));
- if (!d) return false;
- d->offset = offset;
- d->hasbit = hasbit;
- upb_handlerattr_sethandlerdata(&attr, d);
- upb_handlerattr_setalwaysok(&attr, true);
- upb_handlers_addcleanup(h, d, upb_gfree);
+/** upb_msglayout *************************************************************/
-#define TYPE(u, l) \
- case UPB_TYPE_##u: \
- ok = upb_handlers_set##l(h, f, upb_msg_set##l, &attr); break;
+static void upb_msglayout_free(upb_msglayout *l) {
+ upb_gfree(l);
+}
- ok = false;
+static size_t upb_msglayout_place(upb_msglayout *l, size_t size) {
+ size_t ret;
- switch (upb_fielddef_type(f)) {
- TYPE(INT64, int64);
- TYPE(INT32, int32);
- TYPE(ENUM, int32);
- TYPE(UINT64, uint64);
- TYPE(UINT32, uint32);
- TYPE(DOUBLE, double);
- TYPE(FLOAT, float);
- TYPE(BOOL, bool);
- default: UPB_ASSERT(false); break;
+ l->size = align_up(l->size, size);
+ ret = l->size;
+ l->size += size;
+ return ret;
+}
+
+static bool upb_msglayout_init(const upb_msgdef *m,
+ upb_msglayout *l,
+ upb_msgfactory *factory) {
+ upb_msg_field_iter it;
+ upb_msg_oneof_iter oit;
+ size_t hasbit;
+ size_t submsg_count = 0;
+ const upb_msglayout **submsgs;
+ upb_msglayout_field *fields;
+
+ for (upb_msg_field_begin(&it, m);
+ !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* f = upb_msg_iter_field(&it);
+ if (upb_fielddef_issubmsg(f)) {
+ submsg_count++;
+ }
}
-#undef TYPE
- upb_handlerattr_uninit(&attr);
- return ok;
-}
+ memset(l, 0, sizeof(*l));
-bool upb_msg_getscalarhandlerdata(const upb_handlers *h,
- upb_selector_t s,
- upb_fieldtype_t *type,
- size_t *offset,
- int32_t *hasbit) {
- const upb_msg_handlerdata *d;
- upb_func *f = upb_handlers_gethandler(h, s);
+ fields = upb_gmalloc(upb_msgdef_numfields(m) * sizeof(*fields));
+ submsgs = upb_gmalloc(submsg_count * sizeof(*submsgs));
- if ((upb_int64_handlerfunc*)f == upb_msg_setint64) {
- *type = UPB_TYPE_INT64;
- } else if ((upb_int32_handlerfunc*)f == upb_msg_setint32) {
- *type = UPB_TYPE_INT32;
- } else if ((upb_uint64_handlerfunc*)f == upb_msg_setuint64) {
- *type = UPB_TYPE_UINT64;
- } else if ((upb_uint32_handlerfunc*)f == upb_msg_setuint32) {
- *type = UPB_TYPE_UINT32;
- } else if ((upb_double_handlerfunc*)f == upb_msg_setdouble) {
- *type = UPB_TYPE_DOUBLE;
- } else if ((upb_float_handlerfunc*)f == upb_msg_setfloat) {
- *type = UPB_TYPE_FLOAT;
- } else if ((upb_bool_handlerfunc*)f == upb_msg_setbool) {
- *type = UPB_TYPE_BOOL;
- } else {
+ if ((!fields && upb_msgdef_numfields(m)) ||
+ (!submsgs && submsg_count)) {
+ /* OOM. */
+ upb_gfree(fields);
+ upb_gfree(submsgs);
return false;
}
- d = upb_handlers_gethandlerdata(h, s);
- *offset = d->offset;
- *hasbit = d->hasbit;
+ l->field_count = upb_msgdef_numfields(m);
+ l->fields = fields;
+ l->submsgs = submsgs;
+
+ /* Allocate data offsets in three stages:
+ *
+ * 1. hasbits.
+ * 2. regular fields.
+ * 3. oneof fields.
+ *
+ * OPT: There is a lot of room for optimization here to minimize the size.
+ */
+
+ /* Allocate hasbits and set basic field attributes. */
+ submsg_count = 0;
+ for (upb_msg_field_begin(&it, m), hasbit = 0;
+ !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* f = upb_msg_iter_field(&it);
+ upb_msglayout_field *field = &fields[upb_fielddef_index(f)];
+
+ field->number = upb_fielddef_number(f);
+ field->descriptortype = upb_fielddef_descriptortype(f);
+ field->label = upb_fielddef_label(f);
+
+ if (upb_fielddef_issubmsg(f)) {
+ const upb_msglayout *sub_layout =
+ upb_msgfactory_getlayout(factory, upb_fielddef_msgsubdef(f));
+ field->submsg_index = submsg_count++;
+ submsgs[field->submsg_index] = sub_layout;
+ }
+
+ if (upb_fielddef_haspresence(f) && !upb_fielddef_containingoneof(f)) {
+ field->presence = (hasbit++);
+ } else {
+ field->presence = 0;
+ }
+ }
+
+ /* Account for space used by hasbits. */
+ l->size = div_round_up(hasbit, 8);
+
+ /* Allocate non-oneof fields. */
+ for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* f = upb_msg_iter_field(&it);
+ size_t field_size = upb_msg_fielddefsize(f);
+ size_t index = upb_fielddef_index(f);
+
+ if (upb_fielddef_containingoneof(f)) {
+ /* Oneofs are handled separately below. */
+ continue;
+ }
+
+ fields[index].offset = upb_msglayout_place(l, field_size);
+ }
+
+ /* Allocate oneof fields. Each oneof field consists of a uint32 for the case
+ * and space for the actual data. */
+ for (upb_msg_oneof_begin(&oit, m); !upb_msg_oneof_done(&oit);
+ upb_msg_oneof_next(&oit)) {
+ const upb_oneofdef* o = upb_msg_iter_oneof(&oit);
+ upb_oneof_iter fit;
+
+ size_t case_size = sizeof(uint32_t); /* Could potentially optimize this. */
+ size_t field_size = 0;
+ uint32_t case_offset;
+ uint32_t data_offset;
+
+ /* Calculate field size: the max of all field sizes. */
+ for (upb_oneof_begin(&fit, o);
+ !upb_oneof_done(&fit);
+ upb_oneof_next(&fit)) {
+ const upb_fielddef* f = upb_oneof_iter_field(&fit);
+ field_size = UPB_MAX(field_size, upb_msg_fielddefsize(f));
+ }
+
+ /* Align and allocate case offset. */
+ case_offset = upb_msglayout_place(l, case_size);
+ data_offset = upb_msglayout_place(l, field_size);
+
+ for (upb_oneof_begin(&fit, o);
+ !upb_oneof_done(&fit);
+ upb_oneof_next(&fit)) {
+ const upb_fielddef* f = upb_oneof_iter_field(&fit);
+ fields[upb_fielddef_index(f)].offset = data_offset;
+ fields[upb_fielddef_index(f)].presence = ~case_offset;
+ }
+ }
+
+ /* Size of the entire structure should be a multiple of its greatest
+ * alignment. TODO: track overall alignment for real? */
+ l->size = align_up(l->size, 8);
+
return true;
}
+
+
+/** upb_msgfactory ************************************************************/
+
+struct upb_msgfactory {
+ const upb_symtab *symtab; /* We own a ref. */
+ upb_inttable layouts;
+ upb_inttable mergehandlers;
+};
+
+upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab) {
+ upb_msgfactory *ret = upb_gmalloc(sizeof(*ret));
+
+ ret->symtab = symtab;
+ upb_inttable_init(&ret->layouts, UPB_CTYPE_PTR);
+ upb_inttable_init(&ret->mergehandlers, UPB_CTYPE_CONSTPTR);
+
+ return ret;
+}
+
+void upb_msgfactory_free(upb_msgfactory *f) {
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, &f->layouts);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ upb_msglayout *l = upb_value_getptr(upb_inttable_iter_value(&i));
+ upb_msglayout_free(l);
+ }
+
+ upb_inttable_begin(&i, &f->mergehandlers);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ const upb_handlers *h = upb_value_getconstptr(upb_inttable_iter_value(&i));
+ upb_handlers_unref(h, f);
+ }
+
+ upb_inttable_uninit(&f->layouts);
+ upb_inttable_uninit(&f->mergehandlers);
+ upb_gfree(f);
+}
+
+const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f) {
+ return f->symtab;
+}
+
+const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f,
+ const upb_msgdef *m) {
+ upb_value v;
+ UPB_ASSERT(upb_symtab_lookupmsg(f->symtab, upb_msgdef_fullname(m)) == m);
+ UPB_ASSERT(!upb_msgdef_mapentry(m));
+
+ if (upb_inttable_lookupptr(&f->layouts, m, &v)) {
+ UPB_ASSERT(upb_value_getptr(v));
+ return upb_value_getptr(v);
+ } else {
+ /* In case of circular dependency, layout has to be inserted first. */
+ upb_msglayout *l = upb_gmalloc(sizeof(*l));
+ upb_msgfactory *mutable_f = (void*)f;
+ upb_inttable_insertptr(&mutable_f->layouts, m, upb_value_ptr(l));
+ UPB_ASSERT(l);
+ if (!upb_msglayout_init(m, l, f)) {
+ upb_msglayout_free(l);
+ }
+ return l;
+ }
+}
/*
** upb::RefCounted Implementation
**
@@ -8364,9 +6660,10 @@ static size_t begin(const upb_table *t) {
/* A simple "subclass" of upb_table that only adds a hash function for strings. */
static upb_tabkey strcopy(lookupkey_t k2, upb_alloc *a) {
+ uint32_t len = (uint32_t) k2.str.len;
char *str = upb_malloc(a, k2.str.len + sizeof(uint32_t) + 1);
if (str == NULL) return 0;
- memcpy(str, &k2.str.len, sizeof(uint32_t));
+ memcpy(str, &len, sizeof(uint32_t));
memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len + 1);
return (uintptr_t)str;
}
@@ -9345,28 +7642,28 @@ static upb_inttable reftables[268];
#endif
static const upb_msgdef msgs[22] = {
- UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 41, 8, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[0], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[0]), false, UPB_SYNTAX_PROTO2, &reftables[0], &reftables[1]),
- UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[11], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[16]), false, UPB_SYNTAX_PROTO2, &reftables[2], &reftables[3]),
- UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ReservedRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[14], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[20]), false, UPB_SYNTAX_PROTO2, &reftables[4], &reftables[5]),
- UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[17], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[24]), false, UPB_SYNTAX_PROTO2, &reftables[6], &reftables[7]),
- UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 9, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[0], &arrays[21], 4, 2), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[28]), false, UPB_SYNTAX_PROTO2, &reftables[8], &reftables[9]),
- UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 9, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[25], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[32]), false, UPB_SYNTAX_PROTO2, &reftables[10], &reftables[11]),
- UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 8, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[2], &arrays[29], 2, 1), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[36]), false, UPB_SYNTAX_PROTO2, &reftables[12], &reftables[13]),
- UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 24, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[31], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[40]), false, UPB_SYNTAX_PROTO2, &reftables[14], &reftables[15]),
- UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 13, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[4], &arrays[42], 11, 6), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[56]), false, UPB_SYNTAX_PROTO2, &reftables[16], &reftables[17]),
- UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 43, 6, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[53], 13, 12), UPB_STRTABLE_INIT(12, 15, UPB_CTYPE_PTR, 4, &strentries[72]), false, UPB_SYNTAX_PROTO2, &reftables[18], &reftables[19]),
- UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[66], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[88]), false, UPB_SYNTAX_PROTO2, &reftables[20], &reftables[21]),
- UPB_MSGDEF_INIT("google.protobuf.FileOptions", 38, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[68], 42, 17), UPB_STRTABLE_INIT(18, 31, UPB_CTYPE_PTR, 5, &strentries[92]), false, UPB_SYNTAX_PROTO2, &reftables[22], &reftables[23]),
- UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 11, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[8], &arrays[110], 8, 4), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[124]), false, UPB_SYNTAX_PROTO2, &reftables[24], &reftables[25]),
- UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 16, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[118], 7, 6), UPB_STRTABLE_INIT(6, 7, UPB_CTYPE_PTR, 3, &strentries[132]), false, UPB_SYNTAX_PROTO2, &reftables[26], &reftables[27]),
- UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[10], &arrays[125], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[140]), false, UPB_SYNTAX_PROTO2, &reftables[28], &reftables[29]),
- UPB_MSGDEF_INIT("google.protobuf.OneofDescriptorProto", 6, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[126], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[144]), false, UPB_SYNTAX_PROTO2, &reftables[30], &reftables[31]),
- UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[128], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[148]), false, UPB_SYNTAX_PROTO2, &reftables[32], &reftables[33]),
- UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[14], &arrays[132], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[152]), false, UPB_SYNTAX_PROTO2, &reftables[34], &reftables[35]),
- UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[133], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[156]), false, UPB_SYNTAX_PROTO2, &reftables[36], &reftables[37]),
- UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 20, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[135], 7, 5), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[160]), false, UPB_SYNTAX_PROTO2, &reftables[38], &reftables[39]),
- UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 19, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[142], 9, 7), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[168]), false, UPB_SYNTAX_PROTO2, &reftables[40], &reftables[41]),
- UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[151], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[184]), false, UPB_SYNTAX_PROTO2, &reftables[42], &reftables[43]),
+ UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 41, 8, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[0], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[0]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[0], &reftables[1]),
+ UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[11], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[16]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[2], &reftables[3]),
+ UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ReservedRange", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[14], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[20]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[4], &reftables[5]),
+ UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[17], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[24]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[6], &reftables[7]),
+ UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 9, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[0], &arrays[21], 4, 2), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[28]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[8], &reftables[9]),
+ UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 9, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[25], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[32]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[10], &reftables[11]),
+ UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 8, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[2], &arrays[29], 2, 1), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[36]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[12], &reftables[13]),
+ UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 24, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[31], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[40]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[14], &reftables[15]),
+ UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 13, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[4], &arrays[42], 11, 6), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[56]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[16], &reftables[17]),
+ UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 43, 6, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[53], 13, 12), UPB_STRTABLE_INIT(12, 15, UPB_CTYPE_PTR, 4, &strentries[72]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[18], &reftables[19]),
+ UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[66], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[88]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[20], &reftables[21]),
+ UPB_MSGDEF_INIT("google.protobuf.FileOptions", 38, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[68], 42, 17), UPB_STRTABLE_INIT(18, 31, UPB_CTYPE_PTR, 5, &strentries[92]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[22], &reftables[23]),
+ UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 11, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[8], &arrays[110], 8, 4), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[124]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[24], &reftables[25]),
+ UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 16, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[118], 7, 6), UPB_STRTABLE_INIT(6, 7, UPB_CTYPE_PTR, 3, &strentries[132]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[26], &reftables[27]),
+ UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[10], &arrays[125], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[140]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[28], &reftables[29]),
+ UPB_MSGDEF_INIT("google.protobuf.OneofDescriptorProto", 6, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[126], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[144]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[30], &reftables[31]),
+ UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 12, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[128], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[148]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[32], &reftables[33]),
+ UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 8, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[14], &arrays[132], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[152]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[34], &reftables[35]),
+ UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 7, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[133], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[156]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[36], &reftables[37]),
+ UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 20, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[135], 7, 5), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[160]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[38], &reftables[39]),
+ UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 19, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[142], 9, 7), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[168]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[40], &reftables[41]),
+ UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 7, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[151], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[184]), false, UPB_SYNTAX_PROTO2, UPB_WELLKNOWN_UNSPECIFIED, &reftables[42], &reftables[43]),
};
static const upb_fielddef fields[107] = {
@@ -10934,6 +9231,7 @@ static size_t msg_name(void *closure, const void *hd, const char *buf,
upb_def_setfullname(upb_msgdef_upcast_mutable(m), name, NULL);
upb_descreader_setscopename(r, name); /* Passes ownership of name. */
+
return n;
}
@@ -14248,7 +12546,7 @@ done:
return r;
}
-#line 1 "upb/json/parser.rl"
+//#line 1 "upb/json/parser.rl"
/*
** upb::json::Parser (upb_json_parser)
**
@@ -14274,24 +12572,33 @@ done:
#include <float.h>
#include <math.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+/* Need to define __USE_XOPEN before including time.h to make strptime work. */
+#ifndef __USE_XOPEN
+#define __USE_XOPEN
+#endif
+#include <time.h>
+
#define UPB_JSON_MAX_DEPTH 64
-static const char *kDoubleValueFullMessageName = "google.protobuf.DoubleValue";
-static const char *kFloatValueFullMessageName = "google.protobuf.FloatValue";
-static const char *kInt64ValueFullMessageName = "google.protobuf.Int64Value";
-static const char *kUInt64ValueFullMessageName = "google.protobuf.UInt64Value";
-static const char *kInt32ValueFullMessageName = "google.protobuf.Int32Value";
-static const char *kUInt32ValueFullMessageName = "google.protobuf.UInt32Value";
-static const char *kBoolValueFullMessageName = "google.protobuf.BoolValue";
-static const char *kStringValueFullMessageName = "google.protobuf.StringValue";
-static const char *kBytesValueFullMessageName = "google.protobuf.BytesValue";
+/* Type of value message */
+enum {
+ VALUE_NULLVALUE = 0,
+ VALUE_NUMBERVALUE = 1,
+ VALUE_STRINGVALUE = 2,
+ VALUE_BOOLVALUE = 3,
+ VALUE_STRUCTVALUE = 4,
+ VALUE_LISTVALUE = 5
+};
/* Forward declare */
static bool is_top_level(upb_json_parser *p);
+static bool is_wellknown_msg(upb_json_parser *p, upb_wellknowntype_t type);
+static bool is_wellknown_field(upb_json_parser *p, upb_wellknowntype_t type);
static bool is_number_wrapper_object(upb_json_parser *p);
static bool does_number_wrapper_start(upb_json_parser *p);
@@ -14301,16 +12608,28 @@ static bool is_string_wrapper_object(upb_json_parser *p);
static bool does_string_wrapper_start(upb_json_parser *p);
static bool does_string_wrapper_end(upb_json_parser *p);
-static bool is_boolean_wrapper_object(upb_json_parser *p);
-static bool does_boolean_wrapper_start(upb_json_parser *p);
-static bool does_boolean_wrapper_end(upb_json_parser *p);
-
static void start_wrapper_object(upb_json_parser *p);
static void end_wrapper_object(upb_json_parser *p);
+static void start_value_object(upb_json_parser *p, int value_type);
+static void end_value_object(upb_json_parser *p);
+
+static void start_listvalue_object(upb_json_parser *p);
+static void end_listvalue_object(upb_json_parser *p);
+
+static void start_structvalue_object(upb_json_parser *p);
+static void end_structvalue_object(upb_json_parser *p);
+
+static void start_object(upb_json_parser *p);
+static void end_object(upb_json_parser *p);
+
static bool start_subobject(upb_json_parser *p);
static void end_subobject(upb_json_parser *p);
+static void start_member(upb_json_parser *p);
+static void end_member(upb_json_parser *p);
+static bool end_membername(upb_json_parser *p);
+
static const char eof_ch = 'e';
typedef struct {
@@ -14380,6 +12699,10 @@ struct upb_json_parser {
/* Whether to proceed if unknown field is met. */
bool ignore_json_unknown;
+
+ /* Cache for parsing timestamp due to base and zone are handled in different
+ * handlers. */
+ struct tm tm;
};
struct upb_json_parsermethod {
@@ -14890,15 +13213,23 @@ static bool end_text(upb_json_parser *p, const char *ptr) {
static bool start_number(upb_json_parser *p, const char *ptr) {
if (is_top_level(p)) {
- if (!is_number_wrapper_object(p)) {
+ if (is_number_wrapper_object(p)) {
+ start_wrapper_object(p);
+ } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
+ start_value_object(p, VALUE_NUMBERVALUE);
+ } else {
return false;
}
- start_wrapper_object(p);
} else if (does_number_wrapper_start(p)) {
if (!start_subobject(p)) {
return false;
}
start_wrapper_object(p);
+ } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
+ if (!start_subobject(p)) {
+ return false;
+ }
+ start_value_object(p, VALUE_NUMBERVALUE);
}
multipart_startaccum(p);
@@ -14931,6 +13262,15 @@ static bool end_number(upb_json_parser *p, const char *ptr) {
if (!is_top_level(p)) {
end_subobject(p);
}
+ return true;
+ }
+
+ if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
+ end_value_object(p);
+ if (!is_top_level(p)) {
+ end_subobject(p);
+ }
+ return true;
}
return true;
@@ -15105,26 +13445,75 @@ static bool parser_putbool(upb_json_parser *p, bool val) {
static bool end_bool(upb_json_parser *p, bool val) {
if (is_top_level(p)) {
- if (!is_boolean_wrapper_object(p)) {
+ if (is_wellknown_msg(p, UPB_WELLKNOWN_BOOLVALUE)) {
+ start_wrapper_object(p);
+ } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
+ start_value_object(p, VALUE_BOOLVALUE);
+ } else {
return false;
}
- start_wrapper_object(p);
- } else if (does_boolean_wrapper_start(p)) {
+ } else if (is_wellknown_field(p, UPB_WELLKNOWN_BOOLVALUE)) {
if (!start_subobject(p)) {
return false;
}
start_wrapper_object(p);
+ } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
+ if (!start_subobject(p)) {
+ return false;
+ }
+ start_value_object(p, VALUE_BOOLVALUE);
}
if (!parser_putbool(p, val)) {
return false;
}
- if (does_boolean_wrapper_end(p)) {
+ if (is_wellknown_msg(p, UPB_WELLKNOWN_BOOLVALUE)) {
end_wrapper_object(p);
if (!is_top_level(p)) {
end_subobject(p);
}
+ return true;
+ }
+
+ if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
+ end_value_object(p);
+ if (!is_top_level(p)) {
+ end_subobject(p);
+ }
+ return true;
+ }
+
+ return true;
+}
+
+static bool end_null(upb_json_parser *p) {
+ const char *zero_ptr = "0";
+
+ if (is_top_level(p)) {
+ if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
+ start_value_object(p, VALUE_NULLVALUE);
+ } else {
+ return true;
+ }
+ } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
+ if (!start_subobject(p)) {
+ return false;
+ }
+ start_value_object(p, VALUE_NULLVALUE);
+ } else {
+ return true;
+ }
+
+ /* Fill null_value field. */
+ multipart_startaccum(p);
+ capture_begin(p, zero_ptr);
+ capture_end(p, zero_ptr + 1);
+ parse_number(p, false);
+
+ end_value_object(p);
+ if (!is_top_level(p)) {
+ end_subobject(p);
}
return true;
@@ -15132,15 +13521,32 @@ static bool end_bool(upb_json_parser *p, bool val) {
static bool start_stringval(upb_json_parser *p) {
if (is_top_level(p)) {
- if (!is_string_wrapper_object(p)) {
+ if (is_string_wrapper_object(p)) {
+ start_wrapper_object(p);
+ } else if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) ||
+ is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) {
+ start_object(p);
+ } else if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
+ start_value_object(p, VALUE_STRINGVALUE);
+ } else {
return false;
}
- start_wrapper_object(p);
} else if (does_string_wrapper_start(p)) {
if (!start_subobject(p)) {
return false;
}
start_wrapper_object(p);
+ } else if (is_wellknown_field(p, UPB_WELLKNOWN_TIMESTAMP) ||
+ is_wellknown_field(p, UPB_WELLKNOWN_DURATION)) {
+ if (!start_subobject(p)) {
+ return false;
+ }
+ start_object(p);
+ } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
+ if (!start_subobject(p)) {
+ return false;
+ }
+ start_value_object(p, VALUE_STRINGVALUE);
}
if (p->top->f == NULL) {
@@ -15197,6 +13603,12 @@ static bool start_stringval(upb_json_parser *p) {
static bool end_stringval_nontop(upb_json_parser *p) {
bool ok = true;
+ if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) ||
+ is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) {
+ multipart_end(p);
+ return true;
+ }
+
if (p->top->f == NULL) {
multipart_end(p);
return true;
@@ -15271,11 +13683,281 @@ static bool end_stringval(upb_json_parser *p) {
if (!is_top_level(p)) {
end_subobject(p);
}
+ return true;
+ }
+
+ if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
+ end_value_object(p);
+ if (!is_top_level(p)) {
+ end_subobject(p);
+ }
+ return true;
+ }
+
+ if (is_wellknown_msg(p, UPB_WELLKNOWN_TIMESTAMP) ||
+ is_wellknown_msg(p, UPB_WELLKNOWN_DURATION)) {
+ end_object(p);
+ if (!is_top_level(p)) {
+ end_subobject(p);
+ }
+ return true;
}
return true;
}
+static void start_duration_base(upb_json_parser *p, const char *ptr) {
+ capture_begin(p, ptr);
+}
+
+static bool end_duration_base(upb_json_parser *p, const char *ptr) {
+ size_t len;
+ const char *buf;
+ char seconds_buf[14];
+ char nanos_buf[12];
+ char *end;
+ int64_t seconds = 0;
+ int32_t nanos = 0;
+ double val = 0.0;
+ const char *seconds_membername = "seconds";
+ const char *nanos_membername = "nanos";
+ size_t fraction_start;
+
+ if (!capture_end(p, ptr)) {
+ return false;
+ }
+
+ buf = accumulate_getptr(p, &len);
+
+ memset(seconds_buf, 0, 14);
+ memset(nanos_buf, 0, 12);
+
+ /* Find out base end. The maximus duration is 315576000000, which cannot be
+ * represented by double without losing precision. Thus, we need to handle
+ * fraction and base separately. */
+ for (fraction_start = 0; fraction_start < len && buf[fraction_start] != '.';
+ fraction_start++);
+
+ /* Parse base */
+ memcpy(seconds_buf, buf, fraction_start);
+ seconds = strtol(seconds_buf, &end, 10);
+ if (errno == ERANGE || end != seconds_buf + fraction_start) {
+ upb_status_seterrf(&p->status, "error parsing duration: %s",
+ seconds_buf);
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ if (seconds > 315576000000) {
+ upb_status_seterrf(&p->status, "error parsing duration: "
+ "maximum acceptable value is "
+ "315576000000");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ if (seconds < -315576000000) {
+ upb_status_seterrf(&p->status, "error parsing duration: "
+ "minimum acceptable value is "
+ "-315576000000");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ /* Parse fraction */
+ nanos_buf[0] = '0';
+ memcpy(nanos_buf + 1, buf + fraction_start, len - fraction_start);
+ val = strtod(nanos_buf, &end);
+ if (errno == ERANGE || end != nanos_buf + len - fraction_start + 1) {
+ upb_status_seterrf(&p->status, "error parsing duration: %s",
+ nanos_buf);
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ nanos = val * 1000000000;
+ if (seconds < 0) nanos = -nanos;
+
+ /* Clean up buffer */
+ multipart_end(p);
+
+ /* Set seconds */
+ start_member(p);
+ capture_begin(p, seconds_membername);
+ capture_end(p, seconds_membername + 7);
+ end_membername(p);
+ upb_sink_putint64(&p->top->sink, parser_getsel(p), seconds);
+ end_member(p);
+
+ /* Set nanos */
+ start_member(p);
+ capture_begin(p, nanos_membername);
+ capture_end(p, nanos_membername + 5);
+ end_membername(p);
+ upb_sink_putint32(&p->top->sink, parser_getsel(p), nanos);
+ end_member(p);
+
+ /* Continue previous environment */
+ multipart_startaccum(p);
+
+ return true;
+}
+
+static void start_timestamp_base(upb_json_parser *p, const char *ptr) {
+ capture_begin(p, ptr);
+}
+
+#define UPB_TIMESTAMP_BASE_SIZE 19
+
+static bool end_timestamp_base(upb_json_parser *p, const char *ptr) {
+ size_t len;
+ const char *buf;
+ /* 3 for GMT and 1 for ending 0 */
+ char timestamp_buf[UPB_TIMESTAMP_BASE_SIZE + 4];
+
+ if (!capture_end(p, ptr)) {
+ return false;
+ }
+
+ buf = accumulate_getptr(p, &len);
+ UPB_ASSERT(len == UPB_TIMESTAMP_BASE_SIZE);
+ memcpy(timestamp_buf, buf, UPB_TIMESTAMP_BASE_SIZE);
+ memcpy(timestamp_buf + UPB_TIMESTAMP_BASE_SIZE, "GMT", 3);
+ timestamp_buf[UPB_TIMESTAMP_BASE_SIZE + 3] = 0;
+
+ /* Parse seconds */
+ if (strptime(timestamp_buf, "%FT%H:%M:%S%Z", &p->tm) == NULL) {
+ upb_status_seterrf(&p->status, "error parsing timestamp: %s", buf);
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ /* Clean up buffer */
+ multipart_end(p);
+ multipart_startaccum(p);
+
+ return true;
+}
+
+static void start_timestamp_fraction(upb_json_parser *p, const char *ptr) {
+ capture_begin(p, ptr);
+}
+
+static bool end_timestamp_fraction(upb_json_parser *p, const char *ptr) {
+ size_t len;
+ const char *buf;
+ char nanos_buf[12];
+ char *end;
+ double val = 0.0;
+ int32_t nanos;
+ const char *nanos_membername = "nanos";
+
+ memset(nanos_buf, 0, 12);
+
+ if (!capture_end(p, ptr)) {
+ return false;
+ }
+
+ buf = accumulate_getptr(p, &len);
+
+ if (len > 10) {
+ upb_status_seterrf(&p->status,
+ "error parsing timestamp: at most 9-digit fraction.");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ /* Parse nanos */
+ nanos_buf[0] = '0';
+ memcpy(nanos_buf + 1, buf, len);
+ val = strtod(nanos_buf, &end);
+
+ if (errno == ERANGE || end != nanos_buf + len + 1) {
+ upb_status_seterrf(&p->status, "error parsing timestamp nanos: %s",
+ nanos_buf);
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ nanos = val * 1000000000;
+
+ /* Clean up previous environment */
+ multipart_end(p);
+
+ /* Set nanos */
+ start_member(p);
+ capture_begin(p, nanos_membername);
+ capture_end(p, nanos_membername + 5);
+ end_membername(p);
+ upb_sink_putint32(&p->top->sink, parser_getsel(p), nanos);
+ end_member(p);
+
+ /* Continue previous environment */
+ multipart_startaccum(p);
+
+ return true;
+}
+
+static void start_timestamp_zone(upb_json_parser *p, const char *ptr) {
+ capture_begin(p, ptr);
+}
+
+static bool end_timestamp_zone(upb_json_parser *p, const char *ptr) {
+ size_t len;
+ const char *buf;
+ int hours;
+ int64_t seconds;
+ const char *seconds_membername = "seconds";
+
+ if (!capture_end(p, ptr)) {
+ return false;
+ }
+
+ buf = accumulate_getptr(p, &len);
+
+ if (buf[0] != 'Z') {
+ if (sscanf(buf + 1, "%2d:00", &hours) != 1) {
+ upb_status_seterrf(&p->status, "error parsing timestamp offset");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ if (buf[0] == '+') {
+ hours = -hours;
+ }
+
+ p->tm.tm_hour += hours;
+ }
+
+ /* Normalize tm */
+ seconds = mktime(&p->tm);
+
+ /* Check timestamp boundary */
+ if (seconds < -62135596800) {
+ upb_status_seterrf(&p->status, "error parsing timestamp: "
+ "minimum acceptable value is "
+ "0001-01-01T00:00:00Z");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ /* Clean up previous environment */
+ multipart_end(p);
+
+ /* Set seconds */
+ start_member(p);
+ capture_begin(p, seconds_membername);
+ capture_end(p, seconds_membername + 7);
+ end_membername(p);
+ upb_sink_putint64(&p->top->sink, parser_getsel(p), seconds);
+ end_member(p);
+
+ /* Continue previous environment */
+ multipart_startaccum(p);
+
+ return true;
+}
+
static void start_member(upb_json_parser *p) {
UPB_ASSERT(!p->top->f);
multipart_startaccum(p);
@@ -15459,10 +14141,6 @@ static void end_member(upb_json_parser *p) {
}
static bool start_subobject(upb_json_parser *p) {
- if (is_top_level(p)) {
- return true;
- }
-
if (p->top->f == NULL) {
upb_jsonparser_frame *inner;
if (!check_stack(p)) return false;
@@ -15525,6 +14203,30 @@ static bool start_subobject(upb_json_parser *p) {
}
}
+static bool start_subobject_full(upb_json_parser *p) {
+ if (is_top_level(p)) {
+ if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
+ start_value_object(p, VALUE_STRUCTVALUE);
+ if (!start_subobject(p)) return false;
+ start_structvalue_object(p);
+ } else if (is_wellknown_msg(p, UPB_WELLKNOWN_STRUCT)) {
+ start_structvalue_object(p);
+ } else {
+ return true;
+ }
+ } else if (is_wellknown_field(p, UPB_WELLKNOWN_STRUCT)) {
+ if (!start_subobject(p)) return false;
+ start_structvalue_object(p);
+ } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
+ if (!start_subobject(p)) return false;
+ start_value_object(p, VALUE_STRUCTVALUE);
+ if (!start_subobject(p)) return false;
+ start_structvalue_object(p);
+ }
+
+ return start_subobject(p);
+}
+
static void end_subobject(upb_json_parser *p) {
if (is_top_level(p)) {
return;
@@ -15546,10 +14248,48 @@ static void end_subobject(upb_json_parser *p) {
}
}
+static void end_subobject_full(upb_json_parser *p) {
+ end_subobject(p);
+
+ if (is_wellknown_msg(p, UPB_WELLKNOWN_STRUCT)) {
+ end_structvalue_object(p);
+ if (!is_top_level(p)) {
+ end_subobject(p);
+ }
+ }
+
+ if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
+ end_value_object(p);
+ if (!is_top_level(p)) {
+ end_subobject(p);
+ }
+ }
+}
+
static bool start_array(upb_json_parser *p) {
upb_jsonparser_frame *inner;
upb_selector_t sel;
+ if (is_top_level(p)) {
+ if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
+ start_value_object(p, VALUE_LISTVALUE);
+ if (!start_subobject(p)) return false;
+ start_listvalue_object(p);
+ } else if (is_wellknown_msg(p, UPB_WELLKNOWN_LISTVALUE)) {
+ start_listvalue_object(p);
+ } else {
+ return false;
+ }
+ } else if (is_wellknown_field(p, UPB_WELLKNOWN_LISTVALUE)) {
+ if (!start_subobject(p)) return false;
+ start_listvalue_object(p);
+ } else if (is_wellknown_field(p, UPB_WELLKNOWN_VALUE)) {
+ if (!start_subobject(p)) return false;
+ start_value_object(p, VALUE_LISTVALUE);
+ if (!start_subobject(p)) return false;
+ start_listvalue_object(p);
+ }
+
UPB_ASSERT(p->top->f);
if (!upb_fielddef_isseq(p->top->f)) {
@@ -15583,6 +14323,20 @@ static void end_array(upb_json_parser *p) {
p->top--;
sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ);
upb_sink_endseq(&p->top->sink, sel);
+
+ if (is_wellknown_msg(p, UPB_WELLKNOWN_LISTVALUE)) {
+ end_listvalue_object(p);
+ if (!is_top_level(p)) {
+ end_subobject(p);
+ }
+ }
+
+ if (is_wellknown_msg(p, UPB_WELLKNOWN_VALUE)) {
+ end_value_object(p);
+ if (!is_top_level(p)) {
+ end_subobject(p);
+ }
+ }
}
static void start_object(upb_json_parser *p) {
@@ -15602,69 +14356,103 @@ static void end_object(upb_json_parser *p) {
}
}
-static bool is_double_value(const upb_msgdef *m) {
- return strcmp(upb_msgdef_fullname(m), kDoubleValueFullMessageName) == 0;
+static bool is_string_wrapper(const upb_msgdef *m) {
+ upb_wellknowntype_t type = upb_msgdef_wellknowntype(m);
+ return type == UPB_WELLKNOWN_STRINGVALUE ||
+ type == UPB_WELLKNOWN_BYTESVALUE;
}
-static bool is_float_value(const upb_msgdef *m) {
- return strcmp(upb_msgdef_fullname(m), kFloatValueFullMessageName) == 0;
-}
+static void start_wrapper_object(upb_json_parser *p) {
+ const char *membername = "value";
-static bool is_int64_value(const upb_msgdef *m) {
- return strcmp(upb_msgdef_fullname(m), kInt64ValueFullMessageName) == 0;
-}
+ start_object(p);
-static bool is_uint64_value(const upb_msgdef *m) {
- return strcmp(upb_msgdef_fullname(m), kUInt64ValueFullMessageName) == 0;
+ /* Set up context for parsing value */
+ start_member(p);
+ capture_begin(p, membername);
+ capture_end(p, membername + 5);
+ end_membername(p);
}
-static bool is_int32_value(const upb_msgdef *m) {
- return strcmp(upb_msgdef_fullname(m), kInt32ValueFullMessageName) == 0;
+static void end_wrapper_object(upb_json_parser *p) {
+ end_member(p);
+ end_object(p);
}
-static bool is_uint32_value(const upb_msgdef *m) {
- return strcmp(upb_msgdef_fullname(m), kUInt32ValueFullMessageName) == 0;
-}
+static void start_value_object(upb_json_parser *p, int value_type) {
+ const char *nullmember = "null_value";
+ const char *numbermember = "number_value";
+ const char *stringmember = "string_value";
+ const char *boolmember = "bool_value";
+ const char *structmember = "struct_value";
+ const char *listmember = "list_value";
+ const char *membername = "";
-static bool is_bool_value(const upb_msgdef *m) {
- return strcmp(upb_msgdef_fullname(m), kBoolValueFullMessageName) == 0;
-}
+ switch (value_type) {
+ case VALUE_NULLVALUE:
+ membername = nullmember;
+ break;
+ case VALUE_NUMBERVALUE:
+ membername = numbermember;
+ break;
+ case VALUE_STRINGVALUE:
+ membername = stringmember;
+ break;
+ case VALUE_BOOLVALUE:
+ membername = boolmember;
+ break;
+ case VALUE_STRUCTVALUE:
+ membername = structmember;
+ break;
+ case VALUE_LISTVALUE:
+ membername = listmember;
+ break;
+ }
+
+ start_object(p);
-static bool is_string_value(const upb_msgdef *m) {
- return strcmp(upb_msgdef_fullname(m), kStringValueFullMessageName) == 0;
+ /* Set up context for parsing value */
+ start_member(p);
+ capture_begin(p, membername);
+ capture_end(p, membername + strlen(membername));
+ end_membername(p);
}
-static bool is_bytes_value(const upb_msgdef *m) {
- return strcmp(upb_msgdef_fullname(m), kBytesValueFullMessageName) == 0;
+static void end_value_object(upb_json_parser *p) {
+ end_member(p);
+ end_object(p);
}
-static bool is_number_wrapper(const upb_msgdef *m) {
- return is_double_value(m) ||
- is_float_value(m) ||
- is_int64_value(m) ||
- is_uint64_value(m) ||
- is_int32_value(m) ||
- is_uint32_value(m);
+static void start_listvalue_object(upb_json_parser *p) {
+ const char *membername = "values";
+
+ start_object(p);
+
+ /* Set up context for parsing value */
+ start_member(p);
+ capture_begin(p, membername);
+ capture_end(p, membername + strlen(membername));
+ end_membername(p);
}
-static bool is_string_wrapper(const upb_msgdef *m) {
- return is_string_value(m) ||
- is_bytes_value(m);
+static void end_listvalue_object(upb_json_parser *p) {
+ end_member(p);
+ end_object(p);
}
-static void start_wrapper_object(upb_json_parser *p) {
- const char *membername = "value";
+static void start_structvalue_object(upb_json_parser *p) {
+ const char *membername = "fields";
start_object(p);
/* Set up context for parsing value */
start_member(p);
capture_begin(p, membername);
- capture_end(p, membername + 5);
+ capture_end(p, membername + strlen(membername));
end_membername(p);
}
-static void end_wrapper_object(upb_json_parser *p) {
+static void end_structvalue_object(upb_json_parser *p) {
end_member(p);
end_object(p);
}
@@ -15673,18 +14461,29 @@ static bool is_top_level(upb_json_parser *p) {
return p->top == p->stack && p->top->f == NULL;
}
+static bool is_wellknown_msg(upb_json_parser *p, upb_wellknowntype_t type) {
+ return p->top->m != NULL && upb_msgdef_wellknowntype(p->top->m) == type;
+}
+
+static bool is_wellknown_field(upb_json_parser *p, upb_wellknowntype_t type) {
+ return p->top->f != NULL &&
+ upb_fielddef_issubmsg(p->top->f) &&
+ (upb_msgdef_wellknowntype(upb_fielddef_msgsubdef(p->top->f))
+ == type);
+}
+
static bool does_number_wrapper_start(upb_json_parser *p) {
return p->top->f != NULL &&
upb_fielddef_issubmsg(p->top->f) &&
- is_number_wrapper(upb_fielddef_msgsubdef(p->top->f));
+ upb_msgdef_isnumberwrapper(upb_fielddef_msgsubdef(p->top->f));
}
static bool does_number_wrapper_end(upb_json_parser *p) {
- return p->top->m != NULL && is_number_wrapper(p->top->m);
+ return p->top->m != NULL && upb_msgdef_isnumberwrapper(p->top->m);
}
static bool is_number_wrapper_object(upb_json_parser *p) {
- return p->top->m != NULL && is_number_wrapper(p->top->m);
+ return p->top->m != NULL && upb_msgdef_isnumberwrapper(p->top->m);
}
static bool does_string_wrapper_start(upb_json_parser *p) {
@@ -15701,20 +14500,6 @@ static bool is_string_wrapper_object(upb_json_parser *p) {
return p->top->m != NULL && is_string_wrapper(p->top->m);
}
-static bool does_boolean_wrapper_start(upb_json_parser *p) {
- return p->top->f != NULL &&
- upb_fielddef_issubmsg(p->top->f) &&
- is_bool_value(upb_fielddef_msgsubdef(p->top->f));
-}
-
-static bool does_boolean_wrapper_end(upb_json_parser *p) {
- return p->top->m != NULL && is_bool_value(p->top->m);
-}
-
-static bool is_boolean_wrapper_object(upb_json_parser *p) {
- return p->top->m != NULL && is_bool_value(p->top->m);
-}
-
#define CHECK_RETURN_TOP(x) if (!(x)) goto error
@@ -15736,37 +14521,44 @@ static bool is_boolean_wrapper_object(upb_json_parser *p) {
* final state once, when the closing '"' is seen. */
-#line 1589 "upb/json/parser.rl"
+//#line 2114 "upb/json/parser.rl"
-#line 1496 "upb/json/parser.c"
+//#line 1983 "upb/json/parser.c"
static const char _json_actions[] = {
0, 1, 0, 1, 1, 1, 3, 1,
4, 1, 6, 1, 7, 1, 8, 1,
- 9, 1, 11, 1, 13, 1, 14, 1,
- 15, 1, 16, 1, 17, 1, 18, 1,
- 20, 1, 22, 1, 23, 1, 24, 1,
- 25, 1, 26, 1, 27, 1, 28, 2,
- 4, 9, 2, 5, 6, 2, 7, 3,
- 2, 7, 9, 2, 12, 10, 2, 14,
- 16, 2, 15, 16, 2, 19, 2, 2,
- 20, 28, 2, 21, 10, 2, 23, 28,
- 2, 24, 28, 2, 25, 28, 2, 27,
- 28, 3, 15, 12, 10
+ 9, 1, 10, 1, 11, 1, 12, 1,
+ 13, 1, 21, 1, 23, 1, 24, 1,
+ 25, 1, 27, 1, 28, 1, 30, 1,
+ 32, 1, 33, 1, 34, 1, 35, 1,
+ 36, 1, 38, 2, 4, 9, 2, 5,
+ 6, 2, 7, 3, 2, 7, 9, 2,
+ 14, 15, 2, 16, 17, 2, 18, 19,
+ 2, 22, 20, 2, 26, 37, 2, 29,
+ 2, 2, 30, 38, 2, 31, 20, 2,
+ 33, 38, 2, 34, 38, 2, 35, 38,
+ 3, 25, 22, 20, 3, 26, 37, 38,
+ 4, 14, 15, 16, 17
};
-static const unsigned char _json_key_offsets[] = {
+static const short _json_key_offsets[] = {
0, 0, 12, 13, 18, 23, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37,
38, 43, 48, 49, 53, 58, 63, 68,
72, 76, 79, 82, 84, 88, 92, 94,
96, 101, 103, 105, 114, 120, 126, 132,
- 138, 140, 149, 150, 150, 150, 155, 160,
- 165, 166, 167, 168, 169, 169, 170, 171,
- 172, 172, 173, 174, 175, 175, 180, 185,
- 186, 190, 195, 200, 205, 209, 209, 212,
- 215, 218, 221, 224, 227, 227, 227
+ 138, 140, 144, 147, 149, 151, 154, 155,
+ 159, 161, 163, 165, 167, 168, 170, 172,
+ 173, 175, 177, 178, 180, 182, 183, 185,
+ 187, 188, 190, 192, 196, 198, 200, 201,
+ 202, 203, 204, 206, 211, 220, 221, 221,
+ 221, 226, 231, 236, 237, 238, 239, 240,
+ 240, 241, 242, 243, 243, 244, 245, 246,
+ 246, 251, 256, 257, 261, 266, 271, 276,
+ 280, 280, 283, 286, 289, 292, 295, 298,
+ 298, 298, 298, 298
};
static const char _json_trans_keys[] = {
@@ -15787,18 +14579,27 @@ static const char _json_trans_keys[] = {
116, 117, 48, 57, 65, 70, 97, 102,
48, 57, 65, 70, 97, 102, 48, 57,
65, 70, 97, 102, 48, 57, 65, 70,
- 97, 102, 34, 92, 34, 45, 91, 102,
- 110, 116, 123, 48, 57, 34, 32, 93,
- 125, 9, 13, 32, 44, 93, 9, 13,
- 32, 93, 125, 9, 13, 97, 108, 115,
- 101, 117, 108, 108, 114, 117, 101, 32,
- 34, 125, 9, 13, 32, 34, 125, 9,
- 13, 34, 32, 58, 9, 13, 32, 93,
- 125, 9, 13, 32, 44, 125, 9, 13,
- 32, 44, 125, 9, 13, 32, 34, 9,
+ 97, 102, 34, 92, 45, 48, 49, 57,
+ 48, 49, 57, 46, 115, 48, 57, 115,
+ 48, 57, 34, 46, 115, 48, 57, 48,
+ 57, 48, 57, 48, 57, 48, 57, 45,
+ 48, 57, 48, 57, 45, 48, 57, 48,
+ 57, 84, 48, 57, 48, 57, 58, 48,
+ 57, 48, 57, 58, 48, 57, 48, 57,
+ 43, 45, 46, 90, 48, 57, 48, 57,
+ 58, 48, 48, 34, 48, 57, 43, 45,
+ 90, 48, 57, 34, 45, 91, 102, 110,
+ 116, 123, 48, 57, 34, 32, 93, 125,
+ 9, 13, 32, 44, 93, 9, 13, 32,
+ 93, 125, 9, 13, 97, 108, 115, 101,
+ 117, 108, 108, 114, 117, 101, 32, 34,
+ 125, 9, 13, 32, 34, 125, 9, 13,
+ 34, 32, 58, 9, 13, 32, 93, 125,
+ 9, 13, 32, 44, 125, 9, 13, 32,
+ 44, 125, 9, 13, 32, 34, 9, 13,
+ 32, 9, 13, 32, 9, 13, 32, 9,
13, 32, 9, 13, 32, 9, 13, 32,
- 9, 13, 32, 9, 13, 32, 9, 13,
- 32, 9, 13, 0
+ 9, 13, 0
};
static const char _json_single_lengths[] = {
@@ -15807,11 +14608,16 @@ static const char _json_single_lengths[] = {
3, 3, 1, 2, 3, 3, 3, 2,
2, 1, 3, 0, 2, 2, 0, 0,
3, 2, 2, 9, 0, 0, 0, 0,
- 2, 7, 1, 0, 0, 3, 3, 3,
- 1, 1, 1, 1, 0, 1, 1, 1,
- 0, 1, 1, 1, 0, 3, 3, 1,
- 2, 3, 3, 3, 2, 0, 1, 1,
- 1, 1, 1, 1, 0, 0, 0
+ 2, 2, 1, 2, 0, 1, 1, 2,
+ 0, 0, 0, 0, 1, 0, 0, 1,
+ 0, 0, 1, 0, 0, 1, 0, 0,
+ 1, 0, 0, 4, 0, 0, 1, 1,
+ 1, 1, 0, 3, 7, 1, 0, 0,
+ 3, 3, 3, 1, 1, 1, 1, 0,
+ 1, 1, 1, 0, 1, 1, 1, 0,
+ 3, 3, 1, 2, 3, 3, 3, 2,
+ 0, 1, 1, 1, 1, 1, 1, 0,
+ 0, 0, 0, 0
};
static const char _json_range_lengths[] = {
@@ -15820,11 +14626,16 @@ static const char _json_range_lengths[] = {
1, 1, 0, 1, 1, 1, 1, 1,
1, 1, 0, 1, 1, 1, 1, 1,
1, 0, 0, 0, 3, 3, 3, 3,
- 0, 1, 0, 0, 0, 1, 1, 1,
+ 0, 1, 1, 0, 1, 1, 0, 1,
+ 1, 1, 1, 1, 0, 1, 1, 0,
+ 1, 1, 0, 1, 1, 0, 1, 1,
+ 0, 1, 1, 0, 1, 1, 0, 0,
+ 0, 0, 1, 1, 1, 0, 0, 0,
+ 1, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 1, 0,
- 1, 1, 1, 1, 1, 0, 1, 1,
- 1, 1, 1, 1, 0, 0, 0
+ 1, 1, 0, 1, 1, 1, 1, 1,
+ 0, 1, 1, 1, 1, 1, 1, 0,
+ 0, 0, 0, 0
};
static const short _json_index_offsets[] = {
@@ -15833,14 +14644,19 @@ static const short _json_index_offsets[] = {
48, 53, 58, 60, 64, 69, 74, 79,
83, 87, 90, 94, 96, 100, 104, 106,
108, 113, 116, 119, 129, 133, 137, 141,
- 145, 148, 157, 159, 160, 161, 166, 171,
- 176, 178, 180, 182, 184, 185, 187, 189,
- 191, 192, 194, 196, 198, 199, 204, 209,
- 211, 215, 220, 225, 230, 234, 235, 238,
- 241, 244, 247, 250, 253, 254, 255
+ 145, 148, 152, 155, 158, 160, 163, 165,
+ 169, 171, 173, 175, 177, 179, 181, 183,
+ 185, 187, 189, 191, 193, 195, 197, 199,
+ 201, 203, 205, 207, 212, 214, 216, 218,
+ 220, 222, 224, 226, 231, 240, 242, 243,
+ 244, 249, 254, 259, 261, 263, 265, 267,
+ 268, 270, 272, 274, 275, 277, 279, 281,
+ 282, 287, 292, 294, 298, 303, 308, 313,
+ 317, 318, 321, 324, 327, 330, 333, 336,
+ 337, 338, 339, 340
};
-static const char _json_indicies[] = {
+static const unsigned char _json_indicies[] = {
0, 2, 3, 4, 5, 6, 7, 8,
0, 3, 1, 9, 1, 11, 12, 1,
11, 10, 13, 14, 12, 13, 1, 14,
@@ -15859,57 +14675,77 @@ static const char _json_indicies[] = {
55, 55, 55, 55, 55, 55, 55, 56,
1, 57, 57, 57, 1, 58, 58, 58,
1, 59, 59, 59, 1, 60, 60, 60,
- 1, 62, 63, 61, 64, 65, 66, 67,
- 68, 69, 70, 65, 1, 71, 1, 72,
- 73, 75, 76, 1, 75, 74, 77, 78,
- 76, 77, 1, 78, 1, 1, 78, 74,
- 79, 1, 80, 1, 81, 1, 82, 1,
- 83, 84, 1, 85, 1, 86, 1, 87,
- 88, 1, 89, 1, 90, 1, 91, 92,
- 93, 94, 92, 1, 95, 96, 97, 95,
- 1, 98, 1, 99, 100, 99, 1, 100,
- 1, 1, 100, 101, 102, 103, 104, 102,
- 1, 105, 106, 97, 105, 1, 106, 96,
- 106, 1, 107, 108, 108, 1, 109, 109,
- 1, 110, 110, 1, 111, 111, 1, 112,
- 112, 1, 113, 113, 1, 1, 1, 1,
- 0
+ 1, 62, 63, 61, 64, 65, 66, 1,
+ 67, 68, 1, 69, 70, 1, 71, 1,
+ 70, 71, 1, 72, 1, 69, 70, 68,
+ 1, 73, 1, 74, 1, 75, 1, 76,
+ 1, 77, 1, 78, 1, 79, 1, 80,
+ 1, 81, 1, 82, 1, 83, 1, 84,
+ 1, 85, 1, 86, 1, 87, 1, 88,
+ 1, 89, 1, 90, 1, 91, 1, 92,
+ 92, 93, 94, 1, 95, 1, 96, 1,
+ 97, 1, 98, 1, 99, 1, 100, 1,
+ 101, 1, 102, 102, 103, 101, 1, 104,
+ 105, 106, 107, 108, 109, 110, 105, 1,
+ 111, 1, 112, 113, 115, 116, 1, 115,
+ 114, 117, 118, 116, 117, 1, 118, 1,
+ 1, 118, 114, 119, 1, 120, 1, 121,
+ 1, 122, 1, 123, 124, 1, 125, 1,
+ 126, 1, 127, 128, 1, 129, 1, 130,
+ 1, 131, 132, 133, 134, 132, 1, 135,
+ 136, 137, 135, 1, 138, 1, 139, 140,
+ 139, 1, 140, 1, 1, 140, 141, 142,
+ 143, 144, 142, 1, 145, 146, 137, 145,
+ 1, 146, 136, 146, 1, 147, 148, 148,
+ 1, 149, 149, 1, 150, 150, 1, 151,
+ 151, 1, 152, 152, 1, 153, 153, 1,
+ 1, 1, 1, 1, 1, 0
};
static const char _json_trans_targs[] = {
- 1, 0, 2, 71, 3, 6, 10, 13,
- 16, 70, 4, 3, 70, 4, 5, 7,
- 8, 9, 72, 11, 12, 73, 14, 15,
- 74, 17, 18, 75, 17, 18, 75, 19,
- 19, 20, 21, 22, 23, 75, 22, 23,
- 25, 26, 32, 76, 27, 29, 28, 30,
- 31, 34, 77, 35, 34, 77, 35, 33,
- 36, 37, 38, 39, 40, 34, 77, 35,
- 42, 44, 45, 48, 53, 57, 61, 43,
- 78, 78, 46, 45, 43, 46, 47, 49,
- 50, 51, 52, 78, 54, 55, 56, 78,
- 58, 59, 60, 78, 62, 63, 69, 62,
- 63, 69, 64, 64, 65, 66, 67, 68,
- 69, 67, 68, 78, 70, 70, 70, 70,
- 70, 70
+ 1, 0, 2, 106, 3, 6, 10, 13,
+ 16, 105, 4, 3, 105, 4, 5, 7,
+ 8, 9, 107, 11, 12, 108, 14, 15,
+ 109, 17, 18, 110, 17, 18, 110, 19,
+ 19, 20, 21, 22, 23, 110, 22, 23,
+ 25, 26, 32, 111, 27, 29, 28, 30,
+ 31, 34, 112, 35, 34, 112, 35, 33,
+ 36, 37, 38, 39, 40, 34, 112, 35,
+ 42, 43, 47, 43, 47, 44, 46, 45,
+ 113, 49, 50, 51, 52, 53, 54, 55,
+ 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 74, 73, 69,
+ 70, 71, 72, 73, 114, 75, 68, 73,
+ 77, 79, 80, 83, 88, 92, 96, 78,
+ 115, 115, 81, 80, 78, 81, 82, 84,
+ 85, 86, 87, 115, 89, 90, 91, 115,
+ 93, 94, 95, 115, 97, 98, 104, 97,
+ 98, 104, 99, 99, 100, 101, 102, 103,
+ 104, 102, 103, 115, 105, 105, 105, 105,
+ 105, 105
};
static const char _json_trans_actions[] = {
- 0, 0, 74, 68, 27, 0, 0, 0,
- 41, 33, 17, 0, 29, 0, 0, 0,
+ 0, 0, 84, 78, 33, 0, 0, 0,
+ 47, 39, 25, 0, 35, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
- 0, 23, 89, 65, 0, 59, 25, 19,
- 0, 0, 17, 21, 21, 62, 0, 0,
+ 0, 31, 96, 31, 0, 72, 0, 27,
+ 0, 0, 25, 29, 29, 29, 0, 0,
0, 0, 0, 3, 0, 0, 0, 0,
- 0, 5, 15, 0, 0, 47, 7, 13,
- 0, 50, 9, 9, 9, 53, 56, 11,
- 74, 68, 27, 0, 0, 0, 41, 33,
- 45, 71, 17, 0, 29, 0, 0, 0,
- 0, 0, 0, 80, 0, 0, 0, 83,
- 0, 0, 0, 77, 23, 89, 65, 0,
- 59, 25, 19, 0, 0, 17, 21, 21,
- 62, 0, 0, 86, 0, 31, 37, 39,
- 35, 43
+ 0, 5, 15, 0, 0, 51, 7, 13,
+ 0, 54, 9, 9, 9, 57, 60, 11,
+ 17, 17, 17, 0, 0, 0, 19, 0,
+ 21, 23, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 104, 63, 104, 0,
+ 0, 0, 0, 0, 69, 0, 66, 66,
+ 84, 78, 33, 0, 0, 0, 47, 39,
+ 49, 81, 25, 0, 35, 0, 0, 0,
+ 0, 0, 0, 90, 0, 0, 0, 93,
+ 0, 0, 0, 87, 31, 96, 31, 0,
+ 72, 0, 27, 0, 0, 25, 29, 29,
+ 29, 0, 0, 100, 0, 37, 43, 45,
+ 41, 75
};
static const char _json_eof_actions[] = {
@@ -15921,19 +14757,26 @@ static const char _json_eof_actions[] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 31,
- 37, 39, 35, 43, 0, 0, 0
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 37, 43, 45, 41, 75, 0,
+ 0, 0, 0, 0
};
static const int json_start = 1;
static const int json_en_number_machine = 24;
static const int json_en_string_machine = 33;
-static const int json_en_value_machine = 41;
+static const int json_en_duration_machine = 41;
+static const int json_en_timestamp_machine = 48;
+static const int json_en_value_machine = 76;
static const int json_en_main = 1;
-#line 1592 "upb/json/parser.rl"
+//#line 2117 "upb/json/parser.rl"
size_t parse(void *closure, const void *hd, const char *buf, size_t size,
const upb_bufhandle *handle) {
@@ -15956,7 +14799,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size,
capture_resume(parser, buf);
-#line 1712 "upb/json/parser.c"
+//#line 2257 "upb/json/parser.c"
{
int _klen;
unsigned int _trans;
@@ -16031,118 +14874,166 @@ _match:
switch ( *_acts++ )
{
case 1:
-#line 1503 "upb/json/parser.rl"
+//#line 1988 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 2:
-#line 1505 "upb/json/parser.rl"
+//#line 1990 "upb/json/parser.rl"
{ p--; {stack[top++] = cs; cs = 24; goto _again;} }
break;
case 3:
-#line 1509 "upb/json/parser.rl"
+//#line 1994 "upb/json/parser.rl"
{ start_text(parser, p); }
break;
case 4:
-#line 1510 "upb/json/parser.rl"
+//#line 1995 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_text(parser, p)); }
break;
case 5:
-#line 1516 "upb/json/parser.rl"
+//#line 2001 "upb/json/parser.rl"
{ start_hex(parser); }
break;
case 6:
-#line 1517 "upb/json/parser.rl"
+//#line 2002 "upb/json/parser.rl"
{ hexdigit(parser, p); }
break;
case 7:
-#line 1518 "upb/json/parser.rl"
+//#line 2003 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_hex(parser)); }
break;
case 8:
-#line 1524 "upb/json/parser.rl"
+//#line 2009 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(escape(parser, p)); }
break;
case 9:
-#line 1530 "upb/json/parser.rl"
+//#line 2015 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 10:
-#line 1533 "upb/json/parser.rl"
- { {stack[top++] = cs; cs = 33; goto _again;} }
+//#line 2027 "upb/json/parser.rl"
+ { start_duration_base(parser, p); }
break;
case 11:
-#line 1535 "upb/json/parser.rl"
- { p--; {stack[top++] = cs; cs = 41; goto _again;} }
+//#line 2028 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_duration_base(parser, p)); }
break;
case 12:
-#line 1540 "upb/json/parser.rl"
- { start_member(parser); }
+//#line 2030 "upb/json/parser.rl"
+ { p--; {cs = stack[--top]; goto _again;} }
break;
case 13:
-#line 1541 "upb/json/parser.rl"
- { CHECK_RETURN_TOP(end_membername(parser)); }
+//#line 2035 "upb/json/parser.rl"
+ { start_timestamp_base(parser, p); }
break;
case 14:
-#line 1544 "upb/json/parser.rl"
- { end_member(parser); }
+//#line 2036 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_timestamp_base(parser, p)); }
break;
case 15:
-#line 1550 "upb/json/parser.rl"
- { start_object(parser); }
+//#line 2038 "upb/json/parser.rl"
+ { start_timestamp_fraction(parser, p); }
break;
case 16:
-#line 1553 "upb/json/parser.rl"
- { end_object(parser); }
+//#line 2039 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_timestamp_fraction(parser, p)); }
break;
case 17:
-#line 1559 "upb/json/parser.rl"
- { CHECK_RETURN_TOP(start_array(parser)); }
+//#line 2041 "upb/json/parser.rl"
+ { start_timestamp_zone(parser, p); }
break;
case 18:
-#line 1563 "upb/json/parser.rl"
- { end_array(parser); }
+//#line 2042 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_timestamp_zone(parser, p)); }
break;
case 19:
-#line 1568 "upb/json/parser.rl"
- { CHECK_RETURN_TOP(start_number(parser, p)); }
+//#line 2044 "upb/json/parser.rl"
+ { p--; {cs = stack[--top]; goto _again;} }
break;
case 20:
-#line 1569 "upb/json/parser.rl"
- { CHECK_RETURN_TOP(end_number(parser, p)); }
+//#line 2049 "upb/json/parser.rl"
+ {
+ if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) {
+ {stack[top++] = cs; cs = 48; goto _again;}
+ } else if (is_wellknown_msg(parser, UPB_WELLKNOWN_DURATION)) {
+ {stack[top++] = cs; cs = 41; goto _again;}
+ } else {
+ {stack[top++] = cs; cs = 33; goto _again;}
+ }
+ }
break;
case 21:
-#line 1571 "upb/json/parser.rl"
- { CHECK_RETURN_TOP(start_stringval(parser)); }
+//#line 2060 "upb/json/parser.rl"
+ { p--; {stack[top++] = cs; cs = 76; goto _again;} }
break;
case 22:
-#line 1572 "upb/json/parser.rl"
- { CHECK_RETURN_TOP(end_stringval(parser)); }
+//#line 2065 "upb/json/parser.rl"
+ { start_member(parser); }
break;
case 23:
-#line 1574 "upb/json/parser.rl"
- { CHECK_RETURN_TOP(end_bool(parser, true)); }
+//#line 2066 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_membername(parser)); }
break;
case 24:
-#line 1576 "upb/json/parser.rl"
- { CHECK_RETURN_TOP(end_bool(parser, false)); }
+//#line 2069 "upb/json/parser.rl"
+ { end_member(parser); }
break;
case 25:
-#line 1578 "upb/json/parser.rl"
- { /* null value */ }
+//#line 2075 "upb/json/parser.rl"
+ { start_object(parser); }
break;
case 26:
-#line 1580 "upb/json/parser.rl"
- { CHECK_RETURN_TOP(start_subobject(parser)); }
+//#line 2078 "upb/json/parser.rl"
+ { end_object(parser); }
break;
case 27:
-#line 1581 "upb/json/parser.rl"
- { end_subobject(parser); }
+//#line 2084 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(start_array(parser)); }
break;
case 28:
-#line 1586 "upb/json/parser.rl"
+//#line 2088 "upb/json/parser.rl"
+ { end_array(parser); }
+ break;
+ case 29:
+//#line 2093 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(start_number(parser, p)); }
+ break;
+ case 30:
+//#line 2094 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_number(parser, p)); }
+ break;
+ case 31:
+//#line 2096 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(start_stringval(parser)); }
+ break;
+ case 32:
+//#line 2097 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_stringval(parser)); }
+ break;
+ case 33:
+//#line 2099 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_bool(parser, true)); }
+ break;
+ case 34:
+//#line 2101 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_bool(parser, false)); }
+ break;
+ case 35:
+//#line 2103 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_null(parser)); }
+ break;
+ case 36:
+//#line 2105 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(start_subobject_full(parser)); }
+ break;
+ case 37:
+//#line 2106 "upb/json/parser.rl"
+ { end_subobject_full(parser); }
+ break;
+ case 38:
+//#line 2111 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
-#line 1898 "upb/json/parser.c"
+//#line 2491 "upb/json/parser.c"
}
}
@@ -16159,32 +15050,34 @@ _again:
while ( __nacts-- > 0 ) {
switch ( *__acts++ ) {
case 0:
-#line 1499 "upb/json/parser.rl"
- {
- p--; {cs = stack[--top]; goto _again;}
- }
+//#line 1986 "upb/json/parser.rl"
+ { p--; {cs = stack[--top]; goto _again;} }
break;
- case 20:
-#line 1569 "upb/json/parser.rl"
+ case 26:
+//#line 2078 "upb/json/parser.rl"
+ { end_object(parser); }
+ break;
+ case 30:
+//#line 2094 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_number(parser, p)); }
break;
- case 23:
-#line 1574 "upb/json/parser.rl"
+ case 33:
+//#line 2099 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, true)); }
break;
- case 24:
-#line 1576 "upb/json/parser.rl"
+ case 34:
+//#line 2101 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, false)); }
break;
- case 25:
-#line 1578 "upb/json/parser.rl"
- { /* null value */ }
+ case 35:
+//#line 2103 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_null(parser)); }
break;
- case 27:
-#line 1581 "upb/json/parser.rl"
- { end_subobject(parser); }
+ case 37:
+//#line 2106 "upb/json/parser.rl"
+ { end_subobject_full(parser); }
break;
-#line 1940 "upb/json/parser.c"
+//#line 2535 "upb/json/parser.c"
}
}
}
@@ -16192,7 +15085,7 @@ _again:
_out: {}
}
-#line 1614 "upb/json/parser.rl"
+//#line 2139 "upb/json/parser.rl"
if (p != pe) {
upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p);
@@ -16214,17 +15107,19 @@ bool end(void *closure, const void *hd) {
/* Prevent compile warning on unused static constants. */
UPB_UNUSED(json_start);
+ UPB_UNUSED(json_en_duration_machine);
UPB_UNUSED(json_en_number_machine);
UPB_UNUSED(json_en_string_machine);
+ UPB_UNUSED(json_en_timestamp_machine);
UPB_UNUSED(json_en_value_machine);
UPB_UNUSED(json_en_main);
parse(parser, hd, &eof_ch, 0, NULL);
return parser->current_state >=
-#line 1978 "upb/json/parser.c"
-70
-#line 1642 "upb/json/parser.rl"
+//#line 2575 "upb/json/parser.c"
+105
+//#line 2169 "upb/json/parser.rl"
;
}
@@ -16239,13 +15134,13 @@ static void json_parser_reset(upb_json_parser *p) {
/* Emit Ragel initialization of the parser. */
-#line 1995 "upb/json/parser.c"
+//#line 2592 "upb/json/parser.c"
{
cs = json_start;
top = 0;
}
-#line 1656 "upb/json/parser.rl"
+//#line 2183 "upb/json/parser.rl"
p->current_state = cs;
p->parser_top = top;
accumulate_clear(p);
@@ -16398,6 +15293,7 @@ const upb_byteshandler *upb_json_parsermethod_inputhandler(
#include <string.h>
#include <stdint.h>
+#include <time.h>
struct upb_json_printer {
upb_sink input_;
@@ -16418,6 +15314,12 @@ struct upb_json_printer {
* repeated fields and messages (maps), and the worst case is a
* message->repeated field->submessage->repeated field->... nesting. */
bool first_elem_[UPB_MAX_HANDLER_DEPTH * 2];
+
+ /* To print timestamp, printer needs to cache its seconds and nanos values
+ * and convert them when ending timestamp message. See comments of
+ * printer_sethandlers_timestamp for more detail. */
+ int64_t seconds;
+ int32_t nanos;
};
/* StringPiece; a pointer plus a length. */
@@ -17076,6 +15978,369 @@ void printer_sethandlers_mapentry(const void *closure, bool preserve_fieldnames,
upb_handlerattr_uninit(&empty_attr);
}
+static bool putseconds(void *closure, const void *handler_data,
+ int64_t seconds) {
+ upb_json_printer *p = closure;
+ p->seconds = seconds;
+ UPB_UNUSED(handler_data);
+ return true;
+}
+
+static bool putnanos(void *closure, const void *handler_data,
+ int32_t nanos) {
+ upb_json_printer *p = closure;
+ p->nanos = nanos;
+ UPB_UNUSED(handler_data);
+ return true;
+}
+
+static void *scalar_startstr_nokey(void *closure, const void *handler_data,
+ size_t size_hint) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ UPB_UNUSED(size_hint);
+ print_data(p, "\"", 1);
+ return p;
+}
+
+static size_t putstr_nokey(void *closure, const void *handler_data,
+ const char *str, size_t len,
+ const upb_bufhandle *handle) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ UPB_UNUSED(handle);
+ print_data(p, "\"", 1);
+ putstring(p, str, len);
+ print_data(p, "\"", 1);
+ return len + 2;
+}
+
+static void *startseq_nokey(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ p->depth_++;
+ p->first_elem_[p->depth_] = true;
+ print_data(p, "[", 1);
+ return closure;
+}
+
+static void *startmap_nokey(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ p->depth_++;
+ p->first_elem_[p->depth_] = true;
+ print_data(p, "{", 1);
+ return closure;
+}
+
+static bool putnull(void *closure, const void *handler_data,
+ int32_t null) {
+ upb_json_printer *p = closure;
+ print_data(p, "null", 4);
+ UPB_UNUSED(handler_data);
+ UPB_UNUSED(null);
+ return true;
+}
+
+static bool printer_startdurationmsg(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ if (p->depth_ == 0) {
+ upb_bytessink_start(p->output_, 0, &p->subc_);
+ }
+ return true;
+}
+
+#define UPB_DURATION_MAX_JSON_LEN 23
+#define UPB_DURATION_MAX_NANO_LEN 9
+
+static bool printer_enddurationmsg(void *closure, const void *handler_data,
+ upb_status *s) {
+ upb_json_printer *p = closure;
+ char buffer[UPB_DURATION_MAX_JSON_LEN];
+ size_t base_len;
+ size_t curr;
+ size_t i;
+
+ memset(buffer, 0, UPB_DURATION_MAX_JSON_LEN);
+
+ if (p->seconds < -315576000000) {
+ upb_status_seterrf(s, "error parsing duration: "
+ "minimum acceptable value is "
+ "-315576000000");
+ return false;
+ }
+
+ if (p->seconds > 315576000000) {
+ upb_status_seterrf(s, "error serializing duration: "
+ "maximum acceptable value is "
+ "315576000000");
+ return false;
+ }
+
+ _upb_snprintf(buffer, sizeof(buffer), "%ld", (long)p->seconds);
+ base_len = strlen(buffer);
+
+ if (p->nanos != 0) {
+ char nanos_buffer[UPB_DURATION_MAX_NANO_LEN + 3];
+ _upb_snprintf(nanos_buffer, sizeof(nanos_buffer), "%.9f",
+ p->nanos / 1000000000.0);
+ /* Remove trailing 0. */
+ for (i = UPB_DURATION_MAX_NANO_LEN + 2;
+ nanos_buffer[i] == '0'; i--) {
+ nanos_buffer[i] = 0;
+ }
+ strcpy(buffer + base_len, nanos_buffer + 1);
+ }
+
+ curr = strlen(buffer);
+ strcpy(buffer + curr, "s");
+
+ p->seconds = 0;
+ p->nanos = 0;
+
+ print_data(p, "\"", 1);
+ print_data(p, buffer, strlen(buffer));
+ print_data(p, "\"", 1);
+
+ if (p->depth_ == 0) {
+ upb_bytessink_end(p->output_);
+ }
+
+ UPB_UNUSED(handler_data);
+ return true;
+}
+
+static bool printer_starttimestampmsg(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ if (p->depth_ == 0) {
+ upb_bytessink_start(p->output_, 0, &p->subc_);
+ }
+ return true;
+}
+
+#define UPB_TIMESTAMP_MAX_JSON_LEN 31
+#define UPB_TIMESTAMP_BEFORE_NANO_LEN 19
+#define UPB_TIMESTAMP_MAX_NANO_LEN 9
+
+static bool printer_endtimestampmsg(void *closure, const void *handler_data,
+ upb_status *s) {
+ upb_json_printer *p = closure;
+ char buffer[UPB_TIMESTAMP_MAX_JSON_LEN];
+ time_t time = p->seconds;
+ size_t curr;
+ size_t i;
+ size_t year_length =
+ strftime(buffer, UPB_TIMESTAMP_MAX_JSON_LEN, "%Y", gmtime(&time));
+
+ if (p->seconds < -62135596800) {
+ upb_status_seterrf(s, "error parsing timestamp: "
+ "minimum acceptable value is "
+ "0001-01-01T00:00:00Z");
+ return false;
+ }
+
+ if (p->seconds > 253402300799) {
+ upb_status_seterrf(s, "error parsing timestamp: "
+ "maximum acceptable value is "
+ "9999-12-31T23:59:59Z");
+ return false;
+ }
+
+ /* strftime doesn't guarantee 4 digits for year. Prepend 0 by ourselves. */
+ for (i = 0; i < 4 - year_length; i++) {
+ buffer[i] = '0';
+ }
+
+ strftime(buffer + (4 - year_length), UPB_TIMESTAMP_MAX_JSON_LEN,
+ "%Y-%m-%dT%H:%M:%S", gmtime(&time));
+ if (p->nanos != 0) {
+ char nanos_buffer[UPB_TIMESTAMP_MAX_NANO_LEN + 3];
+ _upb_snprintf(nanos_buffer, sizeof(nanos_buffer), "%.9f",
+ p->nanos / 1000000000.0);
+ /* Remove trailing 0. */
+ for (i = UPB_TIMESTAMP_MAX_NANO_LEN + 2;
+ nanos_buffer[i] == '0'; i--) {
+ nanos_buffer[i] = 0;
+ }
+ strcpy(buffer + UPB_TIMESTAMP_BEFORE_NANO_LEN, nanos_buffer + 1);
+ }
+
+ curr = strlen(buffer);
+ strcpy(buffer + curr, "Z");
+
+ p->seconds = 0;
+ p->nanos = 0;
+
+ print_data(p, "\"", 1);
+ print_data(p, buffer, strlen(buffer));
+ print_data(p, "\"", 1);
+
+ if (p->depth_ == 0) {
+ upb_bytessink_end(p->output_);
+ }
+
+ UPB_UNUSED(handler_data);
+ UPB_UNUSED(s);
+ return true;
+}
+
+static bool printer_startmsg_noframe(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ if (p->depth_ == 0) {
+ upb_bytessink_start(p->output_, 0, &p->subc_);
+ }
+ return true;
+}
+
+static bool printer_endmsg_noframe(
+ void *closure, const void *handler_data, upb_status *s) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ UPB_UNUSED(s);
+ if (p->depth_ == 0) {
+ upb_bytessink_end(p->output_);
+ }
+ return true;
+}
+
+/* Set up handlers for a duration submessage. */
+void printer_sethandlers_duration(const void *closure, upb_handlers *h) {
+ const upb_msgdef *md = upb_handlers_msgdef(h);
+
+ const upb_fielddef* seconds_field =
+ upb_msgdef_itof(md, UPB_DURATION_SECONDS);
+ const upb_fielddef* nanos_field =
+ upb_msgdef_itof(md, UPB_DURATION_NANOS);
+
+ upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER;
+
+ upb_handlers_setstartmsg(h, printer_startdurationmsg, &empty_attr);
+ upb_handlers_setint64(h, seconds_field, putseconds, &empty_attr);
+ upb_handlers_setint32(h, nanos_field, putnanos, &empty_attr);
+ upb_handlers_setendmsg(h, printer_enddurationmsg, &empty_attr);
+
+ UPB_UNUSED(closure);
+}
+
+/* Set up handlers for a timestamp submessage. Instead of printing fields
+ * separately, the json representation of timestamp follows RFC 3339 */
+void printer_sethandlers_timestamp(const void *closure, upb_handlers *h) {
+ const upb_msgdef *md = upb_handlers_msgdef(h);
+
+ const upb_fielddef* seconds_field =
+ upb_msgdef_itof(md, UPB_TIMESTAMP_SECONDS);
+ const upb_fielddef* nanos_field =
+ upb_msgdef_itof(md, UPB_TIMESTAMP_NANOS);
+
+ upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER;
+
+ upb_handlers_setstartmsg(h, printer_starttimestampmsg, &empty_attr);
+ upb_handlers_setint64(h, seconds_field, putseconds, &empty_attr);
+ upb_handlers_setint32(h, nanos_field, putnanos, &empty_attr);
+ upb_handlers_setendmsg(h, printer_endtimestampmsg, &empty_attr);
+
+ UPB_UNUSED(closure);
+}
+
+void printer_sethandlers_value(const void *closure, upb_handlers *h) {
+ const upb_msgdef *md = upb_handlers_msgdef(h);
+ upb_msg_field_iter i;
+
+ upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER;
+
+ upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr);
+ upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr);
+
+ upb_msg_field_begin(&i, md);
+ for(; !upb_msg_field_done(&i); upb_msg_field_next(&i)) {
+ const upb_fielddef *f = upb_msg_iter_field(&i);
+
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_ENUM:
+ upb_handlers_setint32(h, f, putnull, &empty_attr);
+ break;
+ case UPB_TYPE_DOUBLE:
+ upb_handlers_setdouble(h, f, putdouble, &empty_attr);
+ break;
+ case UPB_TYPE_STRING:
+ upb_handlers_setstartstr(h, f, scalar_startstr_nokey, &empty_attr);
+ upb_handlers_setstring(h, f, scalar_str, &empty_attr);
+ upb_handlers_setendstr(h, f, scalar_endstr, &empty_attr);
+ break;
+ case UPB_TYPE_BOOL:
+ upb_handlers_setbool(h, f, putbool, &empty_attr);
+ break;
+ case UPB_TYPE_MESSAGE:
+ break;
+ default:
+ UPB_ASSERT(false);
+ break;
+ }
+ }
+
+ UPB_UNUSED(closure);
+}
+
+#define WRAPPER_SETHANDLERS(wrapper, type, putmethod) \
+void printer_sethandlers_##wrapper(const void *closure, upb_handlers *h) { \
+ const upb_msgdef *md = upb_handlers_msgdef(h); \
+ const upb_fielddef* f = upb_msgdef_itof(md, 1); \
+ upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; \
+ upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr); \
+ upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr); \
+ upb_handlers_set##type(h, f, putmethod, &empty_attr); \
+ UPB_UNUSED(closure); \
+}
+
+WRAPPER_SETHANDLERS(doublevalue, double, putdouble)
+WRAPPER_SETHANDLERS(floatvalue, float, putfloat)
+WRAPPER_SETHANDLERS(int64value, int64, putint64_t)
+WRAPPER_SETHANDLERS(uint64value, uint64, putuint64_t)
+WRAPPER_SETHANDLERS(int32value, int32, putint32_t)
+WRAPPER_SETHANDLERS(uint32value, uint32, putuint32_t)
+WRAPPER_SETHANDLERS(boolvalue, bool, putbool)
+WRAPPER_SETHANDLERS(stringvalue, string, putstr_nokey)
+WRAPPER_SETHANDLERS(bytesvalue, string, putbytes)
+
+#undef WRAPPER_SETHANDLERS
+
+void printer_sethandlers_listvalue(const void *closure, upb_handlers *h) {
+ const upb_msgdef *md = upb_handlers_msgdef(h);
+ const upb_fielddef* f = upb_msgdef_itof(md, 1);
+
+ upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER;
+
+ upb_handlers_setstartseq(h, f, startseq_nokey, &empty_attr);
+ upb_handlers_setendseq(h, f, endseq, &empty_attr);
+
+ upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr);
+ upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr);
+
+ upb_handlers_setstartsubmsg(h, f, repeated_startsubmsg, &empty_attr);
+
+ UPB_UNUSED(closure);
+}
+
+void printer_sethandlers_structvalue(const void *closure, upb_handlers *h) {
+ const upb_msgdef *md = upb_handlers_msgdef(h);
+ const upb_fielddef* f = upb_msgdef_itof(md, 1);
+
+ upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER;
+
+ upb_handlers_setstartseq(h, f, startmap_nokey, &empty_attr);
+ upb_handlers_setendseq(h, f, endmap, &empty_attr);
+
+ upb_handlers_setstartmsg(h, printer_startmsg_noframe, &empty_attr);
+ upb_handlers_setendmsg(h, printer_endmsg_noframe, &empty_attr);
+
+ upb_handlers_setstartsubmsg(h, f, repeated_startsubmsg, &empty_attr);
+
+ UPB_UNUSED(closure);
+}
+
void printer_sethandlers(const void *closure, upb_handlers *h) {
const upb_msgdef *md = upb_handlers_msgdef(h);
bool is_mapentry = upb_msgdef_mapentry(md);
@@ -17091,6 +16356,42 @@ void printer_sethandlers(const void *closure, upb_handlers *h) {
return;
}
+ switch (upb_msgdef_wellknowntype(md)) {
+ case UPB_WELLKNOWN_UNSPECIFIED:
+ break;
+ case UPB_WELLKNOWN_DURATION:
+ printer_sethandlers_duration(closure, h);
+ return;
+ case UPB_WELLKNOWN_TIMESTAMP:
+ printer_sethandlers_timestamp(closure, h);
+ return;
+ case UPB_WELLKNOWN_VALUE:
+ printer_sethandlers_value(closure, h);
+ return;
+ case UPB_WELLKNOWN_LISTVALUE:
+ printer_sethandlers_listvalue(closure, h);
+ return;
+ case UPB_WELLKNOWN_STRUCT:
+ printer_sethandlers_structvalue(closure, h);
+ return;
+#define WRAPPER(wellknowntype, name) \
+ case wellknowntype: \
+ printer_sethandlers_##name(closure, h); \
+ return; \
+
+ WRAPPER(UPB_WELLKNOWN_DOUBLEVALUE, doublevalue);
+ WRAPPER(UPB_WELLKNOWN_FLOATVALUE, floatvalue);
+ WRAPPER(UPB_WELLKNOWN_INT64VALUE, int64value);
+ WRAPPER(UPB_WELLKNOWN_UINT64VALUE, uint64value);
+ WRAPPER(UPB_WELLKNOWN_INT32VALUE, int32value);
+ WRAPPER(UPB_WELLKNOWN_UINT32VALUE, uint32value);
+ WRAPPER(UPB_WELLKNOWN_BOOLVALUE, boolvalue);
+ WRAPPER(UPB_WELLKNOWN_STRINGVALUE, stringvalue);
+ WRAPPER(UPB_WELLKNOWN_BYTESVALUE, bytesvalue);
+
+#undef WRAPPER
+ }
+
upb_handlers_setstartmsg(h, printer_startmsg, &empty_attr);
upb_handlers_setendmsg(h, printer_endmsg, &empty_attr);
@@ -17198,6 +16499,8 @@ upb_json_printer *upb_json_printer_create(upb_env *e, const upb_handlers *h,
p->output_ = output;
json_printer_reset(p);
upb_sink_reset(&p->input_, h, p);
+ p->seconds = 0;
+ p->nanos = 0;
/* If this fails, increase the value in printer.h. */
UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(e) - size_before <=
@@ -17215,3 +16518,8 @@ const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md,
return upb_handlers_newfrozen(
md, owner, printer_sethandlers, &preserve_fieldnames);
}
+
+#undef UPB_SIZE
+#undef UPB_FIELD_AT
+#undef UPB_READ_ONEOF
+#undef UPB_WRITE_ONEOF