google-protobuf 3.4.1.1-x86-linux → 3.5.0-x86-linux

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of google-protobuf might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39910983cda5c59a079924cd697f710987c7841e
4
- data.tar.gz: 33cc6614e794c02193bbc117012397da64d0d398
3
+ metadata.gz: 53726691c603d78a3d533137d758e91b6f8b1623
4
+ data.tar.gz: de2912402a84550f8310f2e02fbf6d31389006a4
5
5
  SHA512:
6
- metadata.gz: 76939e7fe29e3bf3282fe2ea4d6e3010d90c534a3ff18ed6f54022024eb676696ecfb9afd66c15b28b39afa3e764726e0ad3887c292546fb26fe8a32cc5e4143
7
- data.tar.gz: 59f9342c94eec0142d8bcbcd3cd061f74d665116f170e934c7f183e872796b6d11afb5751320e25f75421b4e88a4bb32c6127b8cb78fec241801c3cdd99ba54d
6
+ metadata.gz: 1c9d0821d9035209c0168a46b87a167c6f33c95484c179c87aea3c0546c248988c08f1c24df22547295bc64811b42f408f805c6c34c947093c13bbfbedc6a640
7
+ data.tar.gz: 4aa1b37a32df41b8e18d32b9da808ec222648823dd4d3222f401789f22590ffcbc293df89232e15cbb7e159529522fe2d830ddc3e21b0a9debf48c2b2456cb7a
@@ -228,7 +228,6 @@ DEFINE_CLASS(Descriptor, "Google::Protobuf::Descriptor");
228
228
  void Descriptor_mark(void* _self) {
229
229
  Descriptor* self = _self;
230
230
  rb_gc_mark(self->klass);
231
- rb_gc_mark(self->typeclass_references);
232
231
  }
233
232
 
234
233
  void Descriptor_free(void* _self) {
@@ -283,7 +282,6 @@ VALUE Descriptor_alloc(VALUE klass) {
283
282
  self->pb_serialize_handlers = NULL;
284
283
  self->json_serialize_handlers = NULL;
285
284
  self->json_serialize_handlers_preserve = NULL;
286
- self->typeclass_references = rb_ary_new();
287
285
  return ret;
288
286
  }
289
287
 
@@ -1635,7 +1633,7 @@ VALUE Builder_alloc(VALUE klass) {
1635
1633
  Builder* self = ALLOC(Builder);
1636
1634
  VALUE ret = TypedData_Wrap_Struct(
1637
1635
  klass, &_Builder_type, self);
1638
- self->pending_list = rb_ary_new();
1636
+ self->pending_list = Qnil;
1639
1637
  self->defs = NULL;
1640
1638
  return ret;
1641
1639
  }
@@ -1645,11 +1643,24 @@ void Builder_register(VALUE module) {
1645
1643
  rb_define_alloc_func(klass, Builder_alloc);
1646
1644
  rb_define_method(klass, "add_message", Builder_add_message, 1);
1647
1645
  rb_define_method(klass, "add_enum", Builder_add_enum, 1);
1646
+ rb_define_method(klass, "initialize", Builder_initialize, 0);
1648
1647
  rb_define_method(klass, "finalize_to_pool", Builder_finalize_to_pool, 1);
1649
1648
  cBuilder = klass;
1650
1649
  rb_gc_register_address(&cBuilder);
1651
1650
  }
1652
1651
 
1652
+ /*
1653
+ * call-seq:
1654
+ * Builder.new(d) => builder
1655
+ *
1656
+ * Create a new message builder.
1657
+ */
1658
+ VALUE Builder_initialize(VALUE _self) {
1659
+ DEFINE_SELF(Builder, self, _self);
1660
+ self->pending_list = rb_ary_new();
1661
+ return Qnil;
1662
+ }
1663
+
1653
1664
  /*
1654
1665
  * call-seq:
1655
1666
  * Builder.add_message(name, &block)
@@ -44,6 +44,56 @@ VALUE noleak_rb_str_cat(VALUE rb_str, const char *str, long len) {
44
44
  return rb_str;
45
45
  }
46
46
 
47
+ // The code below also comes from upb's prototype Ruby binding, developed by
48
+ // haberman@.
49
+
50
+ /* stringsink *****************************************************************/
51
+
52
+ static void *stringsink_start(void *_sink, const void *hd, size_t size_hint) {
53
+ stringsink *sink = _sink;
54
+ sink->len = 0;
55
+ return sink;
56
+ }
57
+
58
+ static size_t stringsink_string(void *_sink, const void *hd, const char *ptr,
59
+ size_t len, const upb_bufhandle *handle) {
60
+ stringsink *sink = _sink;
61
+ size_t new_size = sink->size;
62
+
63
+ UPB_UNUSED(hd);
64
+ UPB_UNUSED(handle);
65
+
66
+ while (sink->len + len > new_size) {
67
+ new_size *= 2;
68
+ }
69
+
70
+ if (new_size != sink->size) {
71
+ sink->ptr = realloc(sink->ptr, new_size);
72
+ sink->size = new_size;
73
+ }
74
+
75
+ memcpy(sink->ptr + sink->len, ptr, len);
76
+ sink->len += len;
77
+
78
+ return len;
79
+ }
80
+
81
+ void stringsink_init(stringsink *sink) {
82
+ upb_byteshandler_init(&sink->handler);
83
+ upb_byteshandler_setstartstr(&sink->handler, stringsink_start, NULL);
84
+ upb_byteshandler_setstring(&sink->handler, stringsink_string, NULL);
85
+
86
+ upb_bytessink_reset(&sink->sink, &sink->handler, sink);
87
+
88
+ sink->size = 32;
89
+ sink->ptr = malloc(sink->size);
90
+ sink->len = 0;
91
+ }
92
+
93
+ void stringsink_uninit(stringsink *sink) {
94
+ free(sink->ptr);
95
+ }
96
+
47
97
  // -----------------------------------------------------------------------------
48
98
  // Parsing.
49
99
  // -----------------------------------------------------------------------------
@@ -613,6 +663,20 @@ static void add_handlers_for_oneof_field(upb_handlers *h,
613
663
  upb_handlerattr_uninit(&attr);
614
664
  }
615
665
 
666
+ static bool unknown_field_handler(void* closure, const void* hd,
667
+ const char* buf, size_t size) {
668
+ UPB_UNUSED(hd);
669
+
670
+ MessageHeader* msg = (MessageHeader*)closure;
671
+ if (msg->unknown_fields == NULL) {
672
+ msg->unknown_fields = malloc(sizeof(stringsink));
673
+ stringsink_init(msg->unknown_fields);
674
+ }
675
+
676
+ stringsink_string(msg->unknown_fields, NULL, buf, size, NULL);
677
+
678
+ return true;
679
+ }
616
680
 
617
681
  static void add_handlers_for_message(const void *closure, upb_handlers *h) {
618
682
  const upb_msgdef* msgdef = upb_handlers_msgdef(h);
@@ -634,6 +698,9 @@ static void add_handlers_for_message(const void *closure, upb_handlers *h) {
634
698
  desc->layout = create_layout(desc->msgdef);
635
699
  }
636
700
 
701
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
702
+ upb_handlers_setunknown(h, unknown_field_handler, &attr);
703
+
637
704
  for (upb_msg_field_begin(&i, desc->msgdef);
638
705
  !upb_msg_field_done(&i);
639
706
  upb_msg_field_next(&i)) {
@@ -831,65 +898,6 @@ VALUE Message_decode_json(VALUE klass, VALUE data) {
831
898
  // -----------------------------------------------------------------------------
832
899
  // Serializing.
833
900
  // -----------------------------------------------------------------------------
834
- //
835
- // The code below also comes from upb's prototype Ruby binding, developed by
836
- // haberman@.
837
-
838
- /* stringsink *****************************************************************/
839
-
840
- // This should probably be factored into a common upb component.
841
-
842
- typedef struct {
843
- upb_byteshandler handler;
844
- upb_bytessink sink;
845
- char *ptr;
846
- size_t len, size;
847
- } stringsink;
848
-
849
- static void *stringsink_start(void *_sink, const void *hd, size_t size_hint) {
850
- stringsink *sink = _sink;
851
- sink->len = 0;
852
- return sink;
853
- }
854
-
855
- static size_t stringsink_string(void *_sink, const void *hd, const char *ptr,
856
- size_t len, const upb_bufhandle *handle) {
857
- stringsink *sink = _sink;
858
- size_t new_size = sink->size;
859
-
860
- UPB_UNUSED(hd);
861
- UPB_UNUSED(handle);
862
-
863
- while (sink->len + len > new_size) {
864
- new_size *= 2;
865
- }
866
-
867
- if (new_size != sink->size) {
868
- sink->ptr = realloc(sink->ptr, new_size);
869
- sink->size = new_size;
870
- }
871
-
872
- memcpy(sink->ptr + sink->len, ptr, len);
873
- sink->len += len;
874
-
875
- return len;
876
- }
877
-
878
- void stringsink_init(stringsink *sink) {
879
- upb_byteshandler_init(&sink->handler);
880
- upb_byteshandler_setstartstr(&sink->handler, stringsink_start, NULL);
881
- upb_byteshandler_setstring(&sink->handler, stringsink_string, NULL);
882
-
883
- upb_bytessink_reset(&sink->sink, &sink->handler, sink);
884
-
885
- sink->size = 32;
886
- sink->ptr = malloc(sink->size);
887
- sink->len = 0;
888
- }
889
-
890
- void stringsink_uninit(stringsink *sink) {
891
- free(sink->ptr);
892
- }
893
901
 
894
902
  /* msgvisitor *****************************************************************/
895
903
 
@@ -1171,6 +1179,11 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc,
1171
1179
  }
1172
1180
  }
1173
1181
 
1182
+ stringsink* unknown = msg->unknown_fields;
1183
+ if (unknown != NULL) {
1184
+ upb_sink_putunknown(sink, unknown->ptr, unknown->len);
1185
+ }
1186
+
1174
1187
  upb_sink_endmsg(sink, &status);
1175
1188
  }
1176
1189
 
@@ -44,6 +44,11 @@ void Message_mark(void* _self) {
44
44
  }
45
45
 
46
46
  void Message_free(void* self) {
47
+ stringsink* unknown = ((MessageHeader *)self)->unknown_fields;
48
+ if (unknown != NULL) {
49
+ stringsink_uninit(unknown);
50
+ free(unknown);
51
+ }
47
52
  xfree(self);
48
53
  }
49
54
 
@@ -67,6 +72,8 @@ VALUE Message_alloc(VALUE klass) {
67
72
  msg->descriptor = desc;
68
73
  rb_ivar_set(ret, descriptor_instancevar_interned, descriptor);
69
74
 
75
+ msg->unknown_fields = NULL;
76
+
70
77
  layout_init(desc->layout, Message_data(msg));
71
78
 
72
79
  return ret;
@@ -217,20 +224,32 @@ VALUE Message_respond_to_missing(int argc, VALUE* argv, VALUE _self) {
217
224
  return Qtrue;
218
225
  }
219
226
 
227
+ VALUE create_submsg_from_hash(const upb_fielddef *f, VALUE hash) {
228
+ const upb_def *d = upb_fielddef_subdef(f);
229
+ assert(d != NULL);
230
+
231
+ VALUE descriptor = get_def_obj(d);
232
+ VALUE msgclass = rb_funcall(descriptor, rb_intern("msgclass"), 0, NULL);
233
+
234
+ VALUE args[1] = { hash };
235
+ return rb_class_new_instance(1, args, msgclass);
236
+ }
237
+
220
238
  int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
221
239
  MessageHeader* self;
222
- VALUE method_str;
223
- char* name;
240
+ char *name;
224
241
  const upb_fielddef* f;
225
242
  TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
226
243
 
227
- if (!SYMBOL_P(key)) {
244
+ if (TYPE(key) == T_STRING) {
245
+ name = RSTRING_PTR(key);
246
+ } else if (TYPE(key) == T_SYMBOL) {
247
+ name = RSTRING_PTR(rb_id2str(SYM2ID(key)));
248
+ } else {
228
249
  rb_raise(rb_eArgError,
229
- "Expected symbols as hash keys in initialization map.");
250
+ "Expected string or symbols as hash keys when initializing proto from hash.");
230
251
  }
231
252
 
232
- method_str = rb_id2str(SYM2ID(key));
233
- name = RSTRING_PTR(method_str);
234
253
  f = upb_msgdef_ntofz(self->descriptor->msgdef, name);
235
254
  if (f == NULL) {
236
255
  rb_raise(rb_eArgError,
@@ -255,9 +274,18 @@ int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
255
274
  }
256
275
  ary = layout_get(self->descriptor->layout, Message_data(self), f);
257
276
  for (int i = 0; i < RARRAY_LEN(val); i++) {
258
- RepeatedField_push(ary, rb_ary_entry(val, i));
277
+ VALUE entry = rb_ary_entry(val, i);
278
+ if (TYPE(entry) == T_HASH && upb_fielddef_issubmsg(f)) {
279
+ entry = create_submsg_from_hash(f, entry);
280
+ }
281
+
282
+ RepeatedField_push(ary, entry);
259
283
  }
260
284
  } else {
285
+ if (TYPE(val) == T_HASH && upb_fielddef_issubmsg(f)) {
286
+ val = create_submsg_from_hash(f, val);
287
+ }
288
+
261
289
  layout_set(self->descriptor->layout, Message_data(self), f, val);
262
290
  }
263
291
  return 0;
@@ -419,6 +447,13 @@ VALUE Message_to_h(VALUE _self) {
419
447
  msg_value = Map_to_h(msg_value);
420
448
  } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
421
449
  msg_value = RepeatedField_to_ary(msg_value);
450
+
451
+ if (upb_fielddef_type(field) == UPB_TYPE_MESSAGE) {
452
+ for (int i = 0; i < RARRAY_LEN(msg_value); i++) {
453
+ VALUE elem = rb_ary_entry(msg_value, i);
454
+ rb_ary_store(msg_value, i, Message_to_h(elem));
455
+ }
456
+ }
422
457
  } else if (msg_value != Qnil &&
423
458
  upb_fielddef_type(field) == UPB_TYPE_MESSAGE) {
424
459
  msg_value = Message_to_h(msg_value);
@@ -110,6 +110,6 @@ void Init_protobuf_c() {
110
110
  kRubyStringASCIIEncoding = rb_usascii_encoding();
111
111
  kRubyString8bitEncoding = rb_ascii8bit_encoding();
112
112
 
113
- upb_def_to_ruby_obj_map = rb_hash_new();
114
113
  rb_gc_register_address(&upb_def_to_ruby_obj_map);
114
+ upb_def_to_ruby_obj_map = rb_hash_new();
115
115
  }
@@ -116,10 +116,6 @@ struct Descriptor {
116
116
  const upb_handlers* pb_serialize_handlers;
117
117
  const upb_handlers* json_serialize_handlers;
118
118
  const upb_handlers* json_serialize_handlers_preserve;
119
- // Handlers hold type class references for sub-message fields directly in some
120
- // cases. We need to keep these rooted because they might otherwise be
121
- // collected.
122
- VALUE typeclass_references;
123
119
  };
124
120
 
125
121
  struct FieldDescriptor {
@@ -280,6 +276,7 @@ void Builder_free(void* _self);
280
276
  VALUE Builder_alloc(VALUE klass);
281
277
  void Builder_register(VALUE module);
282
278
  Builder* ruby_to_Builder(VALUE value);
279
+ VALUE Builder_initialize(VALUE _self);
283
280
  VALUE Builder_add_message(VALUE _self, VALUE name);
284
281
  VALUE Builder_add_enum(VALUE _self, VALUE name);
285
282
  VALUE Builder_finalize_to_pool(VALUE _self, VALUE pool_rb);
@@ -478,8 +475,20 @@ VALUE layout_inspect(MessageLayout* layout, void* storage);
478
475
  // Message class creation.
479
476
  // -----------------------------------------------------------------------------
480
477
 
478
+ // This should probably be factored into a common upb component.
479
+
480
+ typedef struct {
481
+ upb_byteshandler handler;
482
+ upb_bytessink sink;
483
+ char *ptr;
484
+ size_t len, size;
485
+ } stringsink;
486
+
487
+ void stringsink_uninit(stringsink *sink);
488
+
481
489
  struct MessageHeader {
482
- Descriptor* descriptor; // kept alive by self.class.descriptor reference.
490
+ Descriptor* descriptor; // kept alive by self.class.descriptor reference.
491
+ stringsink* unknown_fields; // store unknown fields in decoding.
483
492
  // Data comes after this.
484
493
  };
485
494
 
@@ -176,6 +176,15 @@ void native_slot_set_value_and_case(upb_fieldtype_t type, VALUE type_class,
176
176
  break;
177
177
  }
178
178
  case UPB_TYPE_STRING:
179
+ if (CLASS_OF(value) == rb_cSymbol) {
180
+ value = rb_funcall(value, rb_intern("to_s"), 0, NULL);
181
+ } else if (CLASS_OF(value) != rb_cString) {
182
+ rb_raise(rb_eTypeError, "Invalid argument for string field.");
183
+ }
184
+
185
+ DEREF(memory, VALUE) = native_slot_encode_and_freeze_string(type, value);
186
+ break;
187
+
179
188
  case UPB_TYPE_BYTES: {
180
189
  if (CLASS_OF(value) != rb_cString) {
181
190
  rb_raise(rb_eTypeError, "Invalid argument for string field.");
@@ -197,7 +206,9 @@ void native_slot_set_value_and_case(upb_fieldtype_t type, VALUE type_class,
197
206
  }
198
207
  case UPB_TYPE_ENUM: {
199
208
  int32_t int_val = 0;
200
- if (!is_ruby_num(value) && TYPE(value) != T_SYMBOL) {
209
+ if (TYPE(value) == T_STRING) {
210
+ value = rb_funcall(value, rb_intern("to_sym"), 0, NULL);
211
+ } else if (!is_ruby_num(value) && TYPE(value) != T_SYMBOL) {
201
212
  rb_raise(rb_eTypeError,
202
213
  "Expected number or symbol type for enum field.");
203
214
  }
@@ -2,6 +2,585 @@
2
2
  #include "upb.h"
3
3
 
4
4
 
5
+ /* Maps descriptor type -> upb field type. */
6
+ static const uint8_t upb_desctype_to_fieldtype[] = {
7
+ UPB_WIRE_TYPE_END_GROUP, /* ENDGROUP */
8
+ UPB_TYPE_DOUBLE, /* DOUBLE */
9
+ UPB_TYPE_FLOAT, /* FLOAT */
10
+ UPB_TYPE_INT64, /* INT64 */
11
+ UPB_TYPE_UINT64, /* UINT64 */
12
+ UPB_TYPE_INT32, /* INT32 */
13
+ UPB_TYPE_UINT64, /* FIXED64 */
14
+ UPB_TYPE_UINT32, /* FIXED32 */
15
+ UPB_TYPE_BOOL, /* BOOL */
16
+ UPB_TYPE_STRING, /* STRING */
17
+ UPB_TYPE_MESSAGE, /* GROUP */
18
+ UPB_TYPE_MESSAGE, /* MESSAGE */
19
+ UPB_TYPE_BYTES, /* BYTES */
20
+ UPB_TYPE_UINT32, /* UINT32 */
21
+ UPB_TYPE_ENUM, /* ENUM */
22
+ UPB_TYPE_INT32, /* SFIXED32 */
23
+ UPB_TYPE_INT64, /* SFIXED64 */
24
+ UPB_TYPE_INT32, /* SINT32 */
25
+ UPB_TYPE_INT64, /* SINT64 */
26
+ };
27
+
28
+ /* Data pertaining to the parse. */
29
+ typedef struct {
30
+ upb_env *env;
31
+ /* Current decoding pointer. Points to the beginning of a field until we
32
+ * have finished decoding the whole field. */
33
+ const char *ptr;
34
+ } upb_decstate;
35
+
36
+ /* Data pertaining to a single message frame. */
37
+ typedef struct {
38
+ const char *limit;
39
+ int32_t group_number; /* 0 if we are not parsing a group. */
40
+
41
+ /* These members are unset for an unknown group frame. */
42
+ char *msg;
43
+ const upb_msglayout_msginit_v1 *m;
44
+ } upb_decframe;
45
+
46
+ #define CHK(x) if (!(x)) { return false; }
47
+
48
+ static bool upb_skip_unknowngroup(upb_decstate *d, int field_number,
49
+ const char *limit);
50
+ static bool upb_decode_message(upb_decstate *d, const char *limit,
51
+ int group_number, char *msg,
52
+ const upb_msglayout_msginit_v1 *l);
53
+
54
+ static bool upb_decode_varint(const char **ptr, const char *limit,
55
+ uint64_t *val) {
56
+ uint8_t byte;
57
+ int bitpos = 0;
58
+ const char *p = *ptr;
59
+ *val = 0;
60
+
61
+ do {
62
+ CHK(bitpos < 70 && p < limit);
63
+ byte = *p;
64
+ *val |= (uint64_t)(byte & 0x7F) << bitpos;
65
+ p++;
66
+ bitpos += 7;
67
+ } while (byte & 0x80);
68
+
69
+ *ptr = p;
70
+ return true;
71
+ }
72
+
73
+ static bool upb_decode_varint32(const char **ptr, const char *limit,
74
+ uint32_t *val) {
75
+ uint64_t u64;
76
+ CHK(upb_decode_varint(ptr, limit, &u64) && u64 <= UINT32_MAX);
77
+ *val = u64;
78
+ return true;
79
+ }
80
+
81
+ static bool upb_decode_64bit(const char **ptr, const char *limit,
82
+ uint64_t *val) {
83
+ CHK(limit - *ptr >= 8);
84
+ memcpy(val, *ptr, 8);
85
+ *ptr += 8;
86
+ return true;
87
+ }
88
+
89
+ static bool upb_decode_32bit(const char **ptr, const char *limit,
90
+ uint32_t *val) {
91
+ CHK(limit - *ptr >= 4);
92
+ memcpy(val, *ptr, 4);
93
+ *ptr += 4;
94
+ return true;
95
+ }
96
+
97
+ static bool upb_decode_tag(const char **ptr, const char *limit,
98
+ int *field_number, int *wire_type) {
99
+ uint32_t tag = 0;
100
+ CHK(upb_decode_varint32(ptr, limit, &tag));
101
+ *field_number = tag >> 3;
102
+ *wire_type = tag & 7;
103
+ return true;
104
+ }
105
+
106
+ static int32_t upb_zzdecode_32(uint32_t n) {
107
+ return (n >> 1) ^ -(int32_t)(n & 1);
108
+ }
109
+
110
+ static int64_t upb_zzdecode_64(uint64_t n) {
111
+ return (n >> 1) ^ -(int64_t)(n & 1);
112
+ }
113
+
114
+ static bool upb_decode_string(const char **ptr, const char *limit,
115
+ upb_stringview *val) {
116
+ uint32_t len;
117
+
118
+ CHK(upb_decode_varint32(ptr, limit, &len) &&
119
+ len < INT32_MAX &&
120
+ limit - *ptr >= (int32_t)len);
121
+
122
+ *val = upb_stringview_make(*ptr, len);
123
+ *ptr += len;
124
+ return true;
125
+ }
126
+
127
+ static void upb_set32(void *msg, size_t ofs, uint32_t val) {
128
+ memcpy((char*)msg + ofs, &val, sizeof(val));
129
+ }
130
+
131
+ static bool upb_append_unknown(upb_decstate *d, upb_decframe *frame,
132
+ const char *start) {
133
+ UPB_UNUSED(d);
134
+ UPB_UNUSED(frame);
135
+ UPB_UNUSED(start);
136
+ return true;
137
+ }
138
+
139
+ static bool upb_skip_unknownfielddata(upb_decstate *d, upb_decframe *frame,
140
+ int field_number, int wire_type) {
141
+ switch (wire_type) {
142
+ case UPB_WIRE_TYPE_VARINT: {
143
+ uint64_t val;
144
+ return upb_decode_varint(&d->ptr, frame->limit, &val);
145
+ }
146
+ case UPB_WIRE_TYPE_32BIT: {
147
+ uint32_t val;
148
+ return upb_decode_32bit(&d->ptr, frame->limit, &val);
149
+ }
150
+ case UPB_WIRE_TYPE_64BIT: {
151
+ uint64_t val;
152
+ return upb_decode_64bit(&d->ptr, frame->limit, &val);
153
+ }
154
+ case UPB_WIRE_TYPE_DELIMITED: {
155
+ upb_stringview val;
156
+ return upb_decode_string(&d->ptr, frame->limit, &val);
157
+ }
158
+ case UPB_WIRE_TYPE_START_GROUP:
159
+ return upb_skip_unknowngroup(d, field_number, frame->limit);
160
+ case UPB_WIRE_TYPE_END_GROUP:
161
+ CHK(field_number == frame->group_number);
162
+ frame->limit = d->ptr;
163
+ return true;
164
+ }
165
+ return false;
166
+ }
167
+
168
+ static bool upb_array_grow(upb_array *arr, size_t elements) {
169
+ size_t needed = arr->len + elements;
170
+ size_t new_size = UPB_MAX(arr->size, 8);
171
+ size_t new_bytes;
172
+ size_t old_bytes;
173
+ void *new_data;
174
+
175
+ while (new_size < needed) {
176
+ new_size *= 2;
177
+ }
178
+
179
+ old_bytes = arr->len * arr->element_size;
180
+ new_bytes = new_size * arr->element_size;
181
+ new_data = upb_realloc(arr->alloc, arr->data, old_bytes, new_bytes);
182
+ CHK(new_data);
183
+
184
+ arr->data = new_data;
185
+ arr->size = new_size;
186
+ return true;
187
+ }
188
+
189
+ static void *upb_array_reserve(upb_array *arr, size_t elements) {
190
+ if (arr->size - arr->len < elements) {
191
+ CHK(upb_array_grow(arr, elements));
192
+ }
193
+ return (char*)arr->data + (arr->len * arr->element_size);
194
+ }
195
+
196
+ static void *upb_array_add(upb_array *arr, size_t elements) {
197
+ void *ret = upb_array_reserve(arr, elements);
198
+ arr->len += elements;
199
+ return ret;
200
+ }
201
+
202
+ static upb_array *upb_getarr(upb_decframe *frame,
203
+ const upb_msglayout_fieldinit_v1 *field) {
204
+ UPB_ASSERT(field->label == UPB_LABEL_REPEATED);
205
+ return *(upb_array**)&frame->msg[field->offset];
206
+ }
207
+
208
+ static upb_array *upb_getorcreatearr(upb_decstate *d,
209
+ upb_decframe *frame,
210
+ const upb_msglayout_fieldinit_v1 *field) {
211
+ upb_array *arr = upb_getarr(frame, field);
212
+
213
+ if (!arr) {
214
+ arr = upb_env_malloc(d->env, sizeof(*arr));
215
+ if (!arr) {
216
+ return NULL;
217
+ }
218
+ upb_array_init(arr, upb_desctype_to_fieldtype[field->type],
219
+ upb_arena_alloc(upb_env_arena(d->env)));
220
+ *(upb_array**)&frame->msg[field->offset] = arr;
221
+ }
222
+
223
+ return arr;
224
+ }
225
+
226
+ static void upb_sethasbit(upb_decframe *frame,
227
+ const upb_msglayout_fieldinit_v1 *field) {
228
+ UPB_ASSERT(field->hasbit != UPB_NO_HASBIT);
229
+ frame->msg[field->hasbit / 8] |= (1 << (field->hasbit % 8));
230
+ }
231
+
232
+ static void upb_setoneofcase(upb_decframe *frame,
233
+ const upb_msglayout_fieldinit_v1 *field) {
234
+ UPB_ASSERT(field->oneof_index != UPB_NOT_IN_ONEOF);
235
+ upb_set32(frame->msg, frame->m->oneofs[field->oneof_index].case_offset,
236
+ field->number);
237
+ }
238
+
239
+ static char *upb_decode_prepareslot(upb_decstate *d,
240
+ upb_decframe *frame,
241
+ const upb_msglayout_fieldinit_v1 *field) {
242
+ char *field_mem = frame->msg + field->offset;
243
+ upb_array *arr;
244
+
245
+ if (field->label == UPB_LABEL_REPEATED) {
246
+ arr = upb_getorcreatearr(d, frame, field);
247
+ field_mem = upb_array_reserve(arr, 1);
248
+ }
249
+
250
+ return field_mem;
251
+ }
252
+
253
+ static void upb_decode_setpresent(upb_decframe *frame,
254
+ const upb_msglayout_fieldinit_v1 *field) {
255
+ if (field->label == UPB_LABEL_REPEATED) {
256
+ upb_array *arr = upb_getarr(frame, field);
257
+ UPB_ASSERT(arr->len < arr->size);
258
+ arr->len++;
259
+ } else if (field->oneof_index != UPB_NOT_IN_ONEOF) {
260
+ upb_setoneofcase(frame, field);
261
+ } else if (field->hasbit != UPB_NO_HASBIT) {
262
+ upb_sethasbit(frame, field);
263
+ }
264
+ }
265
+
266
+ static bool upb_decode_submsg(upb_decstate *d,
267
+ upb_decframe *frame,
268
+ const char *limit,
269
+ const upb_msglayout_fieldinit_v1 *field,
270
+ int group_number) {
271
+ char *submsg = *(void**)&frame->msg[field->offset];
272
+ const upb_msglayout_msginit_v1 *subm;
273
+
274
+ UPB_ASSERT(field->submsg_index != UPB_NO_SUBMSG);
275
+ subm = frame->m->submsgs[field->submsg_index];
276
+ UPB_ASSERT(subm);
277
+
278
+ if (!submsg) {
279
+ submsg = upb_env_malloc(d->env, upb_msg_sizeof((upb_msglayout *)subm));
280
+ CHK(submsg);
281
+ submsg = upb_msg_init(
282
+ submsg, (upb_msglayout*)subm, upb_arena_alloc(upb_env_arena(d->env)));
283
+ *(void**)&frame->msg[field->offset] = submsg;
284
+ }
285
+
286
+ upb_decode_message(d, limit, group_number, submsg, subm);
287
+
288
+ return true;
289
+ }
290
+
291
+ static bool upb_decode_varintfield(upb_decstate *d, upb_decframe *frame,
292
+ const char *field_start,
293
+ const upb_msglayout_fieldinit_v1 *field) {
294
+ uint64_t val;
295
+ void *field_mem;
296
+
297
+ field_mem = upb_decode_prepareslot(d, frame, field);
298
+ CHK(field_mem);
299
+ CHK(upb_decode_varint(&d->ptr, frame->limit, &val));
300
+
301
+ switch ((upb_descriptortype_t)field->type) {
302
+ case UPB_DESCRIPTOR_TYPE_INT64:
303
+ case UPB_DESCRIPTOR_TYPE_UINT64:
304
+ memcpy(field_mem, &val, sizeof(val));
305
+ break;
306
+ case UPB_DESCRIPTOR_TYPE_INT32:
307
+ case UPB_DESCRIPTOR_TYPE_UINT32:
308
+ case UPB_DESCRIPTOR_TYPE_ENUM: {
309
+ uint32_t val32 = val;
310
+ memcpy(field_mem, &val32, sizeof(val32));
311
+ break;
312
+ }
313
+ case UPB_DESCRIPTOR_TYPE_BOOL: {
314
+ bool valbool = val != 0;
315
+ memcpy(field_mem, &valbool, sizeof(valbool));
316
+ break;
317
+ }
318
+ case UPB_DESCRIPTOR_TYPE_SINT32: {
319
+ int32_t decoded = upb_zzdecode_32(val);
320
+ memcpy(field_mem, &decoded, sizeof(decoded));
321
+ break;
322
+ }
323
+ case UPB_DESCRIPTOR_TYPE_SINT64: {
324
+ int64_t decoded = upb_zzdecode_64(val);
325
+ memcpy(field_mem, &decoded, sizeof(decoded));
326
+ break;
327
+ }
328
+ default:
329
+ return upb_append_unknown(d, frame, field_start);
330
+ }
331
+
332
+ upb_decode_setpresent(frame, field);
333
+ return true;
334
+ }
335
+
336
+ static bool upb_decode_64bitfield(upb_decstate *d, upb_decframe *frame,
337
+ const char *field_start,
338
+ const upb_msglayout_fieldinit_v1 *field) {
339
+ void *field_mem;
340
+ uint64_t val;
341
+
342
+ field_mem = upb_decode_prepareslot(d, frame, field);
343
+ CHK(field_mem);
344
+ CHK(upb_decode_64bit(&d->ptr, frame->limit, &val));
345
+
346
+ switch ((upb_descriptortype_t)field->type) {
347
+ case UPB_DESCRIPTOR_TYPE_DOUBLE:
348
+ case UPB_DESCRIPTOR_TYPE_FIXED64:
349
+ case UPB_DESCRIPTOR_TYPE_SFIXED64:
350
+ memcpy(field_mem, &val, sizeof(val));
351
+ break;
352
+ default:
353
+ return upb_append_unknown(d, frame, field_start);
354
+ }
355
+
356
+ upb_decode_setpresent(frame, field);
357
+ return true;
358
+ }
359
+
360
+ static bool upb_decode_32bitfield(upb_decstate *d, upb_decframe *frame,
361
+ const char *field_start,
362
+ const upb_msglayout_fieldinit_v1 *field) {
363
+ void *field_mem;
364
+ uint32_t val;
365
+
366
+ field_mem = upb_decode_prepareslot(d, frame, field);
367
+ CHK(field_mem);
368
+ CHK(upb_decode_32bit(&d->ptr, frame->limit, &val));
369
+
370
+ switch ((upb_descriptortype_t)field->type) {
371
+ case UPB_DESCRIPTOR_TYPE_FLOAT:
372
+ case UPB_DESCRIPTOR_TYPE_FIXED32:
373
+ case UPB_DESCRIPTOR_TYPE_SFIXED32:
374
+ memcpy(field_mem, &val, sizeof(val));
375
+ break;
376
+ default:
377
+ return upb_append_unknown(d, frame, field_start);
378
+ }
379
+
380
+ upb_decode_setpresent(frame, field);
381
+ return true;
382
+ }
383
+
384
+ static bool upb_decode_fixedpacked(upb_array *arr, upb_stringview data,
385
+ int elem_size) {
386
+ int elements = data.size / elem_size;
387
+ void *field_mem;
388
+
389
+ CHK((size_t)(elements * elem_size) == data.size);
390
+ field_mem = upb_array_add(arr, elements);
391
+ CHK(field_mem);
392
+ memcpy(field_mem, data.data, data.size);
393
+ return true;
394
+ }
395
+
396
+ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame,
397
+ const char *field_start,
398
+ const upb_msglayout_fieldinit_v1 *field,
399
+ upb_stringview val) {
400
+ upb_array *arr = upb_getorcreatearr(d, frame, field);
401
+
402
+ #define VARINT_CASE(ctype, decode) { \
403
+ const char *ptr = val.data; \
404
+ const char *limit = ptr + val.size; \
405
+ while (ptr < limit) { \
406
+ uint64_t val; \
407
+ void *field_mem; \
408
+ ctype decoded; \
409
+ CHK(upb_decode_varint(&ptr, limit, &val)); \
410
+ decoded = (decode)(val); \
411
+ field_mem = upb_array_add(arr, 1); \
412
+ CHK(field_mem); \
413
+ memcpy(field_mem, &decoded, sizeof(ctype)); \
414
+ } \
415
+ return true; \
416
+ }
417
+
418
+ switch ((upb_descriptortype_t)field->type) {
419
+ case UPB_DESCRIPTOR_TYPE_STRING:
420
+ case UPB_DESCRIPTOR_TYPE_BYTES: {
421
+ void *field_mem = upb_array_add(arr, 1);
422
+ CHK(field_mem);
423
+ memcpy(field_mem, &val, sizeof(val));
424
+ return true;
425
+ }
426
+ case UPB_DESCRIPTOR_TYPE_FLOAT:
427
+ case UPB_DESCRIPTOR_TYPE_FIXED32:
428
+ case UPB_DESCRIPTOR_TYPE_SFIXED32:
429
+ return upb_decode_fixedpacked(arr, val, sizeof(int32_t));
430
+ case UPB_DESCRIPTOR_TYPE_DOUBLE:
431
+ case UPB_DESCRIPTOR_TYPE_FIXED64:
432
+ case UPB_DESCRIPTOR_TYPE_SFIXED64:
433
+ return upb_decode_fixedpacked(arr, val, sizeof(int64_t));
434
+ case UPB_DESCRIPTOR_TYPE_INT32:
435
+ case UPB_DESCRIPTOR_TYPE_UINT32:
436
+ case UPB_DESCRIPTOR_TYPE_ENUM:
437
+ /* TODO: proto2 enum field that isn't in the enum. */
438
+ VARINT_CASE(uint32_t, uint32_t);
439
+ case UPB_DESCRIPTOR_TYPE_INT64:
440
+ case UPB_DESCRIPTOR_TYPE_UINT64:
441
+ VARINT_CASE(uint64_t, uint64_t);
442
+ case UPB_DESCRIPTOR_TYPE_BOOL:
443
+ VARINT_CASE(bool, bool);
444
+ case UPB_DESCRIPTOR_TYPE_SINT32:
445
+ VARINT_CASE(int32_t, upb_zzdecode_32);
446
+ case UPB_DESCRIPTOR_TYPE_SINT64:
447
+ VARINT_CASE(int64_t, upb_zzdecode_64);
448
+ case UPB_DESCRIPTOR_TYPE_MESSAGE:
449
+ CHK(val.size <= (size_t)(frame->limit - val.data));
450
+ return upb_decode_submsg(d, frame, val.data + val.size, field, 0);
451
+ case UPB_DESCRIPTOR_TYPE_GROUP:
452
+ return upb_append_unknown(d, frame, field_start);
453
+ }
454
+ #undef VARINT_CASE
455
+ UPB_UNREACHABLE();
456
+ }
457
+
458
+ static bool upb_decode_delimitedfield(upb_decstate *d, upb_decframe *frame,
459
+ const char *field_start,
460
+ const upb_msglayout_fieldinit_v1 *field) {
461
+ upb_stringview val;
462
+
463
+ CHK(upb_decode_string(&d->ptr, frame->limit, &val));
464
+
465
+ if (field->label == UPB_LABEL_REPEATED) {
466
+ return upb_decode_toarray(d, frame, field_start, field, val);
467
+ } else {
468
+ switch ((upb_descriptortype_t)field->type) {
469
+ case UPB_DESCRIPTOR_TYPE_STRING:
470
+ case UPB_DESCRIPTOR_TYPE_BYTES: {
471
+ void *field_mem = upb_decode_prepareslot(d, frame, field);
472
+ CHK(field_mem);
473
+ memcpy(field_mem, &val, sizeof(val));
474
+ break;
475
+ }
476
+ case UPB_DESCRIPTOR_TYPE_MESSAGE:
477
+ CHK(val.size <= (size_t)(frame->limit - val.data));
478
+ CHK(upb_decode_submsg(d, frame, val.data + val.size, field, 0));
479
+ break;
480
+ default:
481
+ /* TODO(haberman): should we accept the last element of a packed? */
482
+ return upb_append_unknown(d, frame, field_start);
483
+ }
484
+ upb_decode_setpresent(frame, field);
485
+ return true;
486
+ }
487
+ }
488
+
489
+ static const upb_msglayout_fieldinit_v1 *upb_find_field(
490
+ const upb_msglayout_msginit_v1 *l, uint32_t field_number) {
491
+ /* Lots of optimization opportunities here. */
492
+ int i;
493
+ for (i = 0; i < l->field_count; i++) {
494
+ if (l->fields[i].number == field_number) {
495
+ return &l->fields[i];
496
+ }
497
+ }
498
+
499
+ return NULL; /* Unknown field. */
500
+ }
501
+
502
+ static bool upb_decode_field(upb_decstate *d, upb_decframe *frame) {
503
+ int field_number;
504
+ int wire_type;
505
+ const char *field_start = d->ptr;
506
+ const upb_msglayout_fieldinit_v1 *field;
507
+
508
+ CHK(upb_decode_tag(&d->ptr, frame->limit, &field_number, &wire_type));
509
+ field = upb_find_field(frame->m, field_number);
510
+
511
+ if (field) {
512
+ switch (wire_type) {
513
+ case UPB_WIRE_TYPE_VARINT:
514
+ return upb_decode_varintfield(d, frame, field_start, field);
515
+ case UPB_WIRE_TYPE_32BIT:
516
+ return upb_decode_32bitfield(d, frame, field_start, field);
517
+ case UPB_WIRE_TYPE_64BIT:
518
+ return upb_decode_64bitfield(d, frame, field_start, field);
519
+ case UPB_WIRE_TYPE_DELIMITED:
520
+ return upb_decode_delimitedfield(d, frame, field_start, field);
521
+ case UPB_WIRE_TYPE_START_GROUP:
522
+ CHK(field->type == UPB_DESCRIPTOR_TYPE_GROUP);
523
+ return upb_decode_submsg(d, frame, frame->limit, field, field_number);
524
+ case UPB_WIRE_TYPE_END_GROUP:
525
+ CHK(frame->group_number == field_number)
526
+ frame->limit = d->ptr;
527
+ return true;
528
+ default:
529
+ return false;
530
+ }
531
+ } else {
532
+ CHK(field_number != 0);
533
+ return upb_skip_unknownfielddata(d, frame, field_number, wire_type);
534
+ }
535
+ }
536
+
537
+ static bool upb_skip_unknowngroup(upb_decstate *d, int field_number,
538
+ const char *limit) {
539
+ upb_decframe frame;
540
+ frame.msg = NULL;
541
+ frame.m = NULL;
542
+ frame.group_number = field_number;
543
+ frame.limit = limit;
544
+
545
+ while (d->ptr < frame.limit) {
546
+ int wire_type;
547
+ int field_number;
548
+
549
+ CHK(upb_decode_tag(&d->ptr, frame.limit, &field_number, &wire_type));
550
+ CHK(upb_skip_unknownfielddata(d, &frame, field_number, wire_type));
551
+ }
552
+
553
+ return true;
554
+ }
555
+
556
+ static bool upb_decode_message(upb_decstate *d, const char *limit,
557
+ int group_number, char *msg,
558
+ const upb_msglayout_msginit_v1 *l) {
559
+ upb_decframe frame;
560
+ frame.group_number = group_number;
561
+ frame.limit = limit;
562
+ frame.msg = msg;
563
+ frame.m = l;
564
+
565
+ while (d->ptr < frame.limit) {
566
+ CHK(upb_decode_field(d, &frame));
567
+ }
568
+
569
+ return true;
570
+ }
571
+
572
+ bool upb_decode(upb_stringview buf, void *msg,
573
+ const upb_msglayout_msginit_v1 *l, upb_env *env) {
574
+ upb_decstate state;
575
+ state.ptr = buf.data;
576
+ state.env = env;
577
+
578
+ return upb_decode_message(&state, buf.data + buf.size, 0, msg, l);
579
+ }
580
+
581
+ #undef CHK
582
+
583
+
5
584
  #include <ctype.h>
6
585
  #include <stdlib.h>
7
586
  #include <string.h>
@@ -326,6 +905,7 @@ static bool assign_msg_indices(upb_msgdef *m, upb_status *s) {
326
905
  v = upb_value_bool(true);
327
906
  upb_inttable_insert(&t, UPB_STARTMSG_SELECTOR, v);
328
907
  upb_inttable_insert(&t, UPB_ENDMSG_SELECTOR, v);
908
+ upb_inttable_insert(&t, UPB_UNKNOWN_SELECTOR, v);
329
909
  for(upb_msg_field_begin(&j, m);
330
910
  !upb_msg_field_done(&j);
331
911
  upb_msg_field_next(&j)) {
@@ -2308,6 +2888,9 @@ bool upb_symtab_addfile(upb_symtab *s, upb_filedef *file, upb_status *status) {
2308
2888
  bool ret;
2309
2889
 
2310
2890
  n = upb_filedef_defcount(file);
2891
+ if (n == 0) {
2892
+ return true;
2893
+ }
2311
2894
  defs = upb_gmalloc(sizeof(*defs) * n);
2312
2895
 
2313
2896
  if (defs == NULL) {
@@ -2356,6 +2939,397 @@ bool upb_symtab_done(const upb_symtab_iter *iter) {
2356
2939
  const upb_def *upb_symtab_iter_def(const upb_symtab_iter *iter) {
2357
2940
  return upb_value_getptr(upb_strtable_iter_value(&iter->iter));
2358
2941
  }
2942
+ /* We encode backwards, to avoid pre-computing lengths (one-pass encode). */
2943
+
2944
+
2945
+ #define UPB_PB_VARINT_MAX_LEN 10
2946
+ #define CHK(x) do { if (!(x)) { return false; } } while(0)
2947
+
2948
+ /* Maps descriptor type -> upb field type. */
2949
+ static const uint8_t upb_desctype_to_fieldtype2[] = {
2950
+ UPB_WIRE_TYPE_END_GROUP, /* ENDGROUP */
2951
+ UPB_TYPE_DOUBLE, /* DOUBLE */
2952
+ UPB_TYPE_FLOAT, /* FLOAT */
2953
+ UPB_TYPE_INT64, /* INT64 */
2954
+ UPB_TYPE_UINT64, /* UINT64 */
2955
+ UPB_TYPE_INT32, /* INT32 */
2956
+ UPB_TYPE_UINT64, /* FIXED64 */
2957
+ UPB_TYPE_UINT32, /* FIXED32 */
2958
+ UPB_TYPE_BOOL, /* BOOL */
2959
+ UPB_TYPE_STRING, /* STRING */
2960
+ UPB_TYPE_MESSAGE, /* GROUP */
2961
+ UPB_TYPE_MESSAGE, /* MESSAGE */
2962
+ UPB_TYPE_BYTES, /* BYTES */
2963
+ UPB_TYPE_UINT32, /* UINT32 */
2964
+ UPB_TYPE_ENUM, /* ENUM */
2965
+ UPB_TYPE_INT32, /* SFIXED32 */
2966
+ UPB_TYPE_INT64, /* SFIXED64 */
2967
+ UPB_TYPE_INT32, /* SINT32 */
2968
+ UPB_TYPE_INT64, /* SINT64 */
2969
+ };
2970
+
2971
+ static size_t upb_encode_varint(uint64_t val, char *buf) {
2972
+ size_t i;
2973
+ if (val < 128) { buf[0] = val; return 1; }
2974
+ i = 0;
2975
+ while (val) {
2976
+ uint8_t byte = val & 0x7fU;
2977
+ val >>= 7;
2978
+ if (val) byte |= 0x80U;
2979
+ buf[i++] = byte;
2980
+ }
2981
+ return i;
2982
+ }
2983
+
2984
+ static uint32_t upb_zzencode_32(int32_t n) { return (n << 1) ^ (n >> 31); }
2985
+ static uint64_t upb_zzencode_64(int64_t n) { return (n << 1) ^ (n >> 63); }
2986
+
2987
+ typedef struct {
2988
+ upb_env *env;
2989
+ char *buf, *ptr, *limit;
2990
+ } upb_encstate;
2991
+
2992
+ static size_t upb_roundup_pow2(size_t bytes) {
2993
+ size_t ret = 128;
2994
+ while (ret < bytes) {
2995
+ ret *= 2;
2996
+ }
2997
+ return ret;
2998
+ }
2999
+
3000
+ static bool upb_encode_growbuffer(upb_encstate *e, size_t bytes) {
3001
+ size_t old_size = e->limit - e->buf;
3002
+ size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr));
3003
+ char *new_buf = upb_env_realloc(e->env, e->buf, old_size, new_size);
3004
+ CHK(new_buf);
3005
+
3006
+ /* We want previous data at the end, realloc() put it at the beginning. */
3007
+ memmove(e->limit - old_size, e->buf, old_size);
3008
+
3009
+ e->ptr = new_buf + new_size - (e->limit - e->ptr);
3010
+ e->limit = new_buf + new_size;
3011
+ e->buf = new_buf;
3012
+ return true;
3013
+ }
3014
+
3015
+ /* Call to ensure that at least "bytes" bytes are available for writing at
3016
+ * e->ptr. Returns false if the bytes could not be allocated. */
3017
+ static bool upb_encode_reserve(upb_encstate *e, size_t bytes) {
3018
+ CHK(UPB_LIKELY((size_t)(e->ptr - e->buf) >= bytes) ||
3019
+ upb_encode_growbuffer(e, bytes));
3020
+
3021
+ e->ptr -= bytes;
3022
+ return true;
3023
+ }
3024
+
3025
+ /* Writes the given bytes to the buffer, handling reserve/advance. */
3026
+ static bool upb_put_bytes(upb_encstate *e, const void *data, size_t len) {
3027
+ CHK(upb_encode_reserve(e, len));
3028
+ memcpy(e->ptr, data, len);
3029
+ return true;
3030
+ }
3031
+
3032
+ static bool upb_put_fixed64(upb_encstate *e, uint64_t val) {
3033
+ /* TODO(haberman): byte-swap for big endian. */
3034
+ return upb_put_bytes(e, &val, sizeof(uint64_t));
3035
+ }
3036
+
3037
+ static bool upb_put_fixed32(upb_encstate *e, uint32_t val) {
3038
+ /* TODO(haberman): byte-swap for big endian. */
3039
+ return upb_put_bytes(e, &val, sizeof(uint32_t));
3040
+ }
3041
+
3042
+ static bool upb_put_varint(upb_encstate *e, uint64_t val) {
3043
+ size_t len;
3044
+ char *start;
3045
+ CHK(upb_encode_reserve(e, UPB_PB_VARINT_MAX_LEN));
3046
+ len = upb_encode_varint(val, e->ptr);
3047
+ start = e->ptr + UPB_PB_VARINT_MAX_LEN - len;
3048
+ memmove(start, e->ptr, len);
3049
+ e->ptr = start;
3050
+ return true;
3051
+ }
3052
+
3053
+ static bool upb_put_double(upb_encstate *e, double d) {
3054
+ uint64_t u64;
3055
+ UPB_ASSERT(sizeof(double) == sizeof(uint64_t));
3056
+ memcpy(&u64, &d, sizeof(uint64_t));
3057
+ return upb_put_fixed64(e, u64);
3058
+ }
3059
+
3060
+ static bool upb_put_float(upb_encstate *e, float d) {
3061
+ uint32_t u32;
3062
+ UPB_ASSERT(sizeof(float) == sizeof(uint32_t));
3063
+ memcpy(&u32, &d, sizeof(uint32_t));
3064
+ return upb_put_fixed32(e, u32);
3065
+ }
3066
+
3067
+ static uint32_t upb_readcase(const char *msg, const upb_msglayout_msginit_v1 *m,
3068
+ int oneof_index) {
3069
+ uint32_t ret;
3070
+ memcpy(&ret, msg + m->oneofs[oneof_index].case_offset, sizeof(ret));
3071
+ return ret;
3072
+ }
3073
+
3074
+ static bool upb_readhasbit(const char *msg,
3075
+ const upb_msglayout_fieldinit_v1 *f) {
3076
+ UPB_ASSERT(f->hasbit != UPB_NO_HASBIT);
3077
+ return msg[f->hasbit / 8] & (1 << (f->hasbit % 8));
3078
+ }
3079
+
3080
+ static bool upb_put_tag(upb_encstate *e, int field_number, int wire_type) {
3081
+ return upb_put_varint(e, (field_number << 3) | wire_type);
3082
+ }
3083
+
3084
+ static bool upb_put_fixedarray(upb_encstate *e, const upb_array *arr,
3085
+ size_t size) {
3086
+ size_t bytes = arr->len * size;
3087
+ return upb_put_bytes(e, arr->data, bytes) && upb_put_varint(e, bytes);
3088
+ }
3089
+
3090
+ bool upb_encode_message(upb_encstate *e, const char *msg,
3091
+ const upb_msglayout_msginit_v1 *m,
3092
+ size_t *size);
3093
+
3094
+ static bool upb_encode_array(upb_encstate *e, const char *field_mem,
3095
+ const upb_msglayout_msginit_v1 *m,
3096
+ const upb_msglayout_fieldinit_v1 *f) {
3097
+ const upb_array *arr = *(const upb_array**)field_mem;
3098
+
3099
+ if (arr == NULL || arr->len == 0) {
3100
+ return true;
3101
+ }
3102
+
3103
+ UPB_ASSERT(arr->type == upb_desctype_to_fieldtype2[f->type]);
3104
+
3105
+ #define VARINT_CASE(ctype, encode) { \
3106
+ ctype *start = arr->data; \
3107
+ ctype *ptr = start + arr->len; \
3108
+ size_t pre_len = e->limit - e->ptr; \
3109
+ do { \
3110
+ ptr--; \
3111
+ CHK(upb_put_varint(e, encode)); \
3112
+ } while (ptr != start); \
3113
+ CHK(upb_put_varint(e, e->limit - e->ptr - pre_len)); \
3114
+ } \
3115
+ break; \
3116
+ do { ; } while(0)
3117
+
3118
+ switch (f->type) {
3119
+ case UPB_DESCRIPTOR_TYPE_DOUBLE:
3120
+ CHK(upb_put_fixedarray(e, arr, sizeof(double)));
3121
+ break;
3122
+ case UPB_DESCRIPTOR_TYPE_FLOAT:
3123
+ CHK(upb_put_fixedarray(e, arr, sizeof(float)));
3124
+ break;
3125
+ case UPB_DESCRIPTOR_TYPE_SFIXED64:
3126
+ case UPB_DESCRIPTOR_TYPE_FIXED64:
3127
+ CHK(upb_put_fixedarray(e, arr, sizeof(uint64_t)));
3128
+ break;
3129
+ case UPB_DESCRIPTOR_TYPE_FIXED32:
3130
+ case UPB_DESCRIPTOR_TYPE_SFIXED32:
3131
+ CHK(upb_put_fixedarray(e, arr, sizeof(uint32_t)));
3132
+ break;
3133
+ case UPB_DESCRIPTOR_TYPE_INT64:
3134
+ case UPB_DESCRIPTOR_TYPE_UINT64:
3135
+ VARINT_CASE(uint64_t, *ptr);
3136
+ case UPB_DESCRIPTOR_TYPE_UINT32:
3137
+ case UPB_DESCRIPTOR_TYPE_INT32:
3138
+ case UPB_DESCRIPTOR_TYPE_ENUM:
3139
+ VARINT_CASE(uint32_t, *ptr);
3140
+ case UPB_DESCRIPTOR_TYPE_BOOL:
3141
+ VARINT_CASE(bool, *ptr);
3142
+ case UPB_DESCRIPTOR_TYPE_SINT32:
3143
+ VARINT_CASE(int32_t, upb_zzencode_32(*ptr));
3144
+ case UPB_DESCRIPTOR_TYPE_SINT64:
3145
+ VARINT_CASE(int64_t, upb_zzencode_64(*ptr));
3146
+ case UPB_DESCRIPTOR_TYPE_STRING:
3147
+ case UPB_DESCRIPTOR_TYPE_BYTES: {
3148
+ upb_stringview *start = arr->data;
3149
+ upb_stringview *ptr = start + arr->len;
3150
+ do {
3151
+ ptr--;
3152
+ CHK(upb_put_bytes(e, ptr->data, ptr->size) &&
3153
+ upb_put_varint(e, ptr->size) &&
3154
+ upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
3155
+ } while (ptr != start);
3156
+ return true;
3157
+ }
3158
+ case UPB_DESCRIPTOR_TYPE_GROUP: {
3159
+ void **start = arr->data;
3160
+ void **ptr = start + arr->len;
3161
+ const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index];
3162
+ do {
3163
+ size_t size;
3164
+ ptr--;
3165
+ CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) &&
3166
+ upb_encode_message(e, *ptr, subm, &size) &&
3167
+ upb_put_tag(e, f->number, UPB_WIRE_TYPE_START_GROUP));
3168
+ } while (ptr != start);
3169
+ return true;
3170
+ }
3171
+ case UPB_DESCRIPTOR_TYPE_MESSAGE: {
3172
+ void **start = arr->data;
3173
+ void **ptr = start + arr->len;
3174
+ const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index];
3175
+ do {
3176
+ size_t size;
3177
+ ptr--;
3178
+ CHK(upb_encode_message(e, *ptr, subm, &size) &&
3179
+ upb_put_varint(e, size) &&
3180
+ upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
3181
+ } while (ptr != start);
3182
+ return true;
3183
+ }
3184
+ }
3185
+ #undef VARINT_CASE
3186
+
3187
+ /* We encode all primitive arrays as packed, regardless of what was specified
3188
+ * in the .proto file. Could special case 1-sized arrays. */
3189
+ CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
3190
+ return true;
3191
+ }
3192
+
3193
+ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem,
3194
+ const upb_msglayout_msginit_v1 *m,
3195
+ const upb_msglayout_fieldinit_v1 *f,
3196
+ bool is_proto3) {
3197
+ bool skip_zero_value = is_proto3 && f->oneof_index == UPB_NOT_IN_ONEOF;
3198
+
3199
+ #define CASE(ctype, type, wire_type, encodeval) do { \
3200
+ ctype val = *(ctype*)field_mem; \
3201
+ if (skip_zero_value && val == 0) { \
3202
+ return true; \
3203
+ } \
3204
+ return upb_put_ ## type(e, encodeval) && \
3205
+ upb_put_tag(e, f->number, wire_type); \
3206
+ } while(0)
3207
+
3208
+ switch (f->type) {
3209
+ case UPB_DESCRIPTOR_TYPE_DOUBLE:
3210
+ CASE(double, double, UPB_WIRE_TYPE_64BIT, val);
3211
+ case UPB_DESCRIPTOR_TYPE_FLOAT:
3212
+ CASE(float, float, UPB_WIRE_TYPE_32BIT, val);
3213
+ case UPB_DESCRIPTOR_TYPE_INT64:
3214
+ case UPB_DESCRIPTOR_TYPE_UINT64:
3215
+ CASE(uint64_t, varint, UPB_WIRE_TYPE_VARINT, val);
3216
+ case UPB_DESCRIPTOR_TYPE_UINT32:
3217
+ case UPB_DESCRIPTOR_TYPE_INT32:
3218
+ case UPB_DESCRIPTOR_TYPE_ENUM:
3219
+ CASE(uint32_t, varint, UPB_WIRE_TYPE_VARINT, val);
3220
+ case UPB_DESCRIPTOR_TYPE_SFIXED64:
3221
+ case UPB_DESCRIPTOR_TYPE_FIXED64:
3222
+ CASE(uint64_t, fixed64, UPB_WIRE_TYPE_64BIT, val);
3223
+ case UPB_DESCRIPTOR_TYPE_FIXED32:
3224
+ case UPB_DESCRIPTOR_TYPE_SFIXED32:
3225
+ CASE(uint32_t, fixed32, UPB_WIRE_TYPE_32BIT, val);
3226
+ case UPB_DESCRIPTOR_TYPE_BOOL:
3227
+ CASE(bool, varint, UPB_WIRE_TYPE_VARINT, val);
3228
+ case UPB_DESCRIPTOR_TYPE_SINT32:
3229
+ CASE(int32_t, varint, UPB_WIRE_TYPE_VARINT, upb_zzencode_32(val));
3230
+ case UPB_DESCRIPTOR_TYPE_SINT64:
3231
+ CASE(int64_t, varint, UPB_WIRE_TYPE_VARINT, upb_zzencode_64(val));
3232
+ case UPB_DESCRIPTOR_TYPE_STRING:
3233
+ case UPB_DESCRIPTOR_TYPE_BYTES: {
3234
+ upb_stringview view = *(upb_stringview*)field_mem;
3235
+ if (skip_zero_value && view.size == 0) {
3236
+ return true;
3237
+ }
3238
+ return upb_put_bytes(e, view.data, view.size) &&
3239
+ upb_put_varint(e, view.size) &&
3240
+ upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED);
3241
+ }
3242
+ case UPB_DESCRIPTOR_TYPE_GROUP: {
3243
+ size_t size;
3244
+ void *submsg = *(void**)field_mem;
3245
+ const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index];
3246
+ if (skip_zero_value && submsg == NULL) {
3247
+ return true;
3248
+ }
3249
+ return upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) &&
3250
+ upb_encode_message(e, submsg, subm, &size) &&
3251
+ upb_put_tag(e, f->number, UPB_WIRE_TYPE_START_GROUP);
3252
+ }
3253
+ case UPB_DESCRIPTOR_TYPE_MESSAGE: {
3254
+ size_t size;
3255
+ void *submsg = *(void**)field_mem;
3256
+ const upb_msglayout_msginit_v1 *subm = m->submsgs[f->submsg_index];
3257
+ if (skip_zero_value && submsg == NULL) {
3258
+ return true;
3259
+ }
3260
+ return upb_encode_message(e, submsg, subm, &size) &&
3261
+ upb_put_varint(e, size) &&
3262
+ upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED);
3263
+ }
3264
+ }
3265
+ #undef CASE
3266
+ UPB_UNREACHABLE();
3267
+ }
3268
+
3269
+ bool upb_encode_hasscalarfield(const char *msg,
3270
+ const upb_msglayout_msginit_v1 *m,
3271
+ const upb_msglayout_fieldinit_v1 *f) {
3272
+ if (f->oneof_index != UPB_NOT_IN_ONEOF) {
3273
+ return upb_readcase(msg, m, f->oneof_index) == f->number;
3274
+ } else if (m->is_proto2) {
3275
+ return upb_readhasbit(msg, f);
3276
+ } else {
3277
+ /* For proto3, we'll test for the field being empty later. */
3278
+ return true;
3279
+ }
3280
+ }
3281
+
3282
+ bool upb_encode_message(upb_encstate* e, const char *msg,
3283
+ const upb_msglayout_msginit_v1 *m,
3284
+ size_t *size) {
3285
+ int i;
3286
+ char *buf_end = e->ptr;
3287
+
3288
+ if (msg == NULL) {
3289
+ return true;
3290
+ }
3291
+
3292
+ for (i = m->field_count - 1; i >= 0; i--) {
3293
+ const upb_msglayout_fieldinit_v1 *f = &m->fields[i];
3294
+
3295
+ if (f->label == UPB_LABEL_REPEATED) {
3296
+ CHK(upb_encode_array(e, msg + f->offset, m, f));
3297
+ } else {
3298
+ if (upb_encode_hasscalarfield(msg, m, f)) {
3299
+ CHK(upb_encode_scalarfield(e, msg + f->offset, m, f, !m->is_proto2));
3300
+ }
3301
+ }
3302
+ }
3303
+
3304
+ *size = buf_end - e->ptr;
3305
+ return true;
3306
+ }
3307
+
3308
+ char *upb_encode(const void *msg, const upb_msglayout_msginit_v1 *m,
3309
+ upb_env *env, size_t *size) {
3310
+ upb_encstate e;
3311
+ e.env = env;
3312
+ e.buf = NULL;
3313
+ e.limit = NULL;
3314
+ e.ptr = NULL;
3315
+
3316
+ if (!upb_encode_message(&e, msg, m, size)) {
3317
+ *size = 0;
3318
+ return NULL;
3319
+ }
3320
+
3321
+ *size = e.limit - e.ptr;
3322
+
3323
+ if (*size == 0) {
3324
+ static char ch;
3325
+ return &ch;
3326
+ } else {
3327
+ UPB_ASSERT(e.ptr);
3328
+ return e.ptr;
3329
+ }
3330
+ }
3331
+
3332
+ #undef CHK
2359
3333
  /*
2360
3334
  ** TODO(haberman): it's unclear whether a lot of the consistency checks should
2361
3335
  ** UPB_ASSERT() or return false.
@@ -2727,6 +3701,12 @@ SETTER(endseq, upb_endfield_handlerfunc*, UPB_HANDLER_ENDSEQ)
2727
3701
 
2728
3702
  #undef SETTER
2729
3703
 
3704
+ bool upb_handlers_setunknown(upb_handlers *h, upb_unknown_handlerfunc *func,
3705
+ upb_handlerattr *attr) {
3706
+ return doset(h, UPB_UNKNOWN_SELECTOR, NULL, UPB_HANDLER_INT32,
3707
+ (upb_func *)func, attr);
3708
+ }
3709
+
2730
3710
  bool upb_handlers_setstartmsg(upb_handlers *h, upb_startmsg_handlerfunc *func,
2731
3711
  upb_handlerattr *attr) {
2732
3712
  return doset(h, UPB_STARTMSG_SELECTOR, NULL, UPB_HANDLER_INT32,
@@ -3076,7 +4056,8 @@ bool upb_fieldtype_mapkeyok(upb_fieldtype_t type) {
3076
4056
  void *upb_array_pack(const upb_array *arr, void *p, size_t *ofs, size_t size);
3077
4057
  void *upb_map_pack(const upb_map *map, void *p, size_t *ofs, size_t size);
3078
4058
 
3079
- #define CHARPTR_AT(msg, ofs) ((char*)msg + ofs)
4059
+ #define PTR_AT(msg, ofs, type) (type*)((char*)msg + ofs)
4060
+ #define VOIDPTR_AT(msg, ofs) PTR_AT(msg, ofs, void)
3080
4061
  #define ENCODE_MAX_NESTING 64
3081
4062
  #define CHECK_TRUE(x) if (!(x)) { return false; }
3082
4063
 
@@ -3118,12 +4099,20 @@ static size_t upb_msgval_sizeof(upb_fieldtype_t type) {
3118
4099
  case UPB_TYPE_MESSAGE:
3119
4100
  return sizeof(void*);
3120
4101
  case UPB_TYPE_STRING:
3121
- return sizeof(char*) + sizeof(size_t);
4102
+ return sizeof(upb_stringview);
3122
4103
  }
3123
4104
  UPB_UNREACHABLE();
3124
4105
  }
3125
4106
 
3126
- static uint8_t upb_msg_fieldsize(const upb_fielddef *f) {
4107
+ static uint8_t upb_msg_fieldsize(const upb_msglayout_fieldinit_v1 *field) {
4108
+ if (field->label == UPB_LABEL_REPEATED) {
4109
+ return sizeof(void*);
4110
+ } else {
4111
+ return upb_msgval_sizeof(field->type);
4112
+ }
4113
+ }
4114
+
4115
+ static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) {
3127
4116
  if (upb_fielddef_isseq(f)) {
3128
4117
  return sizeof(void*);
3129
4118
  } else {
@@ -3167,7 +4156,6 @@ static upb_ctype_t upb_fieldtotabtype(upb_fieldtype_t type) {
3167
4156
  }
3168
4157
 
3169
4158
  static upb_msgval upb_msgval_fromdefault(const upb_fielddef *f) {
3170
- /* TODO(haberman): improve/optimize this (maybe use upb_msgval in fielddef) */
3171
4159
  switch (upb_fielddef_type(f)) {
3172
4160
  case UPB_TYPE_FLOAT:
3173
4161
  return upb_msgval_float(upb_fielddef_defaultfloat(f));
@@ -3179,7 +4167,7 @@ static upb_msgval upb_msgval_fromdefault(const upb_fielddef *f) {
3179
4167
  case UPB_TYPE_BYTES: {
3180
4168
  size_t len;
3181
4169
  const char *ptr = upb_fielddef_defaultstr(f, &len);
3182
- return upb_msgval_str(ptr, len);
4170
+ return upb_msgval_makestr(ptr, len);
3183
4171
  }
3184
4172
  case UPB_TYPE_MESSAGE:
3185
4173
  return upb_msgval_msg(NULL);
@@ -3202,63 +4190,44 @@ static upb_msgval upb_msgval_fromdefault(const upb_fielddef *f) {
3202
4190
  /** upb_msglayout *************************************************************/
3203
4191
 
3204
4192
  struct upb_msglayout {
3205
- upb_msgfactory *factory;
3206
- const upb_msgdef *msgdef;
3207
- size_t size;
3208
- size_t extdict_offset;
3209
- void *default_msg;
3210
- uint32_t *field_offsets;
3211
- uint32_t *case_offsets;
3212
- uint32_t *hasbits;
3213
- bool has_extdict;
3214
- uint8_t align;
4193
+ struct upb_msglayout_msginit_v1 data;
3215
4194
  };
3216
4195
 
3217
- static void upb_msg_checkfield(const upb_msglayout *l, const upb_fielddef *f) {
3218
- UPB_ASSERT(l->msgdef == upb_fielddef_containingtype(f));
3219
- }
3220
-
3221
4196
  static void upb_msglayout_free(upb_msglayout *l) {
3222
- upb_gfree(l->default_msg);
4197
+ upb_gfree(l->data.default_msg);
3223
4198
  upb_gfree(l);
3224
4199
  }
3225
4200
 
3226
- const upb_msgdef *upb_msglayout_msgdef(const upb_msglayout *l) {
3227
- return l->msgdef;
3228
- }
3229
-
3230
4201
  static size_t upb_msglayout_place(upb_msglayout *l, size_t size) {
3231
4202
  size_t ret;
3232
4203
 
3233
- l->size = align_up(l->size, size);
3234
- l->align = align_up(l->align, size);
3235
- ret = l->size;
3236
- l->size += size;
4204
+ l->data.size = align_up(l->data.size, size);
4205
+ ret = l->data.size;
4206
+ l->data.size += size;
3237
4207
  return ret;
3238
4208
  }
3239
4209
 
3240
4210
  static uint32_t upb_msglayout_offset(const upb_msglayout *l,
3241
4211
  const upb_fielddef *f) {
3242
- return l->field_offsets[upb_fielddef_index(f)];
4212
+ return l->data.fields[upb_fielddef_index(f)].offset;
3243
4213
  }
3244
4214
 
3245
4215
  static uint32_t upb_msglayout_hasbit(const upb_msglayout *l,
3246
4216
  const upb_fielddef *f) {
3247
- return l->hasbits[upb_fielddef_index(f)];
4217
+ return l->data.fields[upb_fielddef_index(f)].hasbit;
3248
4218
  }
3249
4219
 
3250
- static bool upb_msglayout_initdefault(upb_msglayout *l) {
3251
- const upb_msgdef *m = l->msgdef;
4220
+ static bool upb_msglayout_initdefault(upb_msglayout *l, const upb_msgdef *m) {
3252
4221
  upb_msg_field_iter it;
3253
4222
 
3254
- if (upb_msgdef_syntax(m) == UPB_SYNTAX_PROTO2 && l->size) {
4223
+ if (upb_msgdef_syntax(m) == UPB_SYNTAX_PROTO2 && l->data.size) {
3255
4224
  /* Allocate default message and set default values in it. */
3256
- l->default_msg = upb_gmalloc(l->size);
3257
- if (!l->default_msg) {
4225
+ l->data.default_msg = upb_gmalloc(l->data.size);
4226
+ if (!l->data.default_msg) {
3258
4227
  return false;
3259
4228
  }
3260
4229
 
3261
- memset(l->default_msg, 0, l->size);
4230
+ memset(l->data.default_msg, 0, l->data.size);
3262
4231
 
3263
4232
  for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it);
3264
4233
  upb_msg_field_next(&it)) {
@@ -3268,10 +4237,14 @@ static bool upb_msglayout_initdefault(upb_msglayout *l) {
3268
4237
  continue;
3269
4238
  }
3270
4239
 
4240
+ /* TODO(haberman): handle strings. */
3271
4241
  if (!upb_fielddef_isstring(f) &&
3272
4242
  !upb_fielddef_issubmsg(f) &&
3273
4243
  !upb_fielddef_isseq(f)) {
3274
- upb_msg_set(l->default_msg, f, upb_msgval_fromdefault(f), l);
4244
+ upb_msg_set(l->data.default_msg,
4245
+ upb_fielddef_index(f),
4246
+ upb_msgval_fromdefault(f),
4247
+ l);
3275
4248
  }
3276
4249
  }
3277
4250
  }
@@ -3284,22 +4257,46 @@ static upb_msglayout *upb_msglayout_new(const upb_msgdef *m) {
3284
4257
  upb_msg_oneof_iter oit;
3285
4258
  upb_msglayout *l;
3286
4259
  size_t hasbit;
3287
- size_t array_size = upb_msgdef_numfields(m) + upb_msgdef_numoneofs(m);
4260
+ size_t submsg_count = 0;
4261
+ const upb_msglayout_msginit_v1 **submsgs;
4262
+ upb_msglayout_fieldinit_v1 *fields;
4263
+ upb_msglayout_oneofinit_v1 *oneofs;
3288
4264
 
3289
- if (upb_msgdef_syntax(m) == UPB_SYNTAX_PROTO2) {
3290
- array_size += upb_msgdef_numfields(m); /* hasbits. */
4265
+ for (upb_msg_field_begin(&it, m);
4266
+ !upb_msg_field_done(&it);
4267
+ upb_msg_field_next(&it)) {
4268
+ const upb_fielddef* f = upb_msg_iter_field(&it);
4269
+ if (upb_fielddef_issubmsg(f)) {
4270
+ submsg_count++;
4271
+ }
3291
4272
  }
3292
4273
 
3293
- l = upb_gmalloc(sizeof(*l) + (sizeof(uint32_t) * array_size));
4274
+ l = upb_gmalloc(sizeof(*l));
3294
4275
  if (!l) return NULL;
3295
4276
 
3296
4277
  memset(l, 0, sizeof(*l));
3297
4278
 
3298
- l->msgdef = m;
3299
- l->align = 1;
3300
- l->field_offsets = (uint32_t*)CHARPTR_AT(l, sizeof(*l));
3301
- l->case_offsets = l->field_offsets + upb_msgdef_numfields(m);
3302
- l->hasbits = l->case_offsets + upb_msgdef_numoneofs(m);
4279
+ fields = upb_gmalloc(upb_msgdef_numfields(m) * sizeof(*fields));
4280
+ submsgs = upb_gmalloc(submsg_count * sizeof(*submsgs));
4281
+ oneofs = upb_gmalloc(upb_msgdef_numoneofs(m) * sizeof(*oneofs));
4282
+
4283
+ if ((!fields && upb_msgdef_numfields(m)) ||
4284
+ (!submsgs && submsg_count) ||
4285
+ (!oneofs && upb_msgdef_numoneofs(m))) {
4286
+ /* OOM. */
4287
+ upb_gfree(l);
4288
+ upb_gfree(fields);
4289
+ upb_gfree(submsgs);
4290
+ upb_gfree(oneofs);
4291
+ return NULL;
4292
+ }
4293
+
4294
+ l->data.field_count = upb_msgdef_numfields(m);
4295
+ l->data.oneof_count = upb_msgdef_numoneofs(m);
4296
+ l->data.fields = fields;
4297
+ l->data.submsgs = submsgs;
4298
+ l->data.oneofs = oneofs;
4299
+ l->data.is_proto2 = (upb_msgdef_syntax(m) == UPB_SYNTAX_PROTO2);
3303
4300
 
3304
4301
  /* Allocate data offsets in three stages:
3305
4302
  *
@@ -3310,74 +4307,75 @@ static upb_msglayout *upb_msglayout_new(const upb_msgdef *m) {
3310
4307
  * OPT: There is a lot of room for optimization here to minimize the size.
3311
4308
  */
3312
4309
 
3313
- /* Allocate hasbits. Start at sizeof(void*) for upb_alloc*. */
3314
- for (upb_msg_field_begin(&it, m), hasbit = sizeof(void*) * 8;
4310
+ /* Allocate hasbits and set basic field attributes. */
4311
+ for (upb_msg_field_begin(&it, m), hasbit = 0;
3315
4312
  !upb_msg_field_done(&it);
3316
4313
  upb_msg_field_next(&it)) {
3317
4314
  const upb_fielddef* f = upb_msg_iter_field(&it);
4315
+ upb_msglayout_fieldinit_v1 *field = &fields[upb_fielddef_index(f)];
4316
+
4317
+ field->number = upb_fielddef_number(f);
4318
+ field->type = upb_fielddef_type(f);
4319
+ field->label = upb_fielddef_label(f);
4320
+
4321
+ if (upb_fielddef_containingoneof(f)) {
4322
+ field->oneof_index = upb_oneofdef_index(upb_fielddef_containingoneof(f));
4323
+ } else {
4324
+ field->oneof_index = UPB_NOT_IN_ONEOF;
4325
+ }
3318
4326
 
3319
4327
  if (upb_fielddef_haspresence(f) && !upb_fielddef_containingoneof(f)) {
3320
- l->hasbits[upb_fielddef_index(f)] = hasbit++;
4328
+ field->hasbit = hasbit++;
3321
4329
  }
3322
4330
  }
3323
4331
 
3324
4332
  /* Account for space used by hasbits. */
3325
- l->size = div_round_up(hasbit, 8);
4333
+ l->data.size = div_round_up(hasbit, 8);
3326
4334
 
3327
4335
  /* Allocate non-oneof fields. */
3328
4336
  for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it);
3329
4337
  upb_msg_field_next(&it)) {
3330
4338
  const upb_fielddef* f = upb_msg_iter_field(&it);
3331
- size_t field_size = upb_msg_fieldsize(f);
4339
+ size_t field_size = upb_msg_fielddefsize(f);
3332
4340
  size_t index = upb_fielddef_index(f);
3333
4341
 
3334
-
3335
4342
  if (upb_fielddef_containingoneof(f)) {
3336
4343
  /* Oneofs are handled separately below. */
3337
4344
  continue;
3338
4345
  }
3339
4346
 
3340
- l->field_offsets[index] = upb_msglayout_place(l, field_size);
4347
+ fields[index].offset = upb_msglayout_place(l, field_size);
3341
4348
  }
3342
4349
 
3343
4350
  /* Allocate oneof fields. Each oneof field consists of a uint32 for the case
3344
4351
  * and space for the actual data. */
3345
4352
  for (upb_msg_oneof_begin(&oit, m); !upb_msg_oneof_done(&oit);
3346
4353
  upb_msg_oneof_next(&oit)) {
3347
- const upb_oneofdef* oneof = upb_msg_iter_oneof(&oit);
4354
+ const upb_oneofdef* o = upb_msg_iter_oneof(&oit);
3348
4355
  upb_oneof_iter fit;
4356
+
3349
4357
  size_t case_size = sizeof(uint32_t); /* Could potentially optimize this. */
4358
+ upb_msglayout_oneofinit_v1 *oneof = &oneofs[upb_oneofdef_index(o)];
3350
4359
  size_t field_size = 0;
3351
- size_t case_offset;
3352
- size_t val_offset;
3353
4360
 
3354
4361
  /* Calculate field size: the max of all field sizes. */
3355
- for (upb_oneof_begin(&fit, oneof);
4362
+ for (upb_oneof_begin(&fit, o);
3356
4363
  !upb_oneof_done(&fit);
3357
4364
  upb_oneof_next(&fit)) {
3358
4365
  const upb_fielddef* f = upb_oneof_iter_field(&fit);
3359
- field_size = UPB_MAX(field_size, upb_msg_fieldsize(f));
4366
+ field_size = UPB_MAX(field_size, upb_msg_fielddefsize(f));
3360
4367
  }
3361
4368
 
3362
4369
  /* Align and allocate case offset. */
3363
- case_offset = upb_msglayout_place(l, case_size);
3364
- val_offset = upb_msglayout_place(l, field_size);
3365
-
3366
- l->case_offsets[upb_oneofdef_index(oneof)] = case_offset;
3367
-
3368
- /* Assign all fields in the oneof this same offset. */
3369
- for (upb_oneof_begin(&fit, oneof); !upb_oneof_done(&fit);
3370
- upb_oneof_next(&fit)) {
3371
- const upb_fielddef* f = upb_oneof_iter_field(&fit);
3372
- l->field_offsets[upb_fielddef_index(f)] = val_offset;
3373
- }
4370
+ oneof->case_offset = upb_msglayout_place(l, case_size);
4371
+ oneof->data_offset = upb_msglayout_place(l, field_size);
3374
4372
  }
3375
4373
 
3376
4374
  /* Size of the entire structure should be a multiple of its greatest
3377
- * alignment. */
3378
- l->size = align_up(l->size, l->align);
4375
+ * alignment. TODO: track overall alignment for real? */
4376
+ l->data.size = align_up(l->data.size, 8);
3379
4377
 
3380
- if (upb_msglayout_initdefault(l)) {
4378
+ if (upb_msglayout_initdefault(l, m)) {
3381
4379
  return l;
3382
4380
  } else {
3383
4381
  upb_msglayout_free(l);
@@ -3385,10 +4383,6 @@ static upb_msglayout *upb_msglayout_new(const upb_msgdef *m) {
3385
4383
  }
3386
4384
  }
3387
4385
 
3388
- upb_msgfactory *upb_msglayout_factory(const upb_msglayout *layout) {
3389
- return layout->factory;
3390
- }
3391
-
3392
4386
 
3393
4387
  /** upb_msgfactory ************************************************************/
3394
4388
 
@@ -3445,7 +4439,6 @@ const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f,
3445
4439
  upb_msglayout *l = upb_msglayout_new(m);
3446
4440
  upb_inttable_insertptr(&mutable_f->layouts, m, upb_value_ptr(l));
3447
4441
  UPB_ASSERT(l);
3448
- l->factory = f;
3449
4442
  return l;
3450
4443
  }
3451
4444
  }
@@ -3454,16 +4447,15 @@ const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f,
3454
4447
 
3455
4448
  void *upb_msg_startstr(void *msg, const void *hd, size_t size_hint) {
3456
4449
  uint32_t ofs = (uintptr_t)hd;
3457
- /* We pass NULL here because we know we can get away with it. */
3458
- upb_alloc *alloc = upb_msg_alloc(msg, NULL);
4450
+ upb_alloc *alloc = upb_msg_alloc(msg);
3459
4451
  upb_msgval val;
3460
4452
  UPB_UNUSED(size_hint);
3461
4453
 
3462
4454
  val = upb_msgval_read(msg, ofs, upb_msgval_sizeof(UPB_TYPE_STRING));
3463
4455
 
3464
- upb_free(alloc, (void*)val.str.ptr);
3465
- val.str.ptr = NULL;
3466
- val.str.len = 0;
4456
+ upb_free(alloc, (void*)val.str.data);
4457
+ val.str.data = NULL;
4458
+ val.str.size = 0;
3467
4459
 
3468
4460
  upb_msgval_write(msg, ofs, val, upb_msgval_sizeof(UPB_TYPE_STRING));
3469
4461
  return msg;
@@ -3472,23 +4464,22 @@ void *upb_msg_startstr(void *msg, const void *hd, size_t size_hint) {
3472
4464
  size_t upb_msg_str(void *msg, const void *hd, const char *ptr, size_t size,
3473
4465
  const upb_bufhandle *handle) {
3474
4466
  uint32_t ofs = (uintptr_t)hd;
3475
- /* We pass NULL here because we know we can get away with it. */
3476
- upb_alloc *alloc = upb_msg_alloc(msg, NULL);
4467
+ upb_alloc *alloc = upb_msg_alloc(msg);
3477
4468
  upb_msgval val;
3478
4469
  size_t newsize;
3479
4470
  UPB_UNUSED(handle);
3480
4471
 
3481
4472
  val = upb_msgval_read(msg, ofs, upb_msgval_sizeof(UPB_TYPE_STRING));
3482
4473
 
3483
- newsize = val.str.len + size;
3484
- val.str.ptr = upb_realloc(alloc, (void*)val.str.ptr, val.str.len, newsize);
4474
+ newsize = val.str.size + size;
4475
+ val.str.data = upb_realloc(alloc, (void*)val.str.data, val.str.size, newsize);
3485
4476
 
3486
- if (!val.str.ptr) {
4477
+ if (!val.str.data) {
3487
4478
  return false;
3488
4479
  }
3489
4480
 
3490
- memcpy((char*)val.str.ptr + val.str.len, ptr, size);
3491
- val.str.len = newsize;
4481
+ memcpy((char*)val.str.data + val.str.size, ptr, size);
4482
+ val.str.size = newsize;
3492
4483
  upb_msgval_write(msg, ofs, val, upb_msgval_sizeof(UPB_TYPE_STRING));
3493
4484
  return size;
3494
4485
  }
@@ -3553,13 +4544,14 @@ static upb_selector_t getsel2(const upb_fielddef *f, upb_handlertype_t type) {
3553
4544
 
3554
4545
  static bool upb_visitor_hasfield(const upb_msg *msg, const upb_fielddef *f,
3555
4546
  const upb_msglayout *layout) {
4547
+ int field_index = upb_fielddef_index(f);
3556
4548
  if (upb_fielddef_isseq(f)) {
3557
- return upb_msgval_getarr(upb_msg_get(msg, f, layout)) != NULL;
4549
+ return upb_msgval_getarr(upb_msg_get(msg, field_index, layout)) != NULL;
3558
4550
  } else if (upb_msgdef_syntax(upb_fielddef_containingtype(f)) ==
3559
4551
  UPB_SYNTAX_PROTO2) {
3560
- return upb_msg_has(msg, f, layout);
4552
+ return upb_msg_has(msg, field_index, layout);
3561
4553
  } else {
3562
- upb_msgval val = upb_msg_get(msg, f, layout);
4554
+ upb_msgval val = upb_msg_get(msg, field_index, layout);
3563
4555
  switch (upb_fielddef_type(f)) {
3564
4556
  case UPB_TYPE_FLOAT:
3565
4557
  return upb_msgval_getfloat(val) != 0;
@@ -3578,7 +4570,7 @@ static bool upb_visitor_hasfield(const upb_msg *msg, const upb_fielddef *f,
3578
4570
  return upb_msgval_getuint64(val) != 0;
3579
4571
  case UPB_TYPE_STRING:
3580
4572
  case UPB_TYPE_BYTES:
3581
- return upb_msgval_getstr(val) && upb_msgval_getstrlen(val) > 0;
4573
+ return upb_msgval_getstr(val).size > 0;
3582
4574
  case UPB_TYPE_MESSAGE:
3583
4575
  return upb_msgval_getmsg(val) != NULL;
3584
4576
  }
@@ -3589,7 +4581,7 @@ static bool upb_visitor_hasfield(const upb_msg *msg, const upb_fielddef *f,
3589
4581
  static bool upb_visitor_visitmsg2(const upb_msg *msg,
3590
4582
  const upb_msglayout *layout, upb_sink *sink,
3591
4583
  int depth) {
3592
- const upb_msgdef *md = upb_msglayout_msgdef(layout);
4584
+ const upb_msgdef *md = upb_handlers_msgdef(sink->handlers);
3593
4585
  upb_msg_field_iter i;
3594
4586
  upb_status status;
3595
4587
 
@@ -3611,7 +4603,7 @@ static bool upb_visitor_visitmsg2(const upb_msg *msg,
3611
4603
  continue;
3612
4604
  }
3613
4605
 
3614
- val = upb_msg_get(msg, f, layout);
4606
+ val = upb_msg_get(msg, upb_fielddef_index(f), layout);
3615
4607
 
3616
4608
  if (upb_fielddef_isseq(f)) {
3617
4609
  const upb_array *arr = upb_msgval_getarr(val);
@@ -3680,194 +4672,160 @@ bool upb_visitor_visitmsg(upb_visitor *visitor, const upb_msg *msg) {
3680
4672
  /* If we always read/write as a consistent type to each address, this shouldn't
3681
4673
  * violate aliasing.
3682
4674
  */
3683
- #define DEREF(msg, ofs, type) *(type*)CHARPTR_AT(msg, ofs)
4675
+ #define DEREF(msg, ofs, type) *PTR_AT(msg, ofs, type)
3684
4676
 
3685
- static upb_inttable *upb_msg_trygetextdict(const upb_msg *msg,
3686
- const upb_msglayout *l) {
3687
- return l->has_extdict ? DEREF(msg, l->extdict_offset, upb_inttable*) : NULL;
3688
- }
3689
-
3690
- static upb_inttable *upb_msg_getextdict(upb_msg *msg,
3691
- const upb_msglayout *l,
3692
- upb_alloc *a) {
3693
- upb_inttable *ext_dict;
3694
- UPB_ASSERT(l->has_extdict);
4677
+ /* Internal members of a upb_msg. We can change this without breaking binary
4678
+ * compatibility. We put these before the user's data. The user's upb_msg*
4679
+ * points after the upb_msg_internal. */
3695
4680
 
3696
- ext_dict = upb_msg_trygetextdict(msg, l);
4681
+ /* Used when a message is not extendable. */
4682
+ typedef struct {
4683
+ /* TODO(haberman): add unknown fields. */
4684
+ upb_alloc *alloc;
4685
+ } upb_msg_internal;
3697
4686
 
3698
- if (!ext_dict) {
3699
- ext_dict = upb_malloc(a, sizeof(upb_inttable));
4687
+ /* Used when a message is extendable. */
4688
+ typedef struct {
4689
+ upb_inttable *extdict;
4690
+ upb_msg_internal base;
4691
+ } upb_msg_internal_withext;
3700
4692
 
3701
- if (!ext_dict) {
3702
- return NULL;
3703
- }
4693
+ static int upb_msg_internalsize(const upb_msglayout *l) {
4694
+ return sizeof(upb_msg_internal) - l->data.extendable * sizeof(void*);
4695
+ }
3704
4696
 
3705
- /* Use an 8-byte type to ensure all bytes are copied. */
3706
- if (!upb_inttable_init2(ext_dict, UPB_CTYPE_INT64, a)) {
3707
- upb_free(a, ext_dict);
3708
- return NULL;
3709
- }
4697
+ static upb_msg_internal *upb_msg_getinternal(upb_msg *msg) {
4698
+ return VOIDPTR_AT(msg, -sizeof(upb_msg_internal));
4699
+ }
3710
4700
 
3711
- DEREF(msg, l->extdict_offset, upb_inttable*) = ext_dict;
3712
- }
4701
+ static const upb_msg_internal *upb_msg_getinternal_const(const upb_msg *msg) {
4702
+ return VOIDPTR_AT(msg, -sizeof(upb_msg_internal));
4703
+ }
3713
4704
 
3714
- return ext_dict;
4705
+ static upb_msg_internal_withext *upb_msg_getinternalwithext(
4706
+ upb_msg *msg, const upb_msglayout *l) {
4707
+ UPB_ASSERT(l->data.extendable);
4708
+ return VOIDPTR_AT(msg, -sizeof(upb_msg_internal_withext));
3715
4709
  }
3716
4710
 
3717
- static uint32_t upb_msg_getoneofint(const upb_msg *msg,
3718
- const upb_oneofdef *o,
3719
- const upb_msglayout *l) {
3720
- size_t oneof_ofs = l->case_offsets[upb_oneofdef_index(o)];
3721
- return DEREF(msg, oneof_ofs, uint8_t);
4711
+ static const upb_msglayout_fieldinit_v1 *upb_msg_checkfield(
4712
+ int field_index, const upb_msglayout *l) {
4713
+ UPB_ASSERT(field_index >= 0 && field_index < l->data.field_count);
4714
+ return &l->data.fields[field_index];
3722
4715
  }
3723
4716
 
3724
- static void upb_msg_setoneofcase(const upb_msg *msg,
3725
- const upb_oneofdef *o,
3726
- const upb_msglayout *l,
3727
- uint32_t val) {
3728
- size_t oneof_ofs = l->case_offsets[upb_oneofdef_index(o)];
3729
- DEREF(msg, oneof_ofs, uint8_t) = val;
4717
+ static bool upb_msg_inoneof(const upb_msglayout_fieldinit_v1 *field) {
4718
+ return field->oneof_index != UPB_NOT_IN_ONEOF;
3730
4719
  }
3731
4720
 
4721
+ static uint32_t *upb_msg_oneofcase(const upb_msg *msg, int field_index,
4722
+ const upb_msglayout *l) {
4723
+ const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l);
4724
+ UPB_ASSERT(upb_msg_inoneof(field));
4725
+ return PTR_AT(msg, l->data.oneofs[field->oneof_index].case_offset, uint32_t);
4726
+ }
3732
4727
 
3733
- static bool upb_msg_oneofis(const upb_msg *msg, const upb_msglayout *l,
3734
- const upb_oneofdef *o, const upb_fielddef *f) {
3735
- return upb_msg_getoneofint(msg, o, l) == upb_fielddef_number(f);
4728
+ size_t upb_msg_sizeof(const upb_msglayout *l) {
4729
+ return l->data.size + upb_msg_internalsize(l);
3736
4730
  }
3737
4731
 
3738
- size_t upb_msg_sizeof(const upb_msglayout *l) { return l->size; }
4732
+ upb_msg *upb_msg_init(void *mem, const upb_msglayout *l, upb_alloc *a) {
4733
+ upb_msg *msg = VOIDPTR_AT(mem, upb_msg_internalsize(l));
3739
4734
 
3740
- void upb_msg_init(upb_msg *msg, const upb_msglayout *l, upb_alloc *a) {
3741
- if (l->default_msg) {
3742
- memcpy(msg, l->default_msg, l->size);
4735
+ /* Initialize normal members. */
4736
+ if (l->data.default_msg) {
4737
+ memcpy(msg, l->data.default_msg, l->data.size);
3743
4738
  } else {
3744
- memset(msg, 0, l->size);
4739
+ memset(msg, 0, l->data.size);
3745
4740
  }
3746
4741
 
3747
- /* Set arena pointer. */
3748
- memcpy(msg, &a, sizeof(a));
3749
- }
4742
+ /* Initialize internal members. */
4743
+ upb_msg_getinternal(msg)->alloc = a;
3750
4744
 
3751
- void upb_msg_uninit(upb_msg *msg, const upb_msglayout *l) {
3752
- upb_inttable *ext_dict = upb_msg_trygetextdict(msg, l);
3753
- if (ext_dict) {
3754
- upb_inttable_uninit2(ext_dict, upb_msg_alloc(msg, l));
4745
+ if (l->data.extendable) {
4746
+ upb_msg_getinternalwithext(msg, l)->extdict = NULL;
3755
4747
  }
3756
- }
3757
4748
 
3758
- upb_msg *upb_msg_new(const upb_msglayout *l, upb_alloc *a) {
3759
- upb_msg *msg = upb_malloc(a, upb_msg_sizeof(l));
4749
+ return msg;
4750
+ }
3760
4751
 
3761
- if (msg) {
3762
- upb_msg_init(msg, l, a);
4752
+ void *upb_msg_uninit(upb_msg *msg, const upb_msglayout *l) {
4753
+ if (l->data.extendable) {
4754
+ upb_inttable *ext_dict = upb_msg_getinternalwithext(msg, l)->extdict;
4755
+ if (ext_dict) {
4756
+ upb_inttable_uninit2(ext_dict, upb_msg_alloc(msg));
4757
+ upb_free(upb_msg_alloc(msg), ext_dict);
4758
+ }
3763
4759
  }
3764
4760
 
3765
- return msg;
4761
+ return VOIDPTR_AT(msg, -upb_msg_internalsize(l));
4762
+ }
4763
+
4764
+ upb_msg *upb_msg_new(const upb_msglayout *l, upb_alloc *a) {
4765
+ void *mem = upb_malloc(a, upb_msg_sizeof(l));
4766
+ return mem ? upb_msg_init(mem, l, a) : NULL;
3766
4767
  }
3767
4768
 
3768
4769
  void upb_msg_free(upb_msg *msg, const upb_msglayout *l) {
3769
- upb_msg_uninit(msg, l);
3770
- upb_free(upb_msg_alloc(msg, l), msg);
4770
+ upb_free(upb_msg_alloc(msg), upb_msg_uninit(msg, l));
3771
4771
  }
3772
4772
 
3773
- upb_alloc *upb_msg_alloc(const upb_msg *msg, const upb_msglayout *l) {
3774
- upb_alloc *alloc;
3775
- UPB_UNUSED(l);
3776
- memcpy(&alloc, msg, sizeof(alloc));
3777
- return alloc;
4773
+ upb_alloc *upb_msg_alloc(const upb_msg *msg) {
4774
+ return upb_msg_getinternal_const(msg)->alloc;
3778
4775
  }
3779
4776
 
3780
4777
  bool upb_msg_has(const upb_msg *msg,
3781
- const upb_fielddef *f,
4778
+ int field_index,
3782
4779
  const upb_msglayout *l) {
3783
- const upb_oneofdef *o;
3784
- upb_msg_checkfield(l, f);
3785
- UPB_ASSERT(upb_fielddef_haspresence(f));
4780
+ const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l);
3786
4781
 
3787
- if (upb_fielddef_isextension(f)) {
3788
- /* Extensions are set when they are present in the extension dict. */
3789
- upb_inttable *ext_dict = upb_msg_trygetextdict(msg, l);
3790
- upb_value v;
3791
- return ext_dict != NULL &&
3792
- upb_inttable_lookup32(ext_dict, upb_fielddef_number(f), &v);
3793
- } else if ((o = upb_fielddef_containingoneof(f)) != NULL) {
4782
+ UPB_ASSERT(l->data.is_proto2);
4783
+
4784
+ if (upb_msg_inoneof(field)) {
3794
4785
  /* Oneofs are set when the oneof number is set to this field. */
3795
- return upb_msg_getoneofint(msg, o, l) == upb_fielddef_number(f);
4786
+ return *upb_msg_oneofcase(msg, field_index, l) == field->number;
3796
4787
  } else {
3797
4788
  /* Other fields are set when their hasbit is set. */
3798
- uint32_t hasbit = l->hasbits[upb_fielddef_index(f)];
4789
+ uint32_t hasbit = l->data.fields[field_index].hasbit;
3799
4790
  return DEREF(msg, hasbit / 8, char) | (1 << (hasbit % 8));
3800
4791
  }
3801
4792
  }
3802
4793
 
3803
- upb_msgval upb_msg_get(const upb_msg *msg, const upb_fielddef *f,
4794
+ upb_msgval upb_msg_get(const upb_msg *msg, int field_index,
3804
4795
  const upb_msglayout *l) {
3805
- upb_msg_checkfield(l, f);
4796
+ const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l);
4797
+ int size = upb_msg_fieldsize(field);
3806
4798
 
3807
- if (upb_fielddef_isextension(f)) {
3808
- upb_inttable *ext_dict = upb_msg_trygetextdict(msg, l);
3809
- upb_value val;
3810
- if (upb_inttable_lookup32(ext_dict, upb_fielddef_number(f), &val)) {
3811
- return upb_msgval_fromval(val);
4799
+ if (upb_msg_inoneof(field)) {
4800
+ if (*upb_msg_oneofcase(msg, field_index, l) == field->number) {
4801
+ size_t ofs = l->data.oneofs[field->oneof_index].data_offset;
4802
+ return upb_msgval_read(msg, ofs, size);
3812
4803
  } else {
3813
- return upb_msgval_fromdefault(f);
4804
+ /* Return default. */
4805
+ return upb_msgval_read(l->data.default_msg, field->offset, size);
3814
4806
  }
3815
4807
  } else {
3816
- size_t ofs = l->field_offsets[upb_fielddef_index(f)];
3817
- const upb_oneofdef *o = upb_fielddef_containingoneof(f);
3818
- upb_msgval ret;
3819
-
3820
- if (o && !upb_msg_oneofis(msg, l, o, f)) {
3821
- /* Oneof defaults can't come from the message because the memory is reused
3822
- * by all types in the oneof. */
3823
- return upb_msgval_fromdefault(f);
3824
- }
3825
-
3826
- ret = upb_msgval_read(msg, ofs, upb_msg_fieldsize(f));
3827
- return ret;
4808
+ return upb_msgval_read(msg, field->offset, size);
3828
4809
  }
3829
4810
  }
3830
4811
 
3831
- bool upb_msg_set(upb_msg *msg,
3832
- const upb_fielddef *f,
3833
- upb_msgval val,
4812
+ void upb_msg_set(upb_msg *msg, int field_index, upb_msgval val,
3834
4813
  const upb_msglayout *l) {
3835
- upb_alloc *a = upb_msg_alloc(msg, l);
3836
- upb_msg_checkfield(l, f);
3837
-
3838
- if (upb_fielddef_isextension(f)) {
3839
- /* TODO(haberman): introduce table API that can do this in one call. */
3840
- upb_inttable *ext = upb_msg_getextdict(msg, l, a);
3841
- upb_value val2 = upb_toval(val);
3842
- if (!upb_inttable_replace(ext, upb_fielddef_number(f), val2) &&
3843
- !upb_inttable_insert2(ext, upb_fielddef_number(f), val2, a)) {
3844
- return false;
3845
- }
3846
- } else {
3847
- size_t ofs = l->field_offsets[upb_fielddef_index(f)];
3848
- const upb_oneofdef *o = upb_fielddef_containingoneof(f);
4814
+ const upb_msglayout_fieldinit_v1 *field = upb_msg_checkfield(field_index, l);
4815
+ int size = upb_msg_fieldsize(field);
3849
4816
 
3850
- if (o) {
3851
- upb_msg_setoneofcase(msg, o, l, upb_fielddef_number(f));
3852
- }
3853
-
3854
- upb_msgval_write(msg, ofs, val, upb_msg_fieldsize(f));
4817
+ if (upb_msg_inoneof(field)) {
4818
+ size_t ofs = l->data.oneofs[field->oneof_index].data_offset;
4819
+ *upb_msg_oneofcase(msg, field_index, l) = field->number;
4820
+ upb_msgval_write(msg, ofs, val, size);
4821
+ } else {
4822
+ upb_msgval_write(msg, field->offset, val, size);
3855
4823
  }
3856
- return true;
3857
4824
  }
3858
4825
 
3859
4826
 
3860
4827
  /** upb_array *****************************************************************/
3861
4828
 
3862
- struct upb_array {
3863
- upb_fieldtype_t type;
3864
- uint8_t element_size;
3865
- void *data; /* Each element is element_size. */
3866
- size_t len; /* Measured in elements. */
3867
- size_t size; /* Measured in elements. */
3868
- upb_alloc *alloc;
3869
- };
3870
-
3871
4829
  #define DEREF_ARR(arr, i, type) ((type*)arr->data)[i]
3872
4830
 
3873
4831
  size_t upb_array_sizeof(upb_fieldtype_t type) {
@@ -3962,8 +4920,8 @@ static void upb_map_tokey(upb_fieldtype_t type, upb_msgval *key,
3962
4920
  switch (type) {
3963
4921
  case UPB_TYPE_STRING:
3964
4922
  /* Point to string data of the input key. */
3965
- *out_key = key->str.ptr;
3966
- *out_len = key->str.len;
4923
+ *out_key = key->str.data;
4924
+ *out_len = key->str.size;
3967
4925
  return;
3968
4926
  case UPB_TYPE_BOOL:
3969
4927
  case UPB_TYPE_INT32:
@@ -3988,7 +4946,7 @@ static upb_msgval upb_map_fromkey(upb_fieldtype_t type, const char *key,
3988
4946
  size_t len) {
3989
4947
  switch (type) {
3990
4948
  case UPB_TYPE_STRING:
3991
- return upb_msgval_str(key, len);
4949
+ return upb_msgval_makestr(key, len);
3992
4950
  case UPB_TYPE_BOOL:
3993
4951
  case UPB_TYPE_INT32:
3994
4952
  case UPB_TYPE_UINT32:
@@ -6448,138 +7406,138 @@ static upb_inttable reftables[268];
6448
7406
  #endif
6449
7407
 
6450
7408
  static const upb_msgdef msgs[22] = {
6451
- UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 40, 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]),
6452
- UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 4, 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]),
6453
- UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ReservedRange", 4, 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]),
6454
- UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 11, 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]),
6455
- UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 8, 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]),
6456
- UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 8, 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]),
6457
- UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 7, 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]),
6458
- UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 23, 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]),
6459
- UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 12, 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]),
6460
- UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 42, 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]),
6461
- UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 6, 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]),
6462
- UPB_MSGDEF_INIT("google.protobuf.FileOptions", 37, 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]),
6463
- UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 10, 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]),
6464
- UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 15, 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]),
6465
- UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 7, 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]),
6466
- UPB_MSGDEF_INIT("google.protobuf.OneofDescriptorProto", 5, 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]),
6467
- UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 11, 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]),
6468
- UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 7, 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]),
6469
- UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 6, 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]),
6470
- UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 19, 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]),
6471
- UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 18, 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]),
6472
- UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 6, 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]),
7409
+ 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]),
7410
+ 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]),
7411
+ 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]),
7412
+ 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]),
7413
+ 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]),
7414
+ 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]),
7415
+ 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]),
7416
+ 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]),
7417
+ 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]),
7418
+ 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]),
7419
+ 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]),
7420
+ 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]),
7421
+ 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]),
7422
+ 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]),
7423
+ 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]),
7424
+ 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]),
7425
+ 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]),
7426
+ 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]),
7427
+ 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]),
7428
+ 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]),
7429
+ 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]),
7430
+ 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]),
6473
7431
  };
6474
7432
 
6475
7433
  static const upb_fielddef fields[107] = {
6476
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "aggregate_value", 8, &msgs[20], NULL, 15, 6, {0},&reftables[44], &reftables[45]),
6477
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "allow_alias", 2, &msgs[4], NULL, 6, 1, {0},&reftables[46], &reftables[47]),
6478
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "cc_enable_arenas", 31, &msgs[11], NULL, 23, 12, {0},&reftables[48], &reftables[49]),
6479
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "cc_generic_services", 16, &msgs[11], NULL, 17, 6, {0},&reftables[50], &reftables[51]),
6480
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "client_streaming", 5, &msgs[13], NULL, 13, 4, {0},&reftables[52], &reftables[53]),
6481
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "csharp_namespace", 37, &msgs[11], NULL, 27, 14, {0},&reftables[54], &reftables[55]),
6482
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "ctype", 1, &msgs[8], (const upb_def*)(&enums[2]), 6, 1, {0},&reftables[56], &reftables[57]),
6483
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "default_value", 7, &msgs[7], NULL, 16, 7, {0},&reftables[58], &reftables[59]),
6484
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "dependency", 3, &msgs[9], NULL, 30, 8, {0},&reftables[60], &reftables[61]),
6485
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 3, &msgs[8], NULL, 8, 3, {0},&reftables[62], &reftables[63]),
6486
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 33, &msgs[14], NULL, 6, 1, {0},&reftables[64], &reftables[65]),
6487
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 3, &msgs[12], NULL, 8, 3, {0},&reftables[66], &reftables[67]),
6488
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 23, &msgs[11], NULL, 21, 10, {0},&reftables[68], &reftables[69]),
6489
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 1, &msgs[6], NULL, 6, 1, {0},&reftables[70], &reftables[71]),
6490
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 3, &msgs[4], NULL, 7, 2, {0},&reftables[72], &reftables[73]),
6491
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 33, &msgs[17], NULL, 6, 1, {0},&reftables[74], &reftables[75]),
6492
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_DOUBLE, 0, false, false, false, false, "double_value", 6, &msgs[20], NULL, 11, 4, {0},&reftables[76], &reftables[77]),
6493
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "end", 2, &msgs[2], NULL, 3, 1, {0},&reftables[78], &reftables[79]),
6494
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "end", 2, &msgs[1], NULL, 3, 1, {0},&reftables[80], &reftables[81]),
6495
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "enum_type", 5, &msgs[9], (const upb_def*)(&msgs[3]), 13, 1, {0},&reftables[82], &reftables[83]),
6496
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "enum_type", 4, &msgs[0], (const upb_def*)(&msgs[3]), 18, 2, {0},&reftables[84], &reftables[85]),
6497
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "extendee", 2, &msgs[7], NULL, 7, 2, {0},&reftables[86], &reftables[87]),
6498
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension", 6, &msgs[0], (const upb_def*)(&msgs[7]), 24, 4, {0},&reftables[88], &reftables[89]),
6499
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension", 7, &msgs[9], (const upb_def*)(&msgs[7]), 19, 3, {0},&reftables[90], &reftables[91]),
6500
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension_range", 5, &msgs[0], (const upb_def*)(&msgs[1]), 21, 3, {0},&reftables[92], &reftables[93]),
6501
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "field", 2, &msgs[0], (const upb_def*)(&msgs[7]), 12, 0, {0},&reftables[94], &reftables[95]),
6502
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "file", 1, &msgs[10], (const upb_def*)(&msgs[9]), 5, 0, {0},&reftables[96], &reftables[97]),
6503
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "go_package", 11, &msgs[11], NULL, 14, 5, {0},&reftables[98], &reftables[99]),
6504
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "identifier_value", 3, &msgs[20], NULL, 6, 1, {0},&reftables[100], &reftables[101]),
6505
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "input_type", 2, &msgs[13], NULL, 7, 2, {0},&reftables[102], &reftables[103]),
6506
- UPB_FIELDDEF_INIT(UPB_LABEL_REQUIRED, UPB_TYPE_BOOL, 0, false, false, false, false, "is_extension", 2, &msgs[21], NULL, 5, 1, {0},&reftables[104], &reftables[105]),
6507
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_generate_equals_and_hash", 20, &msgs[11], NULL, 20, 9, {0},&reftables[106], &reftables[107]),
6508
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_generic_services", 17, &msgs[11], NULL, 18, 7, {0},&reftables[108], &reftables[109]),
6509
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_multiple_files", 10, &msgs[11], NULL, 13, 4, {0},&reftables[110], &reftables[111]),
6510
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "java_outer_classname", 8, &msgs[11], NULL, 9, 2, {0},&reftables[112], &reftables[113]),
6511
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "java_package", 1, &msgs[11], NULL, 6, 1, {0},&reftables[114], &reftables[115]),
6512
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_string_check_utf8", 27, &msgs[11], NULL, 22, 11, {0},&reftables[116], &reftables[117]),
6513
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "javanano_use_deprecated_package", 38, &msgs[11], NULL, 30, 15, {0},&reftables[118], &reftables[119]),
6514
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "json_name", 10, &msgs[7], NULL, 20, 9, {0},&reftables[120], &reftables[121]),
6515
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "jstype", 6, &msgs[8], (const upb_def*)(&enums[3]), 10, 5, {0},&reftables[122], &reftables[123]),
6516
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "label", 4, &msgs[7], (const upb_def*)(&enums[0]), 11, 4, {0},&reftables[124], &reftables[125]),
6517
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "lazy", 5, &msgs[8], NULL, 9, 4, {0},&reftables[126], &reftables[127]),
6518
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "leading_comments", 3, &msgs[19], NULL, 8, 2, {0},&reftables[128], &reftables[129]),
6519
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "leading_detached_comments", 6, &msgs[19], NULL, 16, 4, {0},&reftables[130], &reftables[131]),
6520
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "location", 1, &msgs[18], (const upb_def*)(&msgs[19]), 5, 0, {0},&reftables[132], &reftables[133]),
6521
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "map_entry", 7, &msgs[12], NULL, 9, 4, {0},&reftables[134], &reftables[135]),
6522
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "message_set_wire_format", 1, &msgs[12], NULL, 6, 1, {0},&reftables[136], &reftables[137]),
6523
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "message_type", 4, &msgs[9], (const upb_def*)(&msgs[0]), 10, 0, {0},&reftables[138], &reftables[139]),
6524
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "method", 2, &msgs[16], (const upb_def*)(&msgs[13]), 6, 0, {0},&reftables[140], &reftables[141]),
6525
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "name", 2, &msgs[20], (const upb_def*)(&msgs[21]), 5, 0, {0},&reftables[142], &reftables[143]),
6526
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[5], NULL, 4, 1, {0},&reftables[144], &reftables[145]),
6527
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[9], NULL, 22, 6, {0},&reftables[146], &reftables[147]),
6528
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[3], NULL, 8, 2, {0},&reftables[148], &reftables[149]),
6529
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[16], NULL, 8, 2, {0},&reftables[150], &reftables[151]),
6530
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[15], NULL, 2, 0, {0},&reftables[152], &reftables[153]),
6531
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[13], NULL, 4, 1, {0},&reftables[154], &reftables[155]),
6532
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[7], NULL, 4, 1, {0},&reftables[156], &reftables[157]),
6533
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[0], NULL, 32, 8, {0},&reftables[158], &reftables[159]),
6534
- UPB_FIELDDEF_INIT(UPB_LABEL_REQUIRED, UPB_TYPE_STRING, 0, false, false, false, false, "name_part", 1, &msgs[21], NULL, 2, 0, {0},&reftables[160], &reftables[161]),
6535
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT64, UPB_INTFMT_VARIABLE, false, false, false, false, "negative_int_value", 5, &msgs[20], NULL, 10, 3, {0},&reftables[162], &reftables[163]),
6536
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "nested_type", 3, &msgs[0], (const upb_def*)(&msgs[0]), 15, 1, {0},&reftables[164], &reftables[165]),
6537
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "no_standard_descriptor_accessor", 2, &msgs[12], NULL, 7, 2, {0},&reftables[166], &reftables[167]),
6538
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "number", 3, &msgs[7], NULL, 10, 3, {0},&reftables[168], &reftables[169]),
6539
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "number", 2, &msgs[5], NULL, 7, 2, {0},&reftables[170], &reftables[171]),
6540
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "objc_class_prefix", 36, &msgs[11], NULL, 24, 13, {0},&reftables[172], &reftables[173]),
6541
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "oneof_decl", 8, &msgs[0], (const upb_def*)(&msgs[15]), 28, 6, {0},&reftables[174], &reftables[175]),
6542
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "oneof_index", 9, &msgs[7], NULL, 19, 8, {0},&reftables[176], &reftables[177]),
6543
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "optimize_for", 9, &msgs[11], (const upb_def*)(&enums[4]), 12, 3, {0},&reftables[178], &reftables[179]),
6544
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 7, &msgs[0], (const upb_def*)(&msgs[12]), 25, 5, {0},&reftables[180], &reftables[181]),
6545
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 8, &msgs[9], (const upb_def*)(&msgs[11]), 20, 4, {0},&reftables[182], &reftables[183]),
6546
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 8, &msgs[7], (const upb_def*)(&msgs[8]), 3, 0, {0},&reftables[184], &reftables[185]),
6547
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 4, &msgs[13], (const upb_def*)(&msgs[14]), 3, 0, {0},&reftables[186], &reftables[187]),
6548
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[16], (const upb_def*)(&msgs[17]), 7, 1, {0},&reftables[188], &reftables[189]),
6549
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[3], (const upb_def*)(&msgs[4]), 7, 1, {0},&reftables[190], &reftables[191]),
6550
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[5], (const upb_def*)(&msgs[6]), 3, 0, {0},&reftables[192], &reftables[193]),
6551
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "output_type", 3, &msgs[13], NULL, 10, 3, {0},&reftables[194], &reftables[195]),
6552
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "package", 2, &msgs[9], NULL, 25, 7, {0},&reftables[196], &reftables[197]),
6553
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "packed", 2, &msgs[8], NULL, 7, 2, {0},&reftables[198], &reftables[199]),
6554
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, true, "path", 1, &msgs[19], NULL, 4, 0, {0},&reftables[200], &reftables[201]),
6555
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "php_class_prefix", 40, &msgs[11], NULL, 31, 16, {0},&reftables[202], &reftables[203]),
6556
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "php_namespace", 41, &msgs[11], NULL, 34, 17, {0},&reftables[204], &reftables[205]),
6557
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_UINT64, UPB_INTFMT_VARIABLE, false, false, false, false, "positive_int_value", 4, &msgs[20], NULL, 9, 2, {0},&reftables[206], &reftables[207]),
6558
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "public_dependency", 10, &msgs[9], NULL, 35, 9, {0},&reftables[208], &reftables[209]),
6559
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "py_generic_services", 18, &msgs[11], NULL, 19, 8, {0},&reftables[210], &reftables[211]),
6560
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "reserved_name", 10, &msgs[0], NULL, 37, 9, {0},&reftables[212], &reftables[213]),
6561
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "reserved_range", 9, &msgs[0], (const upb_def*)(&msgs[2]), 31, 7, {0},&reftables[214], &reftables[215]),
6562
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "server_streaming", 6, &msgs[13], NULL, 14, 5, {0},&reftables[216], &reftables[217]),
6563
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "service", 6, &msgs[9], (const upb_def*)(&msgs[16]), 16, 2, {0},&reftables[218], &reftables[219]),
6564
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "source_code_info", 9, &msgs[9], (const upb_def*)(&msgs[18]), 21, 5, {0},&reftables[220], &reftables[221]),
6565
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, true, "span", 2, &msgs[19], NULL, 7, 1, {0},&reftables[222], &reftables[223]),
6566
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "start", 1, &msgs[2], NULL, 2, 0, {0},&reftables[224], &reftables[225]),
6567
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "start", 1, &msgs[1], NULL, 2, 0, {0},&reftables[226], &reftables[227]),
6568
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BYTES, 0, false, false, false, false, "string_value", 7, &msgs[20], NULL, 12, 5, {0},&reftables[228], &reftables[229]),
6569
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "syntax", 12, &msgs[9], NULL, 39, 11, {0},&reftables[230], &reftables[231]),
6570
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "trailing_comments", 4, &msgs[19], NULL, 11, 3, {0},&reftables[232], &reftables[233]),
6571
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "type", 5, &msgs[7], (const upb_def*)(&enums[1]), 12, 5, {0},&reftables[234], &reftables[235]),
6572
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "type_name", 6, &msgs[7], NULL, 13, 6, {0},&reftables[236], &reftables[237]),
6573
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[12], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[238], &reftables[239]),
6574
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[17], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[240], &reftables[241]),
6575
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[11], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[242], &reftables[243]),
6576
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[14], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[244], &reftables[245]),
6577
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[8], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[246], &reftables[247]),
6578
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[6], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[248], &reftables[249]),
6579
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[4], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[250], &reftables[251]),
6580
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "value", 2, &msgs[3], (const upb_def*)(&msgs[5]), 6, 0, {0},&reftables[252], &reftables[253]),
6581
- UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "weak", 10, &msgs[8], NULL, 11, 6, {0},&reftables[254], &reftables[255]),
6582
- UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "weak_dependency", 11, &msgs[9], NULL, 38, 10, {0},&reftables[256], &reftables[257]),
7434
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "aggregate_value", 8, &msgs[20], NULL, 16, 6, {0},&reftables[44], &reftables[45]),
7435
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "allow_alias", 2, &msgs[4], NULL, 7, 1, {0},&reftables[46], &reftables[47]),
7436
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "cc_enable_arenas", 31, &msgs[11], NULL, 24, 12, {0},&reftables[48], &reftables[49]),
7437
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "cc_generic_services", 16, &msgs[11], NULL, 18, 6, {0},&reftables[50], &reftables[51]),
7438
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "client_streaming", 5, &msgs[13], NULL, 14, 4, {0},&reftables[52], &reftables[53]),
7439
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "csharp_namespace", 37, &msgs[11], NULL, 28, 14, {0},&reftables[54], &reftables[55]),
7440
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "ctype", 1, &msgs[8], (const upb_def*)(&enums[2]), 7, 1, {0},&reftables[56], &reftables[57]),
7441
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "default_value", 7, &msgs[7], NULL, 17, 7, {0},&reftables[58], &reftables[59]),
7442
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "dependency", 3, &msgs[9], NULL, 31, 8, {0},&reftables[60], &reftables[61]),
7443
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 3, &msgs[8], NULL, 9, 3, {0},&reftables[62], &reftables[63]),
7444
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 33, &msgs[14], NULL, 7, 1, {0},&reftables[64], &reftables[65]),
7445
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 3, &msgs[12], NULL, 9, 3, {0},&reftables[66], &reftables[67]),
7446
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 23, &msgs[11], NULL, 22, 10, {0},&reftables[68], &reftables[69]),
7447
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 1, &msgs[6], NULL, 7, 1, {0},&reftables[70], &reftables[71]),
7448
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 3, &msgs[4], NULL, 8, 2, {0},&reftables[72], &reftables[73]),
7449
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 33, &msgs[17], NULL, 7, 1, {0},&reftables[74], &reftables[75]),
7450
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_DOUBLE, 0, false, false, false, false, "double_value", 6, &msgs[20], NULL, 12, 4, {0},&reftables[76], &reftables[77]),
7451
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "end", 2, &msgs[2], NULL, 4, 1, {0},&reftables[78], &reftables[79]),
7452
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "end", 2, &msgs[1], NULL, 4, 1, {0},&reftables[80], &reftables[81]),
7453
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "enum_type", 5, &msgs[9], (const upb_def*)(&msgs[3]), 14, 1, {0},&reftables[82], &reftables[83]),
7454
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "enum_type", 4, &msgs[0], (const upb_def*)(&msgs[3]), 19, 2, {0},&reftables[84], &reftables[85]),
7455
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "extendee", 2, &msgs[7], NULL, 8, 2, {0},&reftables[86], &reftables[87]),
7456
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension", 6, &msgs[0], (const upb_def*)(&msgs[7]), 25, 4, {0},&reftables[88], &reftables[89]),
7457
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension", 7, &msgs[9], (const upb_def*)(&msgs[7]), 20, 3, {0},&reftables[90], &reftables[91]),
7458
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension_range", 5, &msgs[0], (const upb_def*)(&msgs[1]), 22, 3, {0},&reftables[92], &reftables[93]),
7459
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "field", 2, &msgs[0], (const upb_def*)(&msgs[7]), 13, 0, {0},&reftables[94], &reftables[95]),
7460
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "file", 1, &msgs[10], (const upb_def*)(&msgs[9]), 6, 0, {0},&reftables[96], &reftables[97]),
7461
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "go_package", 11, &msgs[11], NULL, 15, 5, {0},&reftables[98], &reftables[99]),
7462
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "identifier_value", 3, &msgs[20], NULL, 7, 1, {0},&reftables[100], &reftables[101]),
7463
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "input_type", 2, &msgs[13], NULL, 8, 2, {0},&reftables[102], &reftables[103]),
7464
+ UPB_FIELDDEF_INIT(UPB_LABEL_REQUIRED, UPB_TYPE_BOOL, 0, false, false, false, false, "is_extension", 2, &msgs[21], NULL, 6, 1, {0},&reftables[104], &reftables[105]),
7465
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_generate_equals_and_hash", 20, &msgs[11], NULL, 21, 9, {0},&reftables[106], &reftables[107]),
7466
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_generic_services", 17, &msgs[11], NULL, 19, 7, {0},&reftables[108], &reftables[109]),
7467
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_multiple_files", 10, &msgs[11], NULL, 14, 4, {0},&reftables[110], &reftables[111]),
7468
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "java_outer_classname", 8, &msgs[11], NULL, 10, 2, {0},&reftables[112], &reftables[113]),
7469
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "java_package", 1, &msgs[11], NULL, 7, 1, {0},&reftables[114], &reftables[115]),
7470
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_string_check_utf8", 27, &msgs[11], NULL, 23, 11, {0},&reftables[116], &reftables[117]),
7471
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "javanano_use_deprecated_package", 38, &msgs[11], NULL, 31, 15, {0},&reftables[118], &reftables[119]),
7472
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "json_name", 10, &msgs[7], NULL, 21, 9, {0},&reftables[120], &reftables[121]),
7473
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "jstype", 6, &msgs[8], (const upb_def*)(&enums[3]), 11, 5, {0},&reftables[122], &reftables[123]),
7474
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "label", 4, &msgs[7], (const upb_def*)(&enums[0]), 12, 4, {0},&reftables[124], &reftables[125]),
7475
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "lazy", 5, &msgs[8], NULL, 10, 4, {0},&reftables[126], &reftables[127]),
7476
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "leading_comments", 3, &msgs[19], NULL, 9, 2, {0},&reftables[128], &reftables[129]),
7477
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "leading_detached_comments", 6, &msgs[19], NULL, 17, 4, {0},&reftables[130], &reftables[131]),
7478
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "location", 1, &msgs[18], (const upb_def*)(&msgs[19]), 6, 0, {0},&reftables[132], &reftables[133]),
7479
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "map_entry", 7, &msgs[12], NULL, 10, 4, {0},&reftables[134], &reftables[135]),
7480
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "message_set_wire_format", 1, &msgs[12], NULL, 7, 1, {0},&reftables[136], &reftables[137]),
7481
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "message_type", 4, &msgs[9], (const upb_def*)(&msgs[0]), 11, 0, {0},&reftables[138], &reftables[139]),
7482
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "method", 2, &msgs[16], (const upb_def*)(&msgs[13]), 7, 0, {0},&reftables[140], &reftables[141]),
7483
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "name", 2, &msgs[20], (const upb_def*)(&msgs[21]), 6, 0, {0},&reftables[142], &reftables[143]),
7484
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[5], NULL, 5, 1, {0},&reftables[144], &reftables[145]),
7485
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[9], NULL, 23, 6, {0},&reftables[146], &reftables[147]),
7486
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[3], NULL, 9, 2, {0},&reftables[148], &reftables[149]),
7487
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[16], NULL, 9, 2, {0},&reftables[150], &reftables[151]),
7488
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[15], NULL, 3, 0, {0},&reftables[152], &reftables[153]),
7489
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[13], NULL, 5, 1, {0},&reftables[154], &reftables[155]),
7490
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[7], NULL, 5, 1, {0},&reftables[156], &reftables[157]),
7491
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[0], NULL, 33, 8, {0},&reftables[158], &reftables[159]),
7492
+ UPB_FIELDDEF_INIT(UPB_LABEL_REQUIRED, UPB_TYPE_STRING, 0, false, false, false, false, "name_part", 1, &msgs[21], NULL, 3, 0, {0},&reftables[160], &reftables[161]),
7493
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT64, UPB_INTFMT_VARIABLE, false, false, false, false, "negative_int_value", 5, &msgs[20], NULL, 11, 3, {0},&reftables[162], &reftables[163]),
7494
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "nested_type", 3, &msgs[0], (const upb_def*)(&msgs[0]), 16, 1, {0},&reftables[164], &reftables[165]),
7495
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "no_standard_descriptor_accessor", 2, &msgs[12], NULL, 8, 2, {0},&reftables[166], &reftables[167]),
7496
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "number", 3, &msgs[7], NULL, 11, 3, {0},&reftables[168], &reftables[169]),
7497
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "number", 2, &msgs[5], NULL, 8, 2, {0},&reftables[170], &reftables[171]),
7498
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "objc_class_prefix", 36, &msgs[11], NULL, 25, 13, {0},&reftables[172], &reftables[173]),
7499
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "oneof_decl", 8, &msgs[0], (const upb_def*)(&msgs[15]), 29, 6, {0},&reftables[174], &reftables[175]),
7500
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "oneof_index", 9, &msgs[7], NULL, 20, 8, {0},&reftables[176], &reftables[177]),
7501
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "optimize_for", 9, &msgs[11], (const upb_def*)(&enums[4]), 13, 3, {0},&reftables[178], &reftables[179]),
7502
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 7, &msgs[0], (const upb_def*)(&msgs[12]), 26, 5, {0},&reftables[180], &reftables[181]),
7503
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 8, &msgs[9], (const upb_def*)(&msgs[11]), 21, 4, {0},&reftables[182], &reftables[183]),
7504
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 8, &msgs[7], (const upb_def*)(&msgs[8]), 4, 0, {0},&reftables[184], &reftables[185]),
7505
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 4, &msgs[13], (const upb_def*)(&msgs[14]), 4, 0, {0},&reftables[186], &reftables[187]),
7506
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[16], (const upb_def*)(&msgs[17]), 8, 1, {0},&reftables[188], &reftables[189]),
7507
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[3], (const upb_def*)(&msgs[4]), 8, 1, {0},&reftables[190], &reftables[191]),
7508
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[5], (const upb_def*)(&msgs[6]), 4, 0, {0},&reftables[192], &reftables[193]),
7509
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "output_type", 3, &msgs[13], NULL, 11, 3, {0},&reftables[194], &reftables[195]),
7510
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "package", 2, &msgs[9], NULL, 26, 7, {0},&reftables[196], &reftables[197]),
7511
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "packed", 2, &msgs[8], NULL, 8, 2, {0},&reftables[198], &reftables[199]),
7512
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, true, "path", 1, &msgs[19], NULL, 5, 0, {0},&reftables[200], &reftables[201]),
7513
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "php_class_prefix", 40, &msgs[11], NULL, 32, 16, {0},&reftables[202], &reftables[203]),
7514
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "php_namespace", 41, &msgs[11], NULL, 35, 17, {0},&reftables[204], &reftables[205]),
7515
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_UINT64, UPB_INTFMT_VARIABLE, false, false, false, false, "positive_int_value", 4, &msgs[20], NULL, 10, 2, {0},&reftables[206], &reftables[207]),
7516
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "public_dependency", 10, &msgs[9], NULL, 36, 9, {0},&reftables[208], &reftables[209]),
7517
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "py_generic_services", 18, &msgs[11], NULL, 20, 8, {0},&reftables[210], &reftables[211]),
7518
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "reserved_name", 10, &msgs[0], NULL, 38, 9, {0},&reftables[212], &reftables[213]),
7519
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "reserved_range", 9, &msgs[0], (const upb_def*)(&msgs[2]), 32, 7, {0},&reftables[214], &reftables[215]),
7520
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "server_streaming", 6, &msgs[13], NULL, 15, 5, {0},&reftables[216], &reftables[217]),
7521
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "service", 6, &msgs[9], (const upb_def*)(&msgs[16]), 17, 2, {0},&reftables[218], &reftables[219]),
7522
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "source_code_info", 9, &msgs[9], (const upb_def*)(&msgs[18]), 22, 5, {0},&reftables[220], &reftables[221]),
7523
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, true, "span", 2, &msgs[19], NULL, 8, 1, {0},&reftables[222], &reftables[223]),
7524
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "start", 1, &msgs[2], NULL, 3, 0, {0},&reftables[224], &reftables[225]),
7525
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "start", 1, &msgs[1], NULL, 3, 0, {0},&reftables[226], &reftables[227]),
7526
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BYTES, 0, false, false, false, false, "string_value", 7, &msgs[20], NULL, 13, 5, {0},&reftables[228], &reftables[229]),
7527
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "syntax", 12, &msgs[9], NULL, 40, 11, {0},&reftables[230], &reftables[231]),
7528
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "trailing_comments", 4, &msgs[19], NULL, 12, 3, {0},&reftables[232], &reftables[233]),
7529
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "type", 5, &msgs[7], (const upb_def*)(&enums[1]), 13, 5, {0},&reftables[234], &reftables[235]),
7530
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "type_name", 6, &msgs[7], NULL, 14, 6, {0},&reftables[236], &reftables[237]),
7531
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[12], (const upb_def*)(&msgs[20]), 6, 0, {0},&reftables[238], &reftables[239]),
7532
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[17], (const upb_def*)(&msgs[20]), 6, 0, {0},&reftables[240], &reftables[241]),
7533
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[11], (const upb_def*)(&msgs[20]), 6, 0, {0},&reftables[242], &reftables[243]),
7534
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[14], (const upb_def*)(&msgs[20]), 6, 0, {0},&reftables[244], &reftables[245]),
7535
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[8], (const upb_def*)(&msgs[20]), 6, 0, {0},&reftables[246], &reftables[247]),
7536
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[6], (const upb_def*)(&msgs[20]), 6, 0, {0},&reftables[248], &reftables[249]),
7537
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[4], (const upb_def*)(&msgs[20]), 6, 0, {0},&reftables[250], &reftables[251]),
7538
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "value", 2, &msgs[3], (const upb_def*)(&msgs[5]), 7, 0, {0},&reftables[252], &reftables[253]),
7539
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "weak", 10, &msgs[8], NULL, 12, 6, {0},&reftables[254], &reftables[255]),
7540
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "weak_dependency", 11, &msgs[9], NULL, 39, 10, {0},&reftables[256], &reftables[257]),
6583
7541
  };
6584
7542
 
6585
7543
  static const upb_enumdef enums[5] = {
@@ -7398,6 +8356,7 @@ typedef struct {
7398
8356
  struct upb_descreader {
7399
8357
  upb_sink sink;
7400
8358
  upb_inttable files;
8359
+ upb_strtable files_by_name;
7401
8360
  upb_filedef *file; /* The last file in files. */
7402
8361
  upb_descreader_frame stack[UPB_MAX_MESSAGE_NESTING];
7403
8362
  int stack_len;
@@ -7564,6 +8523,7 @@ static size_t file_onname(void *closure, const void *hd, const char *buf,
7564
8523
  UPB_UNUSED(handle);
7565
8524
 
7566
8525
  name = upb_gstrndup(buf, n);
8526
+ upb_strtable_insert(&r->files_by_name, name, upb_value_ptr(r->file));
7567
8527
  /* XXX: see comment at the top of the file. */
7568
8528
  ok = upb_filedef_setname(r->file, name, NULL);
7569
8529
  upb_gfree(name);
@@ -7587,6 +8547,18 @@ static size_t file_onpackage(void *closure, const void *hd, const char *buf,
7587
8547
  return n;
7588
8548
  }
7589
8549
 
8550
+ static void *file_startphpnamespace(void *closure, const void *hd,
8551
+ size_t size_hint) {
8552
+ upb_descreader *r = closure;
8553
+ bool ok;
8554
+ UPB_UNUSED(hd);
8555
+ UPB_UNUSED(size_hint);
8556
+
8557
+ ok = upb_filedef_setphpnamespace(r->file, "", NULL);
8558
+ UPB_ASSERT(ok);
8559
+ return closure;
8560
+ }
8561
+
7590
8562
  static size_t file_onphpnamespace(void *closure, const void *hd,
7591
8563
  const char *buf, size_t n,
7592
8564
  const upb_bufhandle *handle) {
@@ -7665,6 +8637,18 @@ static void *file_startext(void *closure, const void *hd) {
7665
8637
  return r;
7666
8638
  }
7667
8639
 
8640
+ static size_t file_ondep(void *closure, const void *hd, const char *buf,
8641
+ size_t n, const upb_bufhandle *handle) {
8642
+ upb_descreader *r = closure;
8643
+ upb_value val;
8644
+ if (upb_strtable_lookup2(&r->files_by_name, buf, n, &val)) {
8645
+ upb_filedef_adddep(r->file, upb_value_getptr(val));
8646
+ }
8647
+ UPB_UNUSED(hd);
8648
+ UPB_UNUSED(handle);
8649
+ return n;
8650
+ }
8651
+
7668
8652
  /** Handlers for google.protobuf.EnumValueDescriptorProto. *********************/
7669
8653
 
7670
8654
  static bool enumval_startmsg(void *closure, const void *hd) {
@@ -8109,6 +9093,8 @@ static void reghandlers(const void *closure, upb_handlers *h) {
8109
9093
  &file_startenum, NULL);
8110
9094
  upb_handlers_setstartsubmsg(h, F(FileDescriptorProto, extension),
8111
9095
  &file_startext, NULL);
9096
+ upb_handlers_setstring(h, F(FileDescriptorProto, dependency),
9097
+ &file_ondep, NULL);
8112
9098
  } else if (upbdefs_google_protobuf_EnumValueDescriptorProto_is(m)) {
8113
9099
  upb_handlers_setstartmsg(h, &enumval_startmsg, NULL);
8114
9100
  upb_handlers_setendmsg(h, &enumval_endmsg, NULL);
@@ -8147,6 +9133,8 @@ static void reghandlers(const void *closure, upb_handlers *h) {
8147
9133
  } else if (upbdefs_google_protobuf_FileOptions_is(m)) {
8148
9134
  upb_handlers_setstring(h, F(FileOptions, php_class_prefix),
8149
9135
  &file_onphpprefix, NULL);
9136
+ upb_handlers_setstartstr(h, F(FileOptions, php_namespace),
9137
+ &file_startphpnamespace, NULL);
8150
9138
  upb_handlers_setstring(h, F(FileOptions, php_namespace),
8151
9139
  &file_onphpnamespace, NULL);
8152
9140
  }
@@ -8166,6 +9154,7 @@ void descreader_cleanup(void *_r) {
8166
9154
 
8167
9155
  upb_gfree(r->name);
8168
9156
  upb_inttable_uninit(&r->files);
9157
+ upb_strtable_uninit(&r->files_by_name);
8169
9158
  upb_inttable_uninit(&r->oneofs);
8170
9159
  upb_gfree(r->default_string);
8171
9160
  while (r->stack_len > 0) {
@@ -8184,6 +9173,7 @@ upb_descreader *upb_descreader_create(upb_env *e, const upb_handlers *h) {
8184
9173
  }
8185
9174
 
8186
9175
  upb_inttable_init(&r->files, UPB_CTYPE_PTR);
9176
+ upb_strtable_init(&r->files_by_name, UPB_CTYPE_PTR);
8187
9177
  upb_inttable_init(&r->oneofs, UPB_CTYPE_PTR);
8188
9178
  upb_sink_reset(upb_descreader_input(r), h, r);
8189
9179
  r->stack_len = 0;
@@ -8483,7 +9473,7 @@ static void put32(compiler *c, uint32_t v) {
8483
9473
  *c->pc++ = v;
8484
9474
  }
8485
9475
 
8486
- static void putop(compiler *c, opcode op, ...) {
9476
+ static void putop(compiler *c, int op, ...) {
8487
9477
  va_list ap;
8488
9478
  va_start(ap, op);
8489
9479
 
@@ -9766,7 +10756,6 @@ have_tag:
9766
10756
  return upb_pbdecoder_suspend(d);
9767
10757
  }
9768
10758
 
9769
- /* TODO: deliver to unknown field callback. */
9770
10759
  switch (wire_type) {
9771
10760
  case UPB_WIRE_TYPE_32BIT:
9772
10761
  CHECK_RETURN(skip(d, 4));
@@ -9804,6 +10793,8 @@ have_tag:
9804
10793
  }
9805
10794
 
9806
10795
  if (d->top->groupnum >= 0) {
10796
+ /* TODO: More code needed for handling unknown groups. */
10797
+ upb_sink_putunknown(&d->top->sink, d->checkpoint, d->ptr - d->checkpoint);
9807
10798
  return DECODE_OK;
9808
10799
  }
9809
10800
 
@@ -10659,6 +11650,12 @@ static void *encode_startdelimfield(void *c, const void *hd) {
10659
11650
  return ok ? c : UPB_BREAK;
10660
11651
  }
10661
11652
 
11653
+ static bool encode_unknown(void *c, const void *hd, const char *buf,
11654
+ size_t len) {
11655
+ UPB_UNUSED(hd);
11656
+ return encode_bytes(c, buf, len) && commit(c);
11657
+ }
11658
+
10662
11659
  static bool encode_enddelimfield(void *c, const void *hd) {
10663
11660
  UPB_UNUSED(hd);
10664
11661
  return end_delim(c);
@@ -10721,6 +11718,7 @@ static void newhandlers_callback(const void *closure, upb_handlers *h) {
10721
11718
 
10722
11719
  upb_handlers_setstartmsg(h, startmsg, NULL);
10723
11720
  upb_handlers_setendmsg(h, endmsg, NULL);
11721
+ upb_handlers_setunknown(h, encode_unknown, NULL);
10724
11722
 
10725
11723
  m = upb_handlers_msgdef(h);
10726
11724
  for(upb_msg_field_begin(&i, m);
@@ -11930,15 +12928,21 @@ static bool end_number(upb_json_parser *p, const char *ptr) {
11930
12928
  return parse_number(p, false);
11931
12929
  }
11932
12930
 
12931
+ /* |buf| is NULL-terminated. |buf| itself will never include quotes;
12932
+ * |is_quoted| tells us whether this text originally appeared inside quotes. */
11933
12933
  static bool parse_number_from_buffer(upb_json_parser *p, const char *buf,
11934
- const char *bufend, bool is_quoted) {
11935
- size_t len = bufend - buf;
12934
+ bool is_quoted) {
12935
+ size_t len = strlen(buf);
12936
+ const char *bufend = buf + len;
11936
12937
  char *end;
11937
12938
  upb_fieldtype_t type = upb_fielddef_type(p->top->f);
11938
12939
  double val;
11939
12940
  double dummy;
12941
+ double inf = 1.0 / 0.0; /* C89 does not have an INFINITY macro. */
12942
+
12943
+ errno = 0;
11940
12944
 
11941
- if (buf[0] == ' ') {
12945
+ if (len == 0 || buf[0] == ' ') {
11942
12946
  return false;
11943
12947
  }
11944
12948
 
@@ -11997,15 +13001,15 @@ static bool parse_number_from_buffer(upb_json_parser *p, const char *buf,
11997
13001
  }
11998
13002
 
11999
13003
  if (type != UPB_TYPE_DOUBLE && type != UPB_TYPE_FLOAT && is_quoted) {
12000
- /* Quoted numbers shouldn't support double forms for integer types. */
13004
+ /* Quoted numbers for integer types are not allowed to be in double form. */
12001
13005
  return false;
12002
13006
  }
12003
13007
 
12004
13008
  if (len == strlen("Infinity") && strcmp(buf, "Infinity") == 0) {
12005
13009
  /* C89 does not have an INFINITY macro. */
12006
- val = 1.0 / 0.0;
13010
+ val = inf;
12007
13011
  } else if (len == strlen("-Infinity") && strcmp(buf, "-Infinity") == 0) {
12008
- val = -1.0 / 0.0;
13012
+ val = -inf;
12009
13013
  } else {
12010
13014
  val = strtod(buf, &end);
12011
13015
  if (errno == ERANGE || end != bufend) {
@@ -12014,28 +13018,29 @@ static bool parse_number_from_buffer(upb_json_parser *p, const char *buf,
12014
13018
  }
12015
13019
 
12016
13020
  switch (type) {
12017
- #define CASE(capitaltype, smalltype, min, max) \
13021
+ #define CASE(capitaltype, smalltype, ctype, min, max) \
12018
13022
  case UPB_TYPE_ ## capitaltype: { \
12019
13023
  if (modf(val, &dummy) != 0 || val > max || val < min) { \
12020
13024
  return false; \
12021
13025
  } else { \
12022
- upb_sink_put ## smalltype(&p->top->sink, parser_getsel(p), val); \
13026
+ upb_sink_put ## smalltype(&p->top->sink, parser_getsel(p), \
13027
+ (ctype)val); \
12023
13028
  return true; \
12024
13029
  } \
12025
13030
  break; \
12026
13031
  }
12027
13032
  case UPB_TYPE_ENUM:
12028
- CASE(INT32, int32, INT32_MIN, INT32_MAX);
12029
- CASE(INT64, int64, INT64_MIN, INT64_MAX);
12030
- CASE(UINT32, uint32, 0, UINT32_MAX);
12031
- CASE(UINT64, uint64, 0, UINT64_MAX);
13033
+ CASE(INT32, int32, int32_t, INT32_MIN, INT32_MAX);
13034
+ CASE(INT64, int64, int64_t, INT64_MIN, INT64_MAX);
13035
+ CASE(UINT32, uint32, uint32_t, 0, UINT32_MAX);
13036
+ CASE(UINT64, uint64, uint64_t, 0, UINT64_MAX);
12032
13037
  #undef CASE
12033
13038
 
12034
13039
  case UPB_TYPE_DOUBLE:
12035
13040
  upb_sink_putdouble(&p->top->sink, parser_getsel(p), val);
12036
13041
  return true;
12037
13042
  case UPB_TYPE_FLOAT:
12038
- if (false /*val > FLT_MAX || val < -FLT_MAX*/) {
13043
+ if ((val > FLT_MAX || val < -FLT_MAX) && val != inf && val != -inf) {
12039
13044
  return false;
12040
13045
  } else {
12041
13046
  upb_sink_putfloat(&p->top->sink, parser_getsel(p), val);
@@ -12049,7 +13054,6 @@ static bool parse_number_from_buffer(upb_json_parser *p, const char *buf,
12049
13054
  static bool parse_number(upb_json_parser *p, bool is_quoted) {
12050
13055
  size_t len;
12051
13056
  const char *buf;
12052
- const char *bufend;
12053
13057
 
12054
13058
  /* strtol() and friends unfortunately do not support specifying the length of
12055
13059
  * the input string, so we need to force a copy into a NULL-terminated buffer. */
@@ -12058,10 +13062,8 @@ static bool parse_number(upb_json_parser *p, bool is_quoted) {
12058
13062
  }
12059
13063
 
12060
13064
  buf = accumulate_getptr(p, &len);
12061
- bufend = buf + len - 1; /* One for NULL. */
12062
- errno = 0;
12063
13065
 
12064
- if (parse_number_from_buffer(p, buf, bufend, is_quoted)) {
13066
+ if (parse_number_from_buffer(p, buf, is_quoted)) {
12065
13067
  multipart_end(p);
12066
13068
  return true;
12067
13069
  } else {
@@ -12521,11 +13523,11 @@ static void end_object(upb_json_parser *p) {
12521
13523
  * final state once, when the closing '"' is seen. */
12522
13524
 
12523
13525
 
12524
- #line 1306 "upb/json/parser.rl"
13526
+ #line 1310 "upb/json/parser.rl"
12525
13527
 
12526
13528
 
12527
13529
 
12528
- #line 1218 "upb/json/parser.c"
13530
+ #line 1222 "upb/json/parser.c"
12529
13531
  static const char _json_actions[] = {
12530
13532
  0, 1, 0, 1, 2, 1, 3, 1,
12531
13533
  5, 1, 6, 1, 7, 1, 8, 1,
@@ -12674,7 +13676,7 @@ static const int json_en_value_machine = 27;
12674
13676
  static const int json_en_main = 1;
12675
13677
 
12676
13678
 
12677
- #line 1309 "upb/json/parser.rl"
13679
+ #line 1313 "upb/json/parser.rl"
12678
13680
 
12679
13681
  size_t parse(void *closure, const void *hd, const char *buf, size_t size,
12680
13682
  const upb_bufhandle *handle) {
@@ -12696,7 +13698,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size,
12696
13698
  capture_resume(parser, buf);
12697
13699
 
12698
13700
 
12699
- #line 1389 "upb/json/parser.c"
13701
+ #line 1393 "upb/json/parser.c"
12700
13702
  {
12701
13703
  int _klen;
12702
13704
  unsigned int _trans;
@@ -12771,118 +13773,118 @@ _match:
12771
13773
  switch ( *_acts++ )
12772
13774
  {
12773
13775
  case 0:
12774
- #line 1221 "upb/json/parser.rl"
13776
+ #line 1225 "upb/json/parser.rl"
12775
13777
  { p--; {cs = stack[--top]; goto _again;} }
12776
13778
  break;
12777
13779
  case 1:
12778
- #line 1222 "upb/json/parser.rl"
13780
+ #line 1226 "upb/json/parser.rl"
12779
13781
  { p--; {stack[top++] = cs; cs = 10; goto _again;} }
12780
13782
  break;
12781
13783
  case 2:
12782
- #line 1226 "upb/json/parser.rl"
13784
+ #line 1230 "upb/json/parser.rl"
12783
13785
  { start_text(parser, p); }
12784
13786
  break;
12785
13787
  case 3:
12786
- #line 1227 "upb/json/parser.rl"
13788
+ #line 1231 "upb/json/parser.rl"
12787
13789
  { CHECK_RETURN_TOP(end_text(parser, p)); }
12788
13790
  break;
12789
13791
  case 4:
12790
- #line 1233 "upb/json/parser.rl"
13792
+ #line 1237 "upb/json/parser.rl"
12791
13793
  { start_hex(parser); }
12792
13794
  break;
12793
13795
  case 5:
12794
- #line 1234 "upb/json/parser.rl"
13796
+ #line 1238 "upb/json/parser.rl"
12795
13797
  { hexdigit(parser, p); }
12796
13798
  break;
12797
13799
  case 6:
12798
- #line 1235 "upb/json/parser.rl"
13800
+ #line 1239 "upb/json/parser.rl"
12799
13801
  { CHECK_RETURN_TOP(end_hex(parser)); }
12800
13802
  break;
12801
13803
  case 7:
12802
- #line 1241 "upb/json/parser.rl"
13804
+ #line 1245 "upb/json/parser.rl"
12803
13805
  { CHECK_RETURN_TOP(escape(parser, p)); }
12804
13806
  break;
12805
13807
  case 8:
12806
- #line 1247 "upb/json/parser.rl"
13808
+ #line 1251 "upb/json/parser.rl"
12807
13809
  { p--; {cs = stack[--top]; goto _again;} }
12808
13810
  break;
12809
13811
  case 9:
12810
- #line 1250 "upb/json/parser.rl"
13812
+ #line 1254 "upb/json/parser.rl"
12811
13813
  { {stack[top++] = cs; cs = 19; goto _again;} }
12812
13814
  break;
12813
13815
  case 10:
12814
- #line 1252 "upb/json/parser.rl"
13816
+ #line 1256 "upb/json/parser.rl"
12815
13817
  { p--; {stack[top++] = cs; cs = 27; goto _again;} }
12816
13818
  break;
12817
13819
  case 11:
12818
- #line 1257 "upb/json/parser.rl"
13820
+ #line 1261 "upb/json/parser.rl"
12819
13821
  { start_member(parser); }
12820
13822
  break;
12821
13823
  case 12:
12822
- #line 1258 "upb/json/parser.rl"
13824
+ #line 1262 "upb/json/parser.rl"
12823
13825
  { CHECK_RETURN_TOP(end_membername(parser)); }
12824
13826
  break;
12825
13827
  case 13:
12826
- #line 1261 "upb/json/parser.rl"
13828
+ #line 1265 "upb/json/parser.rl"
12827
13829
  { end_member(parser); }
12828
13830
  break;
12829
13831
  case 14:
12830
- #line 1267 "upb/json/parser.rl"
13832
+ #line 1271 "upb/json/parser.rl"
12831
13833
  { start_object(parser); }
12832
13834
  break;
12833
13835
  case 15:
12834
- #line 1270 "upb/json/parser.rl"
13836
+ #line 1274 "upb/json/parser.rl"
12835
13837
  { end_object(parser); }
12836
13838
  break;
12837
13839
  case 16:
12838
- #line 1276 "upb/json/parser.rl"
13840
+ #line 1280 "upb/json/parser.rl"
12839
13841
  { CHECK_RETURN_TOP(start_array(parser)); }
12840
13842
  break;
12841
13843
  case 17:
12842
- #line 1280 "upb/json/parser.rl"
13844
+ #line 1284 "upb/json/parser.rl"
12843
13845
  { end_array(parser); }
12844
13846
  break;
12845
13847
  case 18:
12846
- #line 1285 "upb/json/parser.rl"
13848
+ #line 1289 "upb/json/parser.rl"
12847
13849
  { start_number(parser, p); }
12848
13850
  break;
12849
13851
  case 19:
12850
- #line 1286 "upb/json/parser.rl"
13852
+ #line 1290 "upb/json/parser.rl"
12851
13853
  { CHECK_RETURN_TOP(end_number(parser, p)); }
12852
13854
  break;
12853
13855
  case 20:
12854
- #line 1288 "upb/json/parser.rl"
13856
+ #line 1292 "upb/json/parser.rl"
12855
13857
  { CHECK_RETURN_TOP(start_stringval(parser)); }
12856
13858
  break;
12857
13859
  case 21:
12858
- #line 1289 "upb/json/parser.rl"
13860
+ #line 1293 "upb/json/parser.rl"
12859
13861
  { CHECK_RETURN_TOP(end_stringval(parser)); }
12860
13862
  break;
12861
13863
  case 22:
12862
- #line 1291 "upb/json/parser.rl"
13864
+ #line 1295 "upb/json/parser.rl"
12863
13865
  { CHECK_RETURN_TOP(parser_putbool(parser, true)); }
12864
13866
  break;
12865
13867
  case 23:
12866
- #line 1293 "upb/json/parser.rl"
13868
+ #line 1297 "upb/json/parser.rl"
12867
13869
  { CHECK_RETURN_TOP(parser_putbool(parser, false)); }
12868
13870
  break;
12869
13871
  case 24:
12870
- #line 1295 "upb/json/parser.rl"
13872
+ #line 1299 "upb/json/parser.rl"
12871
13873
  { /* null value */ }
12872
13874
  break;
12873
13875
  case 25:
12874
- #line 1297 "upb/json/parser.rl"
13876
+ #line 1301 "upb/json/parser.rl"
12875
13877
  { CHECK_RETURN_TOP(start_subobject(parser)); }
12876
13878
  break;
12877
13879
  case 26:
12878
- #line 1298 "upb/json/parser.rl"
13880
+ #line 1302 "upb/json/parser.rl"
12879
13881
  { end_subobject(parser); }
12880
13882
  break;
12881
13883
  case 27:
12882
- #line 1303 "upb/json/parser.rl"
13884
+ #line 1307 "upb/json/parser.rl"
12883
13885
  { p--; {cs = stack[--top]; goto _again;} }
12884
13886
  break;
12885
- #line 1575 "upb/json/parser.c"
13887
+ #line 1579 "upb/json/parser.c"
12886
13888
  }
12887
13889
  }
12888
13890
 
@@ -12895,7 +13897,7 @@ _again:
12895
13897
  _out: {}
12896
13898
  }
12897
13899
 
12898
- #line 1330 "upb/json/parser.rl"
13900
+ #line 1334 "upb/json/parser.rl"
12899
13901
 
12900
13902
  if (p != pe) {
12901
13903
  upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p);
@@ -12936,13 +13938,13 @@ static void json_parser_reset(upb_json_parser *p) {
12936
13938
 
12937
13939
  /* Emit Ragel initialization of the parser. */
12938
13940
 
12939
- #line 1629 "upb/json/parser.c"
13941
+ #line 1633 "upb/json/parser.c"
12940
13942
  {
12941
13943
  cs = json_start;
12942
13944
  top = 0;
12943
13945
  }
12944
13946
 
12945
- #line 1370 "upb/json/parser.rl"
13947
+ #line 1374 "upb/json/parser.rl"
12946
13948
  p->current_state = cs;
12947
13949
  p->parser_top = top;
12948
13950
  accumulate_clear(p);