google-protobuf 4.26.0-x86-linux → 4.27.0.rc.1-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.

@@ -113,17 +113,17 @@ Error, UINTPTR_MAX is undefined
113
113
 
114
114
  // Macros for function attributes on compilers that support them.
115
115
  #ifdef __GNUC__
116
- #define UPB_FORCEINLINE __inline__ __attribute__((always_inline))
116
+ #define UPB_FORCEINLINE __inline__ __attribute__((always_inline)) static
117
117
  #define UPB_NOINLINE __attribute__((noinline))
118
118
  #define UPB_NORETURN __attribute__((__noreturn__))
119
119
  #define UPB_PRINTF(str, first_vararg) __attribute__((format (printf, str, first_vararg)))
120
120
  #elif defined(_MSC_VER)
121
121
  #define UPB_NOINLINE
122
- #define UPB_FORCEINLINE
122
+ #define UPB_FORCEINLINE static
123
123
  #define UPB_NORETURN __declspec(noreturn)
124
124
  #define UPB_PRINTF(str, first_vararg)
125
125
  #else /* !defined(__GNUC__) */
126
- #define UPB_FORCEINLINE
126
+ #define UPB_FORCEINLINE static
127
127
  #define UPB_NOINLINE
128
128
  #define UPB_NORETURN
129
129
  #define UPB_PRINTF(str, first_vararg)
@@ -305,10 +305,10 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
305
305
 
306
306
  /* Disable proto2 arena behavior (TEMPORARY) **********************************/
307
307
 
308
- #ifdef UPB_DISABLE_PROTO2_ENUM_CHECKING
309
- #define UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 1
308
+ #ifdef UPB_DISABLE_CLOSED_ENUM_CHECKING
309
+ #define UPB_TREAT_CLOSED_ENUMS_LIKE_OPEN 1
310
310
  #else
311
- #define UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 0
311
+ #define UPB_TREAT_CLOSED_ENUMS_LIKE_OPEN 0
312
312
  #endif
313
313
 
314
314
  #if defined(__cplusplus)
@@ -341,6 +341,12 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
341
341
  #define UPB_DESC_MINITABLE(sym) &google__protobuf__##sym##_msg_init
342
342
  #endif
343
343
 
344
+ #ifdef UPB_TRACING_ENABLED
345
+ #ifdef NDEBUG
346
+ error UPB_TRACING_ENABLED Tracing should be disabled in production builds
347
+ #endif
348
+ #endif
349
+
344
350
 
345
351
  #include <errno.h>
346
352
  #include <float.h>
@@ -416,6 +422,9 @@ const upb_MiniTable google__protobuf__FileDescriptorSet_msg_init = {
416
422
  &google_protobuf_FileDescriptorSet_submsgs[0],
417
423
  &google_protobuf_FileDescriptorSet__fields[0],
418
424
  16, 1, kUpb_ExtMode_NonExtendable, 1, UPB_FASTTABLE_MASK(8), 0,
425
+ #ifdef UPB_TRACING_ENABLED
426
+ "google.protobuf.FileDescriptorSet",
427
+ #endif
419
428
  UPB_FASTTABLE_INIT({
420
429
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
421
430
  {0x000800003f00000a, &upb_prm_1bt_max192b},
@@ -452,6 +461,9 @@ const upb_MiniTable google__protobuf__FileDescriptorProto_msg_init = {
452
461
  &google_protobuf_FileDescriptorProto_submsgs[0],
453
462
  &google_protobuf_FileDescriptorProto__fields[0],
454
463
  UPB_SIZE(80, 136), 13, kUpb_ExtMode_NonExtendable, 12, UPB_FASTTABLE_MASK(120), 0,
464
+ #ifdef UPB_TRACING_ENABLED
465
+ "google.protobuf.FileDescriptorProto",
466
+ #endif
455
467
  UPB_FASTTABLE_INIT({
456
468
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
457
469
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
@@ -500,6 +512,9 @@ const upb_MiniTable google__protobuf__DescriptorProto_msg_init = {
500
512
  &google_protobuf_DescriptorProto_submsgs[0],
501
513
  &google_protobuf_DescriptorProto__fields[0],
502
514
  UPB_SIZE(56, 104), 10, kUpb_ExtMode_NonExtendable, 10, UPB_FASTTABLE_MASK(120), 0,
515
+ #ifdef UPB_TRACING_ENABLED
516
+ "google.protobuf.DescriptorProto",
517
+ #endif
503
518
  UPB_FASTTABLE_INIT({
504
519
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
505
520
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
@@ -534,6 +549,9 @@ const upb_MiniTable google__protobuf__DescriptorProto__ExtensionRange_msg_init =
534
549
  &google_protobuf_DescriptorProto_ExtensionRange_submsgs[0],
535
550
  &google_protobuf_DescriptorProto_ExtensionRange__fields[0],
536
551
  UPB_SIZE(24, 32), 3, kUpb_ExtMode_NonExtendable, 3, UPB_FASTTABLE_MASK(255), 0,
552
+ #ifdef UPB_TRACING_ENABLED
553
+ "google.protobuf.DescriptorProto.ExtensionRange",
554
+ #endif
537
555
  };
538
556
 
539
557
  static const upb_MiniTableField google_protobuf_DescriptorProto_ReservedRange__fields[2] = {
@@ -545,6 +563,9 @@ const upb_MiniTable google__protobuf__DescriptorProto__ReservedRange_msg_init =
545
563
  NULL,
546
564
  &google_protobuf_DescriptorProto_ReservedRange__fields[0],
547
565
  24, 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(255), 0,
566
+ #ifdef UPB_TRACING_ENABLED
567
+ "google.protobuf.DescriptorProto.ReservedRange",
568
+ #endif
548
569
  };
549
570
 
550
571
  static const upb_MiniTableSub google_protobuf_ExtensionRangeOptions_submsgs[4] = {
@@ -565,6 +586,9 @@ const upb_MiniTable google__protobuf__ExtensionRangeOptions_msg_init = {
565
586
  &google_protobuf_ExtensionRangeOptions_submsgs[0],
566
587
  &google_protobuf_ExtensionRangeOptions__fields[0],
567
588
  UPB_SIZE(32, 40), 4, kUpb_ExtMode_Extendable, 0, UPB_FASTTABLE_MASK(248), 0,
589
+ #ifdef UPB_TRACING_ENABLED
590
+ "google.protobuf.ExtensionRangeOptions",
591
+ #endif
568
592
  UPB_FASTTABLE_INIT({
569
593
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
570
594
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
@@ -613,6 +637,9 @@ const upb_MiniTable google__protobuf__ExtensionRangeOptions__Declaration_msg_ini
613
637
  NULL,
614
638
  &google_protobuf_ExtensionRangeOptions_Declaration__fields[0],
615
639
  UPB_SIZE(40, 56), 5, kUpb_ExtMode_NonExtendable, 3, UPB_FASTTABLE_MASK(255), 0,
640
+ #ifdef UPB_TRACING_ENABLED
641
+ "google.protobuf.ExtensionRangeOptions.Declaration",
642
+ #endif
616
643
  };
617
644
 
618
645
  static const upb_MiniTableSub google_protobuf_FieldDescriptorProto_submsgs[3] = {
@@ -639,6 +666,9 @@ const upb_MiniTable google__protobuf__FieldDescriptorProto_msg_init = {
639
666
  &google_protobuf_FieldDescriptorProto_submsgs[0],
640
667
  &google_protobuf_FieldDescriptorProto__fields[0],
641
668
  UPB_SIZE(80, 120), 11, kUpb_ExtMode_NonExtendable, 10, UPB_FASTTABLE_MASK(255), 0,
669
+ #ifdef UPB_TRACING_ENABLED
670
+ "google.protobuf.FieldDescriptorProto",
671
+ #endif
642
672
  };
643
673
 
644
674
  static const upb_MiniTableSub google_protobuf_OneofDescriptorProto_submsgs[1] = {
@@ -654,6 +684,9 @@ const upb_MiniTable google__protobuf__OneofDescriptorProto_msg_init = {
654
684
  &google_protobuf_OneofDescriptorProto_submsgs[0],
655
685
  &google_protobuf_OneofDescriptorProto__fields[0],
656
686
  UPB_SIZE(24, 40), 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(255), 0,
687
+ #ifdef UPB_TRACING_ENABLED
688
+ "google.protobuf.OneofDescriptorProto",
689
+ #endif
657
690
  };
658
691
 
659
692
  static const upb_MiniTableSub google_protobuf_EnumDescriptorProto_submsgs[3] = {
@@ -674,6 +707,9 @@ const upb_MiniTable google__protobuf__EnumDescriptorProto_msg_init = {
674
707
  &google_protobuf_EnumDescriptorProto_submsgs[0],
675
708
  &google_protobuf_EnumDescriptorProto__fields[0],
676
709
  UPB_SIZE(40, 64), 5, kUpb_ExtMode_NonExtendable, 5, UPB_FASTTABLE_MASK(56), 0,
710
+ #ifdef UPB_TRACING_ENABLED
711
+ "google.protobuf.EnumDescriptorProto",
712
+ #endif
677
713
  UPB_FASTTABLE_INIT({
678
714
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
679
715
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
@@ -695,6 +731,9 @@ const upb_MiniTable google__protobuf__EnumDescriptorProto__EnumReservedRange_msg
695
731
  NULL,
696
732
  &google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[0],
697
733
  24, 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(255), 0,
734
+ #ifdef UPB_TRACING_ENABLED
735
+ "google.protobuf.EnumDescriptorProto.EnumReservedRange",
736
+ #endif
698
737
  };
699
738
 
700
739
  static const upb_MiniTableSub google_protobuf_EnumValueDescriptorProto_submsgs[1] = {
@@ -711,6 +750,9 @@ const upb_MiniTable google__protobuf__EnumValueDescriptorProto_msg_init = {
711
750
  &google_protobuf_EnumValueDescriptorProto_submsgs[0],
712
751
  &google_protobuf_EnumValueDescriptorProto__fields[0],
713
752
  UPB_SIZE(32, 40), 3, kUpb_ExtMode_NonExtendable, 3, UPB_FASTTABLE_MASK(255), 0,
753
+ #ifdef UPB_TRACING_ENABLED
754
+ "google.protobuf.EnumValueDescriptorProto",
755
+ #endif
714
756
  };
715
757
 
716
758
  static const upb_MiniTableSub google_protobuf_ServiceDescriptorProto_submsgs[2] = {
@@ -728,6 +770,9 @@ const upb_MiniTable google__protobuf__ServiceDescriptorProto_msg_init = {
728
770
  &google_protobuf_ServiceDescriptorProto_submsgs[0],
729
771
  &google_protobuf_ServiceDescriptorProto__fields[0],
730
772
  UPB_SIZE(32, 48), 3, kUpb_ExtMode_NonExtendable, 3, UPB_FASTTABLE_MASK(24), 0,
773
+ #ifdef UPB_TRACING_ENABLED
774
+ "google.protobuf.ServiceDescriptorProto",
775
+ #endif
731
776
  UPB_FASTTABLE_INIT({
732
777
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
733
778
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
@@ -753,6 +798,9 @@ const upb_MiniTable google__protobuf__MethodDescriptorProto_msg_init = {
753
798
  &google_protobuf_MethodDescriptorProto_submsgs[0],
754
799
  &google_protobuf_MethodDescriptorProto__fields[0],
755
800
  UPB_SIZE(48, 72), 6, kUpb_ExtMode_NonExtendable, 6, UPB_FASTTABLE_MASK(255), 0,
801
+ #ifdef UPB_TRACING_ENABLED
802
+ "google.protobuf.MethodDescriptorProto",
803
+ #endif
756
804
  };
757
805
 
758
806
  static const upb_MiniTableSub google_protobuf_FileOptions_submsgs[3] = {
@@ -789,6 +837,9 @@ const upb_MiniTable google__protobuf__FileOptions_msg_init = {
789
837
  &google_protobuf_FileOptions_submsgs[0],
790
838
  &google_protobuf_FileOptions__fields[0],
791
839
  UPB_SIZE(112, 200), 21, kUpb_ExtMode_Extendable, 1, UPB_FASTTABLE_MASK(248), 0,
840
+ #ifdef UPB_TRACING_ENABLED
841
+ "google.protobuf.FileOptions",
842
+ #endif
792
843
  UPB_FASTTABLE_INIT({
793
844
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
794
845
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
@@ -844,6 +895,9 @@ const upb_MiniTable google__protobuf__MessageOptions_msg_init = {
844
895
  &google_protobuf_MessageOptions_submsgs[0],
845
896
  &google_protobuf_MessageOptions__fields[0],
846
897
  UPB_SIZE(24, 32), 7, kUpb_ExtMode_Extendable, 3, UPB_FASTTABLE_MASK(248), 0,
898
+ #ifdef UPB_TRACING_ENABLED
899
+ "google.protobuf.MessageOptions",
900
+ #endif
847
901
  UPB_FASTTABLE_INIT({
848
902
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
849
903
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
@@ -880,9 +934,10 @@ const upb_MiniTable google__protobuf__MessageOptions_msg_init = {
880
934
  })
881
935
  };
882
936
 
883
- static const upb_MiniTableSub google_protobuf_FieldOptions_submsgs[7] = {
937
+ static const upb_MiniTableSub google_protobuf_FieldOptions_submsgs[8] = {
884
938
  {.UPB_PRIVATE(submsg) = &google__protobuf__FieldOptions__EditionDefault_msg_init},
885
939
  {.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSet_msg_init},
940
+ {.UPB_PRIVATE(submsg) = &google__protobuf__FieldOptions__FeatureSupport_msg_init},
886
941
  {.UPB_PRIVATE(submsg) = &google__protobuf__UninterpretedOption_msg_init},
887
942
  {.UPB_PRIVATE(subenum) = &google_protobuf_FieldOptions_CType_enum_init},
888
943
  {.UPB_PRIVATE(subenum) = &google_protobuf_FieldOptions_JSType_enum_init},
@@ -890,26 +945,30 @@ static const upb_MiniTableSub google_protobuf_FieldOptions_submsgs[7] = {
890
945
  {.UPB_PRIVATE(subenum) = &google_protobuf_FieldOptions_OptionTargetType_enum_init},
891
946
  };
892
947
 
893
- static const upb_MiniTableField google_protobuf_FieldOptions__fields[13] = {
894
- {1, 12, 64, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
948
+ static const upb_MiniTableField google_protobuf_FieldOptions__fields[14] = {
949
+ {1, 12, 64, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
895
950
  {2, 16, 65, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)},
896
951
  {3, 17, 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)},
897
952
  {5, 18, 67, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)},
898
- {6, 20, 68, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
953
+ {6, 20, 68, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
899
954
  {10, 24, 69, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)},
900
955
  {15, 25, 70, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)},
901
956
  {16, 26, 71, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)},
902
- {17, 28, 72, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
903
- {19, 32, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
957
+ {17, 28, 72, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
958
+ {19, 32, 0, 7, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
904
959
  {20, UPB_SIZE(36, 40), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
905
960
  {21, UPB_SIZE(40, 48), 73, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
906
- {999, UPB_SIZE(44, 56), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
961
+ {22, UPB_SIZE(44, 56), 74, 2, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
962
+ {999, UPB_SIZE(48, 64), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
907
963
  };
908
964
 
909
965
  const upb_MiniTable google__protobuf__FieldOptions_msg_init = {
910
966
  &google_protobuf_FieldOptions_submsgs[0],
911
967
  &google_protobuf_FieldOptions__fields[0],
912
- UPB_SIZE(48, 64), 13, kUpb_ExtMode_Extendable, 3, UPB_FASTTABLE_MASK(248), 0,
968
+ UPB_SIZE(56, 72), 14, kUpb_ExtMode_Extendable, 3, UPB_FASTTABLE_MASK(248), 0,
969
+ #ifdef UPB_TRACING_ENABLED
970
+ "google.protobuf.FieldOptions",
971
+ #endif
913
972
  UPB_FASTTABLE_INIT({
914
973
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
915
974
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
@@ -934,7 +993,7 @@ const upb_MiniTable google__protobuf__FieldOptions_msg_init = {
934
993
  {0x002800003f0001a2, &upb_prm_2bt_max64b},
935
994
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
936
995
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
937
- {0x003800003f023eba, &upb_prm_2bt_max128b},
996
+ {0x004000003f033eba, &upb_prm_2bt_max128b},
938
997
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
939
998
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
940
999
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
@@ -959,6 +1018,31 @@ const upb_MiniTable google__protobuf__FieldOptions__EditionDefault_msg_init = {
959
1018
  &google_protobuf_FieldOptions_EditionDefault_submsgs[0],
960
1019
  &google_protobuf_FieldOptions_EditionDefault__fields[0],
961
1020
  UPB_SIZE(24, 32), 2, kUpb_ExtMode_NonExtendable, 0, UPB_FASTTABLE_MASK(255), 0,
1021
+ #ifdef UPB_TRACING_ENABLED
1022
+ "google.protobuf.FieldOptions.EditionDefault",
1023
+ #endif
1024
+ };
1025
+
1026
+ static const upb_MiniTableSub google_protobuf_FieldOptions_FeatureSupport_submsgs[3] = {
1027
+ {.UPB_PRIVATE(subenum) = &google_protobuf_Edition_enum_init},
1028
+ {.UPB_PRIVATE(subenum) = &google_protobuf_Edition_enum_init},
1029
+ {.UPB_PRIVATE(subenum) = &google_protobuf_Edition_enum_init},
1030
+ };
1031
+
1032
+ static const upb_MiniTableField google_protobuf_FieldOptions_FeatureSupport__fields[4] = {
1033
+ {1, 12, 64, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
1034
+ {2, 16, 65, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
1035
+ {3, 24, 66, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)},
1036
+ {4, 20, 67, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
1037
+ };
1038
+
1039
+ const upb_MiniTable google__protobuf__FieldOptions__FeatureSupport_msg_init = {
1040
+ &google_protobuf_FieldOptions_FeatureSupport_submsgs[0],
1041
+ &google_protobuf_FieldOptions_FeatureSupport__fields[0],
1042
+ UPB_SIZE(32, 40), 4, kUpb_ExtMode_NonExtendable, 4, UPB_FASTTABLE_MASK(255), 0,
1043
+ #ifdef UPB_TRACING_ENABLED
1044
+ "google.protobuf.FieldOptions.FeatureSupport",
1045
+ #endif
962
1046
  };
963
1047
 
964
1048
  static const upb_MiniTableSub google_protobuf_OneofOptions_submsgs[2] = {
@@ -975,6 +1059,9 @@ const upb_MiniTable google__protobuf__OneofOptions_msg_init = {
975
1059
  &google_protobuf_OneofOptions_submsgs[0],
976
1060
  &google_protobuf_OneofOptions__fields[0],
977
1061
  UPB_SIZE(24, 32), 2, kUpb_ExtMode_Extendable, 1, UPB_FASTTABLE_MASK(248), 0,
1062
+ #ifdef UPB_TRACING_ENABLED
1063
+ "google.protobuf.OneofOptions",
1064
+ #endif
978
1065
  UPB_FASTTABLE_INIT({
979
1066
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
980
1067
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
@@ -1028,6 +1115,9 @@ const upb_MiniTable google__protobuf__EnumOptions_msg_init = {
1028
1115
  &google_protobuf_EnumOptions_submsgs[0],
1029
1116
  &google_protobuf_EnumOptions__fields[0],
1030
1117
  UPB_SIZE(24, 32), 5, kUpb_ExtMode_Extendable, 0, UPB_FASTTABLE_MASK(248), 0,
1118
+ #ifdef UPB_TRACING_ENABLED
1119
+ "google.protobuf.EnumOptions",
1120
+ #endif
1031
1121
  UPB_FASTTABLE_INIT({
1032
1122
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
1033
1123
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
@@ -1080,6 +1170,9 @@ const upb_MiniTable google__protobuf__EnumValueOptions_msg_init = {
1080
1170
  &google_protobuf_EnumValueOptions_submsgs[0],
1081
1171
  &google_protobuf_EnumValueOptions__fields[0],
1082
1172
  UPB_SIZE(24, 32), 4, kUpb_ExtMode_Extendable, 3, UPB_FASTTABLE_MASK(248), 0,
1173
+ #ifdef UPB_TRACING_ENABLED
1174
+ "google.protobuf.EnumValueOptions",
1175
+ #endif
1083
1176
  UPB_FASTTABLE_INIT({
1084
1177
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
1085
1178
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
@@ -1131,6 +1224,9 @@ const upb_MiniTable google__protobuf__ServiceOptions_msg_init = {
1131
1224
  &google_protobuf_ServiceOptions_submsgs[0],
1132
1225
  &google_protobuf_ServiceOptions__fields[0],
1133
1226
  UPB_SIZE(24, 32), 3, kUpb_ExtMode_Extendable, 0, UPB_FASTTABLE_MASK(248), 0,
1227
+ #ifdef UPB_TRACING_ENABLED
1228
+ "google.protobuf.ServiceOptions",
1229
+ #endif
1134
1230
  UPB_FASTTABLE_INIT({
1135
1231
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
1136
1232
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
@@ -1184,6 +1280,9 @@ const upb_MiniTable google__protobuf__MethodOptions_msg_init = {
1184
1280
  &google_protobuf_MethodOptions_submsgs[0],
1185
1281
  &google_protobuf_MethodOptions__fields[0],
1186
1282
  UPB_SIZE(24, 32), 4, kUpb_ExtMode_Extendable, 0, UPB_FASTTABLE_MASK(248), 0,
1283
+ #ifdef UPB_TRACING_ENABLED
1284
+ "google.protobuf.MethodOptions",
1285
+ #endif
1187
1286
  UPB_FASTTABLE_INIT({
1188
1287
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
1189
1288
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
@@ -1238,6 +1337,9 @@ const upb_MiniTable google__protobuf__UninterpretedOption_msg_init = {
1238
1337
  &google_protobuf_UninterpretedOption_submsgs[0],
1239
1338
  &google_protobuf_UninterpretedOption__fields[0],
1240
1339
  UPB_SIZE(64, 96), 7, kUpb_ExtMode_NonExtendable, 0, UPB_FASTTABLE_MASK(24), 0,
1340
+ #ifdef UPB_TRACING_ENABLED
1341
+ "google.protobuf.UninterpretedOption",
1342
+ #endif
1241
1343
  UPB_FASTTABLE_INIT({
1242
1344
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
1243
1345
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
@@ -1255,6 +1357,9 @@ const upb_MiniTable google__protobuf__UninterpretedOption__NamePart_msg_init = {
1255
1357
  NULL,
1256
1358
  &google_protobuf_UninterpretedOption_NamePart__fields[0],
1257
1359
  UPB_SIZE(24, 32), 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(255), 2,
1360
+ #ifdef UPB_TRACING_ENABLED
1361
+ "google.protobuf.UninterpretedOption.NamePart",
1362
+ #endif
1258
1363
  };
1259
1364
 
1260
1365
  static const upb_MiniTableSub google_protobuf_FeatureSet_submsgs[6] = {
@@ -1279,6 +1384,9 @@ const upb_MiniTable google__protobuf__FeatureSet_msg_init = {
1279
1384
  &google_protobuf_FeatureSet_submsgs[0],
1280
1385
  &google_protobuf_FeatureSet__fields[0],
1281
1386
  40, 6, kUpb_ExtMode_Extendable, 6, UPB_FASTTABLE_MASK(255), 0,
1387
+ #ifdef UPB_TRACING_ENABLED
1388
+ "google.protobuf.FeatureSet",
1389
+ #endif
1282
1390
  };
1283
1391
 
1284
1392
  static const upb_MiniTableSub google_protobuf_FeatureSetDefaults_submsgs[3] = {
@@ -1297,26 +1405,34 @@ const upb_MiniTable google__protobuf__FeatureSetDefaults_msg_init = {
1297
1405
  &google_protobuf_FeatureSetDefaults_submsgs[0],
1298
1406
  &google_protobuf_FeatureSetDefaults__fields[0],
1299
1407
  UPB_SIZE(24, 32), 3, kUpb_ExtMode_NonExtendable, 1, UPB_FASTTABLE_MASK(8), 0,
1408
+ #ifdef UPB_TRACING_ENABLED
1409
+ "google.protobuf.FeatureSetDefaults",
1410
+ #endif
1300
1411
  UPB_FASTTABLE_INIT({
1301
1412
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
1302
1413
  {0x001800003f00000a, &upb_prm_1bt_max64b},
1303
1414
  })
1304
1415
  };
1305
1416
 
1306
- static const upb_MiniTableSub google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_submsgs[2] = {
1417
+ static const upb_MiniTableSub google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_submsgs[3] = {
1418
+ {.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSet_msg_init},
1307
1419
  {.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSet_msg_init},
1308
1420
  {.UPB_PRIVATE(subenum) = &google_protobuf_Edition_enum_init},
1309
1421
  };
1310
1422
 
1311
- static const upb_MiniTableField google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault__fields[2] = {
1312
- {2, UPB_SIZE(12, 16), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
1313
- {3, UPB_SIZE(16, 12), 65, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
1423
+ static const upb_MiniTableField google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault__fields[3] = {
1424
+ {3, 12, 64, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
1425
+ {4, 16, 65, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
1426
+ {5, UPB_SIZE(20, 24), 66, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
1314
1427
  };
1315
1428
 
1316
1429
  const upb_MiniTable google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init = {
1317
1430
  &google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_submsgs[0],
1318
1431
  &google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault__fields[0],
1319
- 24, 2, kUpb_ExtMode_NonExtendable, 0, UPB_FASTTABLE_MASK(255), 0,
1432
+ UPB_SIZE(24, 32), 3, kUpb_ExtMode_NonExtendable, 0, UPB_FASTTABLE_MASK(255), 0,
1433
+ #ifdef UPB_TRACING_ENABLED
1434
+ "google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault",
1435
+ #endif
1320
1436
  };
1321
1437
 
1322
1438
  static const upb_MiniTableSub google_protobuf_SourceCodeInfo_submsgs[1] = {
@@ -1331,6 +1447,9 @@ const upb_MiniTable google__protobuf__SourceCodeInfo_msg_init = {
1331
1447
  &google_protobuf_SourceCodeInfo_submsgs[0],
1332
1448
  &google_protobuf_SourceCodeInfo__fields[0],
1333
1449
  16, 1, kUpb_ExtMode_NonExtendable, 1, UPB_FASTTABLE_MASK(8), 0,
1450
+ #ifdef UPB_TRACING_ENABLED
1451
+ "google.protobuf.SourceCodeInfo",
1452
+ #endif
1334
1453
  UPB_FASTTABLE_INIT({
1335
1454
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
1336
1455
  {0x000800003f00000a, &upb_prm_1bt_max128b},
@@ -1349,6 +1468,9 @@ const upb_MiniTable google__protobuf__SourceCodeInfo__Location_msg_init = {
1349
1468
  NULL,
1350
1469
  &google_protobuf_SourceCodeInfo_Location__fields[0],
1351
1470
  UPB_SIZE(40, 72), 5, kUpb_ExtMode_NonExtendable, 4, UPB_FASTTABLE_MASK(56), 0,
1471
+ #ifdef UPB_TRACING_ENABLED
1472
+ "google.protobuf.SourceCodeInfo.Location",
1473
+ #endif
1352
1474
  UPB_FASTTABLE_INIT({
1353
1475
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
1354
1476
  {0x001000003f00000a, &upb_ppv4_1bt},
@@ -1373,6 +1495,9 @@ const upb_MiniTable google__protobuf__GeneratedCodeInfo_msg_init = {
1373
1495
  &google_protobuf_GeneratedCodeInfo_submsgs[0],
1374
1496
  &google_protobuf_GeneratedCodeInfo__fields[0],
1375
1497
  16, 1, kUpb_ExtMode_NonExtendable, 1, UPB_FASTTABLE_MASK(8), 0,
1498
+ #ifdef UPB_TRACING_ENABLED
1499
+ "google.protobuf.GeneratedCodeInfo",
1500
+ #endif
1376
1501
  UPB_FASTTABLE_INIT({
1377
1502
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
1378
1503
  {0x000800003f00000a, &upb_prm_1bt_max64b},
@@ -1395,13 +1520,16 @@ const upb_MiniTable google__protobuf__GeneratedCodeInfo__Annotation_msg_init = {
1395
1520
  &google_protobuf_GeneratedCodeInfo_Annotation_submsgs[0],
1396
1521
  &google_protobuf_GeneratedCodeInfo_Annotation__fields[0],
1397
1522
  UPB_SIZE(40, 48), 5, kUpb_ExtMode_NonExtendable, 5, UPB_FASTTABLE_MASK(8), 0,
1523
+ #ifdef UPB_TRACING_ENABLED
1524
+ "google.protobuf.GeneratedCodeInfo.Annotation",
1525
+ #endif
1398
1526
  UPB_FASTTABLE_INIT({
1399
1527
  {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
1400
1528
  {0x001800003f00000a, &upb_ppv4_1bt},
1401
1529
  })
1402
1530
  };
1403
1531
 
1404
- static const upb_MiniTable *messages_layout[32] = {
1532
+ static const upb_MiniTable *messages_layout[33] = {
1405
1533
  &google__protobuf__FileDescriptorSet_msg_init,
1406
1534
  &google__protobuf__FileDescriptorProto_msg_init,
1407
1535
  &google__protobuf__DescriptorProto_msg_init,
@@ -1420,6 +1548,7 @@ static const upb_MiniTable *messages_layout[32] = {
1420
1548
  &google__protobuf__MessageOptions_msg_init,
1421
1549
  &google__protobuf__FieldOptions_msg_init,
1422
1550
  &google__protobuf__FieldOptions__EditionDefault_msg_init,
1551
+ &google__protobuf__FieldOptions__FeatureSupport_msg_init,
1423
1552
  &google__protobuf__OneofOptions_msg_init,
1424
1553
  &google__protobuf__EnumOptions_msg_init,
1425
1554
  &google__protobuf__EnumValueOptions_msg_init,
@@ -1438,10 +1567,11 @@ static const upb_MiniTable *messages_layout[32] = {
1438
1567
 
1439
1568
  const upb_MiniTableEnum google_protobuf_Edition_enum_init = {
1440
1569
  64,
1441
- 8,
1570
+ 9,
1442
1571
  {
1443
1572
  0x7,
1444
1573
  0x0,
1574
+ 0x384,
1445
1575
  0x3e6,
1446
1576
  0x3e7,
1447
1577
  0x3e8,
@@ -1621,7 +1751,7 @@ const upb_MiniTableFile google_protobuf_descriptor_proto_upb_file_layout = {
1621
1751
  messages_layout,
1622
1752
  enums_layout,
1623
1753
  NULL,
1624
- 32,
1754
+ 33,
1625
1755
  17,
1626
1756
  0,
1627
1757
  };
@@ -3131,6 +3261,7 @@ static bool upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg,
3131
3261
  bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg,
3132
3262
  const upb_MessageDef* m, const upb_DefPool* symtab,
3133
3263
  int options, upb_Arena* arena, upb_Status* status) {
3264
+ UPB_ASSERT(!upb_Message_IsFrozen(msg));
3134
3265
  jsondec d;
3135
3266
 
3136
3267
  if (size == 0) return true;
@@ -3941,6 +4072,10 @@ static void* upb_global_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize,
3941
4072
  upb_alloc upb_alloc_global = {&upb_global_allocfunc};
3942
4073
 
3943
4074
 
4075
+ #ifdef UPB_TRACING_ENABLED
4076
+ #include <stdatomic.h>
4077
+ #endif
4078
+
3944
4079
  #include <stddef.h>
3945
4080
  #include <stdint.h>
3946
4081
 
@@ -4047,6 +4182,38 @@ static bool _upb_ArenaInternal_HasInitialBlock(upb_ArenaInternal* ai) {
4047
4182
  return ai->block_alloc & 0x1;
4048
4183
  }
4049
4184
 
4185
+ #ifdef UPB_TRACING_ENABLED
4186
+ static void (*_init_arena_trace_handler)(const upb_Arena*, size_t size) = NULL;
4187
+ static void (*_fuse_arena_trace_handler)(const upb_Arena*,
4188
+ const upb_Arena*) = NULL;
4189
+ static void (*_free_arena_trace_handler)(const upb_Arena*) = NULL;
4190
+
4191
+ void upb_Arena_SetTraceHandler(
4192
+ void (*initArenaTraceHandler)(const upb_Arena*, size_t size),
4193
+ void (*fuseArenaTraceHandler)(const upb_Arena*, const upb_Arena*),
4194
+ void (*freeArenaTraceHandler)(const upb_Arena*)) {
4195
+ _init_arena_trace_handler = initArenaTraceHandler;
4196
+ _fuse_arena_trace_handler = fuseArenaTraceHandler;
4197
+ _free_arena_trace_handler = freeArenaTraceHandler;
4198
+ }
4199
+
4200
+ void upb_Arena_LogInit(const upb_Arena* arena, size_t size) {
4201
+ if (_init_arena_trace_handler) {
4202
+ _init_arena_trace_handler(arena, size);
4203
+ }
4204
+ }
4205
+ void upb_Arena_LogFuse(const upb_Arena* arena1, const upb_Arena* arena2) {
4206
+ if (_fuse_arena_trace_handler) {
4207
+ _fuse_arena_trace_handler(arena1, arena2);
4208
+ }
4209
+ }
4210
+ void upb_Arena_LogFree(const upb_Arena* arena) {
4211
+ if (_free_arena_trace_handler) {
4212
+ _free_arena_trace_handler(arena);
4213
+ }
4214
+ }
4215
+ #endif // UPB_TRACING_ENABLED
4216
+
4050
4217
  static upb_ArenaRoot _upb_Arena_FindRoot(upb_Arena* a) {
4051
4218
  upb_ArenaInternal* ai = upb_Arena_Internal(a);
4052
4219
  uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire);
@@ -4104,6 +4271,21 @@ size_t upb_Arena_SpaceAllocated(upb_Arena* arena, size_t* fused_count) {
4104
4271
  return memsize;
4105
4272
  }
4106
4273
 
4274
+ bool UPB_PRIVATE(_upb_Arena_Contains)(const upb_Arena* a, void* ptr) {
4275
+ upb_ArenaInternal* ai = upb_Arena_Internal(a);
4276
+ UPB_ASSERT(ai);
4277
+
4278
+ upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_relaxed);
4279
+ while (block) {
4280
+ uintptr_t beg = (uintptr_t)block;
4281
+ uintptr_t end = beg + block->size;
4282
+ if ((uintptr_t)ptr >= beg && (uintptr_t)ptr < end) return true;
4283
+ block = upb_Atomic_Load(&block->next, memory_order_relaxed);
4284
+ }
4285
+
4286
+ return false;
4287
+ }
4288
+
4107
4289
  uint32_t upb_Arena_DebugRefCount(upb_Arena* a) {
4108
4290
  upb_ArenaInternal* ai = upb_Arena_Internal(a);
4109
4291
  // These loads could probably be relaxed, but given that this is debug-only,
@@ -4195,7 +4377,13 @@ upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) {
4195
4377
  n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_ArenaState));
4196
4378
 
4197
4379
  if (UPB_UNLIKELY(n < sizeof(upb_ArenaState))) {
4380
+ #ifdef UPB_TRACING_ENABLED
4381
+ upb_Arena* ret = _upb_Arena_InitSlow(alloc);
4382
+ upb_Arena_LogInit(ret, n);
4383
+ return ret;
4384
+ #else
4198
4385
  return _upb_Arena_InitSlow(alloc);
4386
+ #endif
4199
4387
  }
4200
4388
 
4201
4389
  a = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), upb_ArenaState);
@@ -4208,13 +4396,14 @@ upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) {
4208
4396
  a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 1);
4209
4397
  a->head.UPB_PRIVATE(ptr) = mem;
4210
4398
  a->head.UPB_PRIVATE(end) = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), char);
4211
-
4399
+ #ifdef UPB_TRACING_ENABLED
4400
+ upb_Arena_LogInit(&a->head, n);
4401
+ #endif
4212
4402
  return &a->head;
4213
4403
  }
4214
4404
 
4215
4405
  static void _upb_Arena_DoFree(upb_ArenaInternal* ai) {
4216
4406
  UPB_ASSERT(_upb_Arena_RefCountFromTagged(ai->parent_or_count) == 1);
4217
-
4218
4407
  while (ai != NULL) {
4219
4408
  // Load first since arena itself is likely from one of its blocks.
4220
4409
  upb_ArenaInternal* next_arena =
@@ -4245,6 +4434,9 @@ retry:
4245
4434
  // expensive then direct loads. As an optimization, we only do RMW ops
4246
4435
  // when we need to update things for other threads to see.
4247
4436
  if (poc == _upb_Arena_TaggedFromRefcount(1)) {
4437
+ #ifdef UPB_TRACING_ENABLED
4438
+ upb_Arena_LogFree(a);
4439
+ #endif
4248
4440
  _upb_Arena_DoFree(ai);
4249
4441
  return;
4250
4442
  }
@@ -4364,6 +4556,10 @@ static bool _upb_Arena_FixupRefs(upb_ArenaInternal* new_root,
4364
4556
  bool upb_Arena_Fuse(upb_Arena* a1, upb_Arena* a2) {
4365
4557
  if (a1 == a2) return true; // trivial fuse
4366
4558
 
4559
+ #ifdef UPB_TRACING_ENABLED
4560
+ upb_Arena_LogFuse(a1, a2);
4561
+ #endif
4562
+
4367
4563
  upb_ArenaInternal* ai1 = upb_Arena_Internal(a1);
4368
4564
  upb_ArenaInternal* ai2 = upb_Arena_Internal(a2);
4369
4565
 
@@ -4430,18 +4626,19 @@ void UPB_PRIVATE(_upb_Arena_SwapOut)(upb_Arena* des, const upb_Arena* src) {
4430
4626
 
4431
4627
  // Must be last.
4432
4628
 
4433
- bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table,
4629
+ bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* m,
4434
4630
  const upb_MiniTableField* f,
4435
4631
  upb_Message* map_entry_message, upb_Arena* arena) {
4632
+ UPB_ASSERT(!upb_Message_IsFrozen(map_entry_message));
4633
+
4436
4634
  // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here.
4437
4635
  const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message(
4438
- mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]);
4636
+ m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]);
4439
4637
  UPB_ASSERT(map_entry_mini_table);
4440
- UPB_ASSERT(map_entry_mini_table->UPB_PRIVATE(field_count) == 2);
4441
4638
  const upb_MiniTableField* map_entry_key_field =
4442
- &map_entry_mini_table->UPB_PRIVATE(fields)[0];
4639
+ upb_MiniTable_MapKey(map_entry_mini_table);
4443
4640
  const upb_MiniTableField* map_entry_value_field =
4444
- &map_entry_mini_table->UPB_PRIVATE(fields)[1];
4641
+ upb_MiniTable_MapValue(map_entry_mini_table);
4445
4642
  // Map key/value cannot have explicit defaults,
4446
4643
  // hence assuming a zero default is valid.
4447
4644
  upb_MessageValue default_val;
@@ -4466,31 +4663,33 @@ upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) {
4466
4663
  }
4467
4664
 
4468
4665
  upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) {
4666
+ UPB_ASSERT(i < upb_Array_Size(arr));
4469
4667
  upb_MessageValue ret;
4470
4668
  const char* data = upb_Array_DataPtr(arr);
4471
4669
  const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr);
4472
- UPB_ASSERT(i < arr->UPB_PRIVATE(size));
4473
4670
  memcpy(&ret, data + (i << lg2), 1 << lg2);
4474
4671
  return ret;
4475
4672
  }
4476
4673
 
4477
4674
  upb_MutableMessageValue upb_Array_GetMutable(upb_Array* arr, size_t i) {
4675
+ UPB_ASSERT(i < upb_Array_Size(arr));
4478
4676
  upb_MutableMessageValue ret;
4479
4677
  char* data = upb_Array_MutableDataPtr(arr);
4480
4678
  const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr);
4481
- UPB_ASSERT(i < arr->UPB_PRIVATE(size));
4482
4679
  memcpy(&ret, data + (i << lg2), 1 << lg2);
4483
4680
  return ret;
4484
4681
  }
4485
4682
 
4486
4683
  void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) {
4684
+ UPB_ASSERT(!upb_Array_IsFrozen(arr));
4685
+ UPB_ASSERT(i < upb_Array_Size(arr));
4487
4686
  char* data = upb_Array_MutableDataPtr(arr);
4488
4687
  const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr);
4489
- UPB_ASSERT(i < arr->UPB_PRIVATE(size));
4490
4688
  memcpy(data + (i << lg2), &val, 1 << lg2);
4491
4689
  }
4492
4690
 
4493
4691
  bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) {
4692
+ UPB_ASSERT(!upb_Array_IsFrozen(arr));
4494
4693
  UPB_ASSERT(arena);
4495
4694
  if (!UPB_PRIVATE(_upb_Array_ResizeUninitialized)(
4496
4695
  arr, arr->UPB_PRIVATE(size) + 1, arena)) {
@@ -4502,6 +4701,7 @@ bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) {
4502
4701
 
4503
4702
  void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx,
4504
4703
  size_t count) {
4704
+ UPB_ASSERT(!upb_Array_IsFrozen(arr));
4505
4705
  const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr);
4506
4706
  char* data = upb_Array_MutableDataPtr(arr);
4507
4707
  memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2);
@@ -4509,6 +4709,7 @@ void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx,
4509
4709
 
4510
4710
  bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count,
4511
4711
  upb_Arena* arena) {
4712
+ UPB_ASSERT(!upb_Array_IsFrozen(arr));
4512
4713
  UPB_ASSERT(arena);
4513
4714
  UPB_ASSERT(i <= arr->UPB_PRIVATE(size));
4514
4715
  UPB_ASSERT(count + arr->UPB_PRIVATE(size) >= count);
@@ -4526,6 +4727,7 @@ bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count,
4526
4727
  * |------------|XXXXXXXX|--------|
4527
4728
  */
4528
4729
  void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) {
4730
+ UPB_ASSERT(!upb_Array_IsFrozen(arr));
4529
4731
  const size_t end = i + count;
4530
4732
  UPB_ASSERT(i <= end);
4531
4733
  UPB_ASSERT(end <= arr->UPB_PRIVATE(size));
@@ -4534,6 +4736,7 @@ void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) {
4534
4736
  }
4535
4737
 
4536
4738
  bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) {
4739
+ UPB_ASSERT(!upb_Array_IsFrozen(arr));
4537
4740
  const size_t oldsize = arr->UPB_PRIVATE(size);
4538
4741
  if (UPB_UNLIKELY(
4539
4742
  !UPB_PRIVATE(_upb_Array_ResizeUninitialized)(arr, size, arena))) {
@@ -4567,6 +4770,20 @@ bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity,
4567
4770
  return true;
4568
4771
  }
4569
4772
 
4773
+ void upb_Array_Freeze(upb_Array* arr, const upb_MiniTable* m) {
4774
+ if (upb_Array_IsFrozen(arr)) return;
4775
+ UPB_PRIVATE(_upb_Array_ShallowFreeze)(arr);
4776
+
4777
+ if (m) {
4778
+ const size_t size = upb_Array_Size(arr);
4779
+
4780
+ for (size_t i = 0; i < size; i++) {
4781
+ upb_MessageValue val = upb_Array_Get(arr, i);
4782
+ upb_Message_Freeze((upb_Message*)val.msg_val, m);
4783
+ }
4784
+ }
4785
+ }
4786
+
4570
4787
 
4571
4788
  #include <stddef.h>
4572
4789
  #include <stdint.h>
@@ -4583,19 +4800,20 @@ const upb_MiniTableExtension* upb_Message_ExtensionByIndex(
4583
4800
  return ext[index].ext;
4584
4801
  }
4585
4802
 
4586
- const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg,
4587
- uint32_t field_number) {
4803
+ const upb_MiniTableExtension* upb_Message_FindExtensionByNumber(
4804
+ const upb_Message* msg, uint32_t field_number) {
4588
4805
  size_t count;
4589
4806
  const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count);
4590
4807
 
4591
- while (count--) {
4592
- if (upb_MiniTableExtension_Number(ext->ext) == field_number) return ext;
4593
- ext++;
4808
+ for (; count--; ext++) {
4809
+ const upb_MiniTableExtension* e = ext->ext;
4810
+ if (upb_MiniTableExtension_Number(e) == field_number) return e;
4594
4811
  }
4595
4812
  return NULL;
4596
4813
  }
4597
4814
 
4598
4815
 
4816
+ #include <stdint.h>
4599
4817
  #include <string.h>
4600
4818
 
4601
4819
 
@@ -4694,6 +4912,20 @@ upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter) {
4694
4912
  return ret;
4695
4913
  }
4696
4914
 
4915
+ void upb_Map_Freeze(upb_Map* map, const upb_MiniTable* m) {
4916
+ if (upb_Map_IsFrozen(map)) return;
4917
+ UPB_PRIVATE(_upb_Map_ShallowFreeze)(map);
4918
+
4919
+ if (m) {
4920
+ size_t iter = kUpb_Map_Begin;
4921
+ upb_MessageValue key, val;
4922
+
4923
+ while (upb_Map_Next(map, &key, &val, &iter)) {
4924
+ upb_Message_Freeze((upb_Message*)val.msg_val, m);
4925
+ }
4926
+ }
4927
+ }
4928
+
4697
4929
  // EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE /////////////////////////
4698
4930
 
4699
4931
  upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) {
@@ -4703,6 +4935,7 @@ upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) {
4703
4935
  upb_strtable_init(&map->table, 4, a);
4704
4936
  map->key_size = key_size;
4705
4937
  map->val_size = value_size;
4938
+ map->UPB_PRIVATE(is_frozen) = false;
4706
4939
 
4707
4940
  return map;
4708
4941
  }
@@ -4866,22 +5099,24 @@ upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* a) {
4866
5099
 
4867
5100
  bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data,
4868
5101
  size_t len, upb_Arena* arena) {
5102
+ UPB_ASSERT(!upb_Message_IsFrozen(msg));
4869
5103
  if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, len, arena)) return false;
4870
- upb_Message_Internal* in = msg->internal;
5104
+ upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
4871
5105
  memcpy(UPB_PTR_AT(in, in->unknown_end, char), data, len);
4872
5106
  in->unknown_end += len;
4873
5107
  return true;
4874
5108
  }
4875
5109
 
4876
5110
  void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) {
4877
- upb_Message_Internal* in = msg->internal;
5111
+ UPB_ASSERT(!upb_Message_IsFrozen(msg));
5112
+ upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
4878
5113
  if (in) {
4879
5114
  in->unknown_end = message_overhead;
4880
5115
  }
4881
5116
  }
4882
5117
 
4883
5118
  const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) {
4884
- upb_Message_Internal* in = msg->internal;
5119
+ upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
4885
5120
  if (in) {
4886
5121
  *len = in->unknown_end - message_overhead;
4887
5122
  return (char*)(in + 1);
@@ -4892,7 +5127,8 @@ const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) {
4892
5127
  }
4893
5128
 
4894
5129
  void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) {
4895
- upb_Message_Internal* in = msg->internal;
5130
+ UPB_ASSERT(!upb_Message_IsFrozen(msg));
5131
+ upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
4896
5132
  const char* internal_unknown_end = UPB_PTR_AT(in, in->unknown_end, char);
4897
5133
 
4898
5134
  #ifndef NDEBUG
@@ -4916,35 +5152,296 @@ size_t upb_Message_ExtensionCount(const upb_Message* msg) {
4916
5152
  return count;
4917
5153
  }
4918
5154
 
5155
+ void upb_Message_Freeze(upb_Message* msg, const upb_MiniTable* m) {
5156
+ if (upb_Message_IsFrozen(msg)) return;
5157
+ UPB_PRIVATE(_upb_Message_ShallowFreeze)(msg);
5158
+
5159
+ // Base Fields.
5160
+ const size_t field_count = upb_MiniTable_FieldCount(m);
5161
+
5162
+ for (size_t i = 0; i < field_count; i++) {
5163
+ const upb_MiniTableField* f = upb_MiniTable_GetFieldByIndex(m, i);
5164
+ const upb_MiniTable* m2 = upb_MiniTable_SubMessage(m, f);
5165
+
5166
+ switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(f)) {
5167
+ case kUpb_FieldMode_Array: {
5168
+ upb_Array* arr = upb_Message_GetMutableArray(msg, f);
5169
+ if (arr) upb_Array_Freeze(arr, m2);
5170
+ break;
5171
+ }
5172
+ case kUpb_FieldMode_Map: {
5173
+ upb_Map* map = upb_Message_GetMutableMap(msg, f);
5174
+ if (map) {
5175
+ const upb_MiniTableField* f2 = upb_MiniTable_MapValue(m2);
5176
+ const upb_MiniTable* m3 = upb_MiniTable_SubMessage(m2, f2);
5177
+ upb_Map_Freeze(map, m3);
5178
+ }
5179
+ break;
5180
+ }
5181
+ case kUpb_FieldMode_Scalar: {
5182
+ if (m2) {
5183
+ upb_Message* msg2 = upb_Message_GetMutableMessage(msg, f);
5184
+ if (msg2) upb_Message_Freeze(msg2, m2);
5185
+ }
5186
+ break;
5187
+ }
5188
+ }
5189
+ }
5190
+
5191
+ // Extensions.
5192
+ size_t ext_count;
5193
+ const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &ext_count);
5194
+
5195
+ for (size_t i = 0; i < ext_count; i++) {
5196
+ const upb_MiniTableExtension* e = ext[i].ext;
5197
+ const upb_MiniTableField* f = &e->UPB_PRIVATE(field);
5198
+ const upb_MiniTable* m2 = upb_MiniTableExtension_GetSubMessage(e);
5199
+
5200
+ upb_MessageValue val;
5201
+ memcpy(&val, &ext[i].data, sizeof(upb_MessageValue));
5202
+
5203
+ switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(f)) {
5204
+ case kUpb_FieldMode_Array: {
5205
+ upb_Array* arr = (upb_Array*)val.array_val;
5206
+ if (arr) upb_Array_Freeze(arr, m2);
5207
+ break;
5208
+ }
5209
+ case kUpb_FieldMode_Map:
5210
+ UPB_UNREACHABLE(); // Maps cannot be extensions.
5211
+ break;
5212
+ case kUpb_FieldMode_Scalar:
5213
+ if (upb_MiniTableField_IsSubMessage(f)) {
5214
+ upb_Message* msg2 = (upb_Message*)val.msg_val;
5215
+ if (msg2) upb_Message_Freeze(msg2, m2);
5216
+ }
5217
+ break;
5218
+ }
5219
+ }
5220
+ }
4919
5221
 
4920
- #include <string.h>
5222
+
5223
+ #include <stddef.h>
4921
5224
 
4922
5225
 
4923
5226
  // Must be last.
4924
5227
 
4925
- bool upb_Message_IsExactlyEqual(const upb_Message* msg1,
4926
- const upb_Message* msg2,
4927
- const upb_MiniTable* m) {
4928
- if (msg1 == msg2) return true;
5228
+ #define kUpb_BaseField_Begin ((size_t)-1)
5229
+ #define kUpb_Extension_Begin ((size_t)-1)
5230
+
5231
+ #ifdef __cplusplus
5232
+ extern "C" {
5233
+ #endif
5234
+
5235
+ static bool _upb_Message_NextBaseField(const upb_Message* msg,
5236
+ const upb_MiniTable* m,
5237
+ const upb_MiniTableField** out_f,
5238
+ upb_MessageValue* out_v, size_t* iter) {
5239
+ const size_t count = upb_MiniTable_FieldCount(m);
5240
+ size_t i = *iter;
5241
+
5242
+ while (++i < count) {
5243
+ const upb_MiniTableField* f = upb_MiniTable_GetFieldByIndex(m, i);
5244
+ const void* src = UPB_PRIVATE(_upb_Message_DataPtr)(msg, f);
5245
+
5246
+ upb_MessageValue val;
5247
+ UPB_PRIVATE(_upb_MiniTableField_DataCopy)(f, &val, src);
5248
+
5249
+ // Skip field if unset or empty.
5250
+ if (upb_MiniTableField_HasPresence(f)) {
5251
+ if (!upb_Message_HasBaseField(msg, f)) continue;
5252
+ } else {
5253
+ if (UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(f, src)) continue;
5254
+
5255
+ if (upb_MiniTableField_IsArray(f)) {
5256
+ if (upb_Array_Size(val.array_val) == 0) continue;
5257
+ } else if (upb_MiniTableField_IsMap(f)) {
5258
+ if (upb_Map_Size(val.map_val) == 0) continue;
5259
+ }
5260
+ }
5261
+
5262
+ *out_f = f;
5263
+ *out_v = val;
5264
+ *iter = i;
5265
+ return true;
5266
+ }
5267
+
5268
+ return false;
5269
+ }
4929
5270
 
4930
- int opts = kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic;
4931
- upb_Arena* a = upb_Arena_New();
5271
+ static bool _upb_Message_NextExtension(const upb_Message* msg,
5272
+ const upb_MiniTable* m,
5273
+ const upb_MiniTableExtension** out_e,
5274
+ upb_MessageValue* out_v, size_t* iter) {
5275
+ size_t count;
5276
+ const upb_Extension* exts = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count);
5277
+ size_t i = *iter;
4932
5278
 
4933
- // Compare deterministically serialized payloads with no unknown fields.
4934
- size_t size1, size2;
4935
- char *data1, *data2;
4936
- upb_EncodeStatus status1 = upb_Encode(msg1, m, opts, a, &data1, &size1);
4937
- upb_EncodeStatus status2 = upb_Encode(msg2, m, opts, a, &data2, &size2);
5279
+ if (++i < count) {
5280
+ *out_e = exts[i].ext;
5281
+ *out_v = exts[i].data;
5282
+ *iter = i;
5283
+ return true;
5284
+ }
5285
+
5286
+ return false;
5287
+ }
5288
+
5289
+ bool upb_Message_IsEmpty(const upb_Message* msg, const upb_MiniTable* m) {
5290
+ if (upb_Message_ExtensionCount(msg)) return false;
4938
5291
 
4939
- if (status1 != kUpb_EncodeStatus_Ok || status2 != kUpb_EncodeStatus_Ok) {
4940
- // TODO: How should we fail here? (In Ruby we throw an exception.)
4941
- upb_Arena_Free(a);
5292
+ const upb_MiniTableField* f;
5293
+ upb_MessageValue v;
5294
+ size_t iter = kUpb_BaseField_Begin;
5295
+ return !_upb_Message_NextBaseField(msg, m, &f, &v, &iter);
5296
+ }
5297
+
5298
+ static bool _upb_Array_IsEqual(const upb_Array* arr1, const upb_Array* arr2,
5299
+ upb_CType ctype, const upb_MiniTable* m,
5300
+ int options) {
5301
+ // Check for trivial equality.
5302
+ if (arr1 == arr2) return true;
5303
+
5304
+ // Must have identical element counts.
5305
+ const size_t size1 = arr1 ? upb_Array_Size(arr1) : 0;
5306
+ const size_t size2 = arr2 ? upb_Array_Size(arr2) : 0;
5307
+ if (size1 != size2) return false;
5308
+
5309
+ for (size_t i = 0; i < size1; i++) {
5310
+ const upb_MessageValue val1 = upb_Array_Get(arr1, i);
5311
+ const upb_MessageValue val2 = upb_Array_Get(arr2, i);
5312
+
5313
+ if (!upb_MessageValue_IsEqual(val1, val2, ctype, m, options)) return false;
5314
+ }
5315
+
5316
+ return true;
5317
+ }
5318
+
5319
+ static bool _upb_Map_IsEqual(const upb_Map* map1, const upb_Map* map2,
5320
+ const upb_MiniTable* m, int options) {
5321
+ // Check for trivial equality.
5322
+ if (map1 == map2) return true;
5323
+
5324
+ // Must have identical element counts.
5325
+ size_t size1 = map1 ? upb_Map_Size(map1) : 0;
5326
+ size_t size2 = map2 ? upb_Map_Size(map2) : 0;
5327
+ if (size1 != size2) return false;
5328
+
5329
+ const upb_MiniTableField* f = upb_MiniTable_MapValue(m);
5330
+ const upb_MiniTable* m2_value = upb_MiniTable_SubMessage(m, f);
5331
+ const upb_CType ctype = upb_MiniTableField_CType(f);
5332
+
5333
+ upb_MessageValue key, val1, val2;
5334
+ size_t iter = kUpb_Map_Begin;
5335
+ while (upb_Map_Next(map1, &key, &val1, &iter)) {
5336
+ if (!upb_Map_Get(map2, key, &val2)) return false;
5337
+ if (!upb_MessageValue_IsEqual(val1, val2, ctype, m2_value, options))
5338
+ return false;
5339
+ }
5340
+
5341
+ return true;
5342
+ }
5343
+
5344
+ static bool _upb_Message_BaseFieldsAreEqual(const upb_Message* msg1,
5345
+ const upb_Message* msg2,
5346
+ const upb_MiniTable* m,
5347
+ int options) {
5348
+ // Iterate over all base fields for each message.
5349
+ // The order will always match if the messages are equal.
5350
+ size_t iter1 = kUpb_BaseField_Begin;
5351
+ size_t iter2 = kUpb_BaseField_Begin;
5352
+
5353
+ for (;;) {
5354
+ const upb_MiniTableField *f1, *f2;
5355
+ upb_MessageValue val1, val2;
5356
+
5357
+ const bool got1 = _upb_Message_NextBaseField(msg1, m, &f1, &val1, &iter1);
5358
+ const bool got2 = _upb_Message_NextBaseField(msg2, m, &f2, &val2, &iter2);
5359
+
5360
+ if (got1 != got2) return false; // Must have identical field counts.
5361
+ if (!got1) return true; // Loop termination condition.
5362
+ if (f1 != f2) return false; // Must have identical fields set.
5363
+
5364
+ const upb_MiniTable* subm = upb_MiniTable_SubMessage(m, f1);
5365
+ const upb_CType ctype = upb_MiniTableField_CType(f1);
5366
+
5367
+ bool eq;
5368
+ switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(f1)) {
5369
+ case kUpb_FieldMode_Array:
5370
+ eq = _upb_Array_IsEqual(val1.array_val, val2.array_val, ctype, subm,
5371
+ options);
5372
+ break;
5373
+ case kUpb_FieldMode_Map:
5374
+ eq = _upb_Map_IsEqual(val1.map_val, val2.map_val, subm, options);
5375
+ break;
5376
+ case kUpb_FieldMode_Scalar:
5377
+ eq = upb_MessageValue_IsEqual(val1, val2, ctype, subm, options);
5378
+ break;
5379
+ }
5380
+ if (!eq) return false;
5381
+ }
5382
+ }
5383
+
5384
+ static bool _upb_Message_ExtensionsAreEqual(const upb_Message* msg1,
5385
+ const upb_Message* msg2,
5386
+ const upb_MiniTable* m,
5387
+ int options) {
5388
+ // Must have identical extension counts.
5389
+ if (upb_Message_ExtensionCount(msg1) != upb_Message_ExtensionCount(msg2)) {
4942
5390
  return false;
4943
5391
  }
4944
5392
 
4945
- const bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0);
4946
- upb_Arena_Free(a);
4947
- return ret;
5393
+ const upb_MiniTableExtension* e;
5394
+ upb_MessageValue val1;
5395
+
5396
+ // Iterate over all extensions for msg1, and search msg2 for each extension.
5397
+ size_t iter1 = kUpb_Extension_Begin;
5398
+ while (_upb_Message_NextExtension(msg1, m, &e, &val1, &iter1)) {
5399
+ const upb_Extension* ext2 = UPB_PRIVATE(_upb_Message_Getext)(msg2, e);
5400
+ if (!ext2) return false;
5401
+
5402
+ const upb_MessageValue val2 = ext2->data;
5403
+ const upb_MiniTableField* f = &e->UPB_PRIVATE(field);
5404
+ const upb_MiniTable* subm = upb_MiniTableField_IsSubMessage(f)
5405
+ ? upb_MiniTableExtension_GetSubMessage(e)
5406
+ : NULL;
5407
+ const upb_CType ctype = upb_MiniTableField_CType(f);
5408
+
5409
+ bool eq;
5410
+ switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(f)) {
5411
+ case kUpb_FieldMode_Array:
5412
+ eq = _upb_Array_IsEqual(val1.array_val, val2.array_val, ctype, subm,
5413
+ options);
5414
+ break;
5415
+ case kUpb_FieldMode_Map:
5416
+ UPB_UNREACHABLE(); // Maps cannot be extensions.
5417
+ break;
5418
+ case kUpb_FieldMode_Scalar: {
5419
+ eq = upb_MessageValue_IsEqual(val1, val2, ctype, subm, options);
5420
+ break;
5421
+ }
5422
+ }
5423
+ if (!eq) return false;
5424
+ }
5425
+ return true;
5426
+ }
5427
+
5428
+ bool upb_Message_IsEqual(const upb_Message* msg1, const upb_Message* msg2,
5429
+ const upb_MiniTable* m, int options) {
5430
+ if (UPB_UNLIKELY(msg1 == msg2)) return true;
5431
+
5432
+ if (!_upb_Message_BaseFieldsAreEqual(msg1, msg2, m, options)) return false;
5433
+ if (!_upb_Message_ExtensionsAreEqual(msg1, msg2, m, options)) return false;
5434
+
5435
+ if (!(options & kUpb_CompareOption_IncludeUnknownFields)) return true;
5436
+
5437
+ // Check the unknown fields.
5438
+ size_t usize1, usize2;
5439
+ const char* uf1 = upb_Message_GetUnknown(msg1, &usize1);
5440
+ const char* uf2 = upb_Message_GetUnknown(msg2, &usize2);
5441
+
5442
+ // The wire encoder enforces a maximum depth of 100 so we match that here.
5443
+ return UPB_PRIVATE(_upb_Message_UnknownFieldsAreEqual)(
5444
+ uf1, usize1, uf2, usize2, 100) == kUpb_UnknownCompareResult_Equal;
4948
5445
  }
4949
5446
 
4950
5447
 
@@ -5018,7 +5515,7 @@ upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type,
5018
5515
  size_t iter = kUpb_Map_Begin;
5019
5516
  while (upb_Map_Next(map, &key, &val, &iter)) {
5020
5517
  const upb_MiniTableField* value_field =
5021
- &map_entry_table->UPB_PRIVATE(fields)[1];
5518
+ upb_MiniTable_MapValue(map_entry_table);
5022
5519
  const upb_MiniTable* value_sub =
5023
5520
  upb_MiniTableField_CType(value_field) == kUpb_CType_Message
5024
5521
  ? upb_MiniTable_GetSubMessageTable(map_entry_table, value_field)
@@ -5044,10 +5541,9 @@ static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map,
5044
5541
  mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]);
5045
5542
  UPB_ASSERT(map_entry_table);
5046
5543
 
5047
- const upb_MiniTableField* key_field =
5048
- &map_entry_table->UPB_PRIVATE(fields)[0];
5544
+ const upb_MiniTableField* key_field = upb_MiniTable_MapKey(map_entry_table);
5049
5545
  const upb_MiniTableField* value_field =
5050
- &map_entry_table->UPB_PRIVATE(fields)[1];
5546
+ upb_MiniTable_MapValue(map_entry_table);
5051
5547
 
5052
5548
  upb_Map* cloned_map = upb_Map_DeepClone(
5053
5549
  map, upb_MiniTableField_CType(key_field),
@@ -5055,13 +5551,13 @@ static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map,
5055
5551
  if (!cloned_map) {
5056
5552
  return NULL;
5057
5553
  }
5058
- _upb_Message_SetNonExtensionField(clone, f, &cloned_map);
5554
+ upb_Message_SetBaseField(clone, f, &cloned_map);
5059
5555
  return cloned_map;
5060
5556
  }
5061
5557
 
5062
5558
  upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type,
5063
5559
  const upb_MiniTable* sub, upb_Arena* arena) {
5064
- const size_t size = array->UPB_PRIVATE(size);
5560
+ const size_t size = upb_Array_Size(array);
5065
5561
  const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(value_type);
5066
5562
  upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, lg2);
5067
5563
  if (!cloned_array) {
@@ -5093,7 +5589,7 @@ static bool upb_Message_Array_DeepClone(const upb_Array* array,
5093
5589
  arena);
5094
5590
 
5095
5591
  // Clear out upb_Array* due to parent memcpy.
5096
- _upb_Message_SetNonExtensionField(clone, field, &cloned_array);
5592
+ upb_Message_SetBaseField(clone, field, &cloned_array);
5097
5593
  return true;
5098
5594
  }
5099
5595
 
@@ -5102,8 +5598,7 @@ static bool upb_Clone_ExtensionValue(
5102
5598
  upb_Extension* dest, upb_Arena* arena) {
5103
5599
  dest->data = source->data;
5104
5600
  return upb_Clone_MessageValue(
5105
- &dest->data,
5106
- upb_MiniTableField_CType(&mini_table_ext->UPB_PRIVATE(field)),
5601
+ &dest->data, upb_MiniTableExtension_CType(mini_table_ext),
5107
5602
  upb_MiniTableExtension_GetSubMessage(mini_table_ext), arena);
5108
5603
  }
5109
5604
 
@@ -5113,8 +5608,9 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
5113
5608
  upb_StringView empty_string = upb_StringView_FromDataAndSize(NULL, 0);
5114
5609
  // Only copy message area skipping upb_Message_Internal.
5115
5610
  memcpy(dst + 1, src + 1, mini_table->UPB_PRIVATE(size) - sizeof(upb_Message));
5116
- for (size_t i = 0; i < mini_table->UPB_PRIVATE(field_count); ++i) {
5117
- const upb_MiniTableField* field = &mini_table->UPB_PRIVATE(fields)[i];
5611
+ for (int i = 0; i < upb_MiniTable_FieldCount(mini_table); ++i) {
5612
+ const upb_MiniTableField* field =
5613
+ upb_MiniTable_GetFieldByIndex(mini_table, i);
5118
5614
  if (upb_MiniTableField_IsScalar(field)) {
5119
5615
  switch (upb_MiniTableField_CType(field)) {
5120
5616
  case kUpb_CType_Message: {
@@ -5188,7 +5684,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
5188
5684
  return NULL;
5189
5685
  }
5190
5686
  } else {
5191
- upb_Array* msg_array = (upb_Array*)msg_ext->data.ptr;
5687
+ upb_Array* msg_array = (upb_Array*)msg_ext->data.array_val;
5192
5688
  UPB_ASSERT(msg_array);
5193
5689
  upb_Array* cloned_array = upb_Array_DeepClone(
5194
5690
  msg_array, upb_MiniTableField_CType(field),
@@ -5196,7 +5692,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
5196
5692
  if (!cloned_array) {
5197
5693
  return NULL;
5198
5694
  }
5199
- dst_ext->data.ptr = (void*)cloned_array;
5695
+ dst_ext->data.array_val = cloned_array;
5200
5696
  }
5201
5697
  }
5202
5698
 
@@ -5348,9 +5844,9 @@ static upb_MiniTableEnum* upb_MtDecoder_BuildMiniTableEnum(
5348
5844
  return upb_MtDecoder_DoBuildMiniTableEnum(decoder, data, len);
5349
5845
  }
5350
5846
 
5351
- upb_MiniTableEnum* upb_MiniDescriptor_BuildEnum(const char* data, size_t len,
5352
- upb_Arena* arena,
5353
- upb_Status* status) {
5847
+ upb_MiniTableEnum* upb_MiniTableEnum_Build(const char* data, size_t len,
5848
+ upb_Arena* arena,
5849
+ upb_Status* status) {
5354
5850
  upb_MdEnumDecoder decoder = {
5355
5851
  .base =
5356
5852
  {
@@ -5391,7 +5887,7 @@ typedef enum {
5391
5887
  kUpb_LayoutItemType_Max = kUpb_LayoutItemType_Field,
5392
5888
  } upb_LayoutItemType;
5393
5889
 
5394
- #define kUpb_LayoutItem_IndexSentinel ((uint16_t)-1)
5890
+ #define kUpb_LayoutItem_IndexSentinel ((uint16_t) - 1)
5395
5891
 
5396
5892
  typedef struct {
5397
5893
  // Index of the corresponding field. When this is a oneof field, the field's
@@ -5588,6 +6084,12 @@ static void upb_MtDecoder_ModifyField(upb_MtDecoder* d,
5588
6084
  upb_MiniTableField_Number(field));
5589
6085
  }
5590
6086
 
6087
+ if (singular && upb_MiniTableField_IsSubMessage(field)) {
6088
+ upb_MdDecoder_ErrorJmp(&d->base,
6089
+ "Field %" PRIu32 " cannot be a singular submessage",
6090
+ upb_MiniTableField_Number(field));
6091
+ }
6092
+
5591
6093
  if (singular) field->UPB_PRIVATE(offset) = kNoPresence;
5592
6094
  if (required) {
5593
6095
  field->UPB_PRIVATE(offset) = kRequiredPresence;
@@ -6074,6 +6576,11 @@ static upb_MiniTable* upb_MtDecoder_DoBuildMiniTableWithBuf(
6074
6576
  decoder->table->UPB_PRIVATE(dense_below) = 0;
6075
6577
  decoder->table->UPB_PRIVATE(table_mask) = -1;
6076
6578
  decoder->table->UPB_PRIVATE(required_count) = 0;
6579
+ #if UPB_TRACING_ENABLED
6580
+ // MiniTables built from MiniDescriptors will not be able to vend the message
6581
+ // name unless it is explicitly set with upb_MiniTable_SetFullName().
6582
+ decoder->table->UPB_PRIVATE(full_name) = 0;
6583
+ #endif
6077
6584
 
6078
6585
  // Strip off and verify the version tag.
6079
6586
  if (!len--) goto done;
@@ -6292,13 +6799,13 @@ bool upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTableField* field,
6292
6799
  return true;
6293
6800
  }
6294
6801
 
6295
- uint32_t upb_MiniTable_GetSubList(const upb_MiniTable* mt,
6802
+ uint32_t upb_MiniTable_GetSubList(const upb_MiniTable* m,
6296
6803
  const upb_MiniTableField** subs) {
6297
6804
  uint32_t msg_count = 0;
6298
6805
  uint32_t enum_count = 0;
6299
6806
 
6300
- for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) {
6301
- const upb_MiniTableField* f = &mt->UPB_PRIVATE(fields)[i];
6807
+ for (int i = 0; i < upb_MiniTable_FieldCount(m); i++) {
6808
+ const upb_MiniTableField* f = upb_MiniTable_GetFieldByIndex(m, i);
6302
6809
  if (upb_MiniTableField_CType(f) == kUpb_CType_Message) {
6303
6810
  *subs = f;
6304
6811
  ++subs;
@@ -6306,9 +6813,9 @@ uint32_t upb_MiniTable_GetSubList(const upb_MiniTable* mt,
6306
6813
  }
6307
6814
  }
6308
6815
 
6309
- for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) {
6310
- const upb_MiniTableField* f = &mt->UPB_PRIVATE(fields)[i];
6311
- if (upb_MiniTableField_CType(f) == kUpb_CType_Enum) {
6816
+ for (int i = 0; i < upb_MiniTable_FieldCount(m); i++) {
6817
+ const upb_MiniTableField* f = upb_MiniTable_GetFieldByIndex(m, i);
6818
+ if (upb_MiniTableField_IsClosedEnum(f)) {
6312
6819
  *subs = f;
6313
6820
  ++subs;
6314
6821
  enum_count++;
@@ -6321,36 +6828,34 @@ uint32_t upb_MiniTable_GetSubList(const upb_MiniTable* mt,
6321
6828
  // The list of sub_tables and sub_enums must exactly match the number and order
6322
6829
  // of sub-message fields and sub-enum fields given by upb_MiniTable_GetSubList()
6323
6830
  // above.
6324
- bool upb_MiniTable_Link(upb_MiniTable* mt, const upb_MiniTable** sub_tables,
6831
+ bool upb_MiniTable_Link(upb_MiniTable* m, const upb_MiniTable** sub_tables,
6325
6832
  size_t sub_table_count,
6326
6833
  const upb_MiniTableEnum** sub_enums,
6327
6834
  size_t sub_enum_count) {
6328
6835
  uint32_t msg_count = 0;
6329
6836
  uint32_t enum_count = 0;
6330
6837
 
6331
- for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) {
6332
- upb_MiniTableField* f = (upb_MiniTableField*)&mt->UPB_PRIVATE(fields)[i];
6838
+ for (int i = 0; i < upb_MiniTable_FieldCount(m); i++) {
6839
+ upb_MiniTableField* f =
6840
+ (upb_MiniTableField*)upb_MiniTable_GetFieldByIndex(m, i);
6333
6841
  if (upb_MiniTableField_CType(f) == kUpb_CType_Message) {
6334
6842
  const upb_MiniTable* sub = sub_tables[msg_count++];
6335
6843
  if (msg_count > sub_table_count) return false;
6336
- if (sub != NULL) {
6337
- if (!upb_MiniTable_SetSubMessage(mt, f, sub)) return false;
6338
- }
6844
+ if (sub && !upb_MiniTable_SetSubMessage(m, f, sub)) return false;
6339
6845
  }
6340
6846
  }
6341
6847
 
6342
- for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) {
6343
- upb_MiniTableField* f = (upb_MiniTableField*)&mt->UPB_PRIVATE(fields)[i];
6848
+ for (int i = 0; i < upb_MiniTable_FieldCount(m); i++) {
6849
+ upb_MiniTableField* f =
6850
+ (upb_MiniTableField*)upb_MiniTable_GetFieldByIndex(m, i);
6344
6851
  if (upb_MiniTableField_IsClosedEnum(f)) {
6345
6852
  const upb_MiniTableEnum* sub = sub_enums[enum_count++];
6346
6853
  if (enum_count > sub_enum_count) return false;
6347
- if (sub != NULL) {
6348
- if (!upb_MiniTable_SetSubEnum(mt, f, sub)) return false;
6349
- }
6854
+ if (sub && !upb_MiniTable_SetSubEnum(m, f, sub)) return false;
6350
6855
  }
6351
6856
  }
6352
6857
 
6353
- return true;
6858
+ return (msg_count == sub_table_count) && (enum_count == sub_enum_count);
6354
6859
  }
6355
6860
 
6356
6861
 
@@ -6705,8 +7210,7 @@ static _upb_DecodeLongVarintReturn _upb_Decoder_DecodeLongVarint(
6705
7210
  const char* ptr, uint64_t val) {
6706
7211
  _upb_DecodeLongVarintReturn ret = {NULL, 0};
6707
7212
  uint64_t byte;
6708
- int i;
6709
- for (i = 1; i < 10; i++) {
7213
+ for (int i = 1; i < 10; i++) {
6710
7214
  byte = (uint8_t)ptr[i];
6711
7215
  val += (byte - 1) << (i * 7);
6712
7216
  if (!(byte & 0x80)) {
@@ -6719,8 +7223,8 @@ static _upb_DecodeLongVarintReturn _upb_Decoder_DecodeLongVarint(
6719
7223
  }
6720
7224
 
6721
7225
  UPB_FORCEINLINE
6722
- static const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr,
6723
- uint64_t* val) {
7226
+ const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr,
7227
+ uint64_t* val) {
6724
7228
  uint64_t byte = (uint8_t)*ptr;
6725
7229
  if (UPB_LIKELY((byte & 0x80) == 0)) {
6726
7230
  *val = byte;
@@ -6734,8 +7238,8 @@ static const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr,
6734
7238
  }
6735
7239
 
6736
7240
  UPB_FORCEINLINE
6737
- static const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr,
6738
- uint32_t* val) {
7241
+ const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr,
7242
+ uint32_t* val) {
6739
7243
  uint64_t byte = (uint8_t)*ptr;
6740
7244
  if (UPB_LIKELY((byte & 0x80) == 0)) {
6741
7245
  *val = byte;
@@ -6752,8 +7256,8 @@ static const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr,
6752
7256
  }
6753
7257
 
6754
7258
  UPB_FORCEINLINE
6755
- static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr,
6756
- uint32_t* size) {
7259
+ const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr,
7260
+ uint32_t* size) {
6757
7261
  uint64_t size64;
6758
7262
  ptr = _upb_Decoder_DecodeVarint(d, ptr, &size64);
6759
7263
  if (size64 >= INT32_MAX ||
@@ -6855,11 +7359,10 @@ static const char* _upb_Decoder_ReadString(upb_Decoder* d, const char* ptr,
6855
7359
  }
6856
7360
 
6857
7361
  UPB_FORCEINLINE
6858
- static const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d,
6859
- const char* ptr,
6860
- upb_Message* submsg,
6861
- const upb_MiniTable* subl,
6862
- uint32_t expected_end_group) {
7362
+ const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d, const char* ptr,
7363
+ upb_Message* submsg,
7364
+ const upb_MiniTable* subl,
7365
+ uint32_t expected_end_group) {
6863
7366
  if (--d->depth < 0) {
6864
7367
  _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded);
6865
7368
  }
@@ -6872,9 +7375,11 @@ static const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d,
6872
7375
  }
6873
7376
 
6874
7377
  UPB_FORCEINLINE
6875
- static const char* _upb_Decoder_DecodeSubMessage(
6876
- upb_Decoder* d, const char* ptr, upb_Message* submsg,
6877
- const upb_MiniTableSub* subs, const upb_MiniTableField* field, int size) {
7378
+ const char* _upb_Decoder_DecodeSubMessage(upb_Decoder* d, const char* ptr,
7379
+ upb_Message* submsg,
7380
+ const upb_MiniTableSub* subs,
7381
+ const upb_MiniTableField* field,
7382
+ int size) {
6878
7383
  int saved_delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, size);
6879
7384
  const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field);
6880
7385
  UPB_ASSERT(subl);
@@ -6884,10 +7389,10 @@ static const char* _upb_Decoder_DecodeSubMessage(
6884
7389
  }
6885
7390
 
6886
7391
  UPB_FORCEINLINE
6887
- static const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr,
6888
- upb_Message* submsg,
6889
- const upb_MiniTable* subl,
6890
- uint32_t number) {
7392
+ const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr,
7393
+ upb_Message* submsg,
7394
+ const upb_MiniTable* subl,
7395
+ uint32_t number) {
6891
7396
  if (_upb_Decoder_IsDone(d, &ptr)) {
6892
7397
  _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
6893
7398
  }
@@ -6897,16 +7402,16 @@ static const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr,
6897
7402
  }
6898
7403
 
6899
7404
  UPB_FORCEINLINE
6900
- static const char* _upb_Decoder_DecodeUnknownGroup(upb_Decoder* d,
6901
- const char* ptr,
6902
- uint32_t number) {
7405
+ const char* _upb_Decoder_DecodeUnknownGroup(upb_Decoder* d, const char* ptr,
7406
+ uint32_t number) {
6903
7407
  return _upb_Decoder_DecodeGroup(d, ptr, NULL, NULL, number);
6904
7408
  }
6905
7409
 
6906
7410
  UPB_FORCEINLINE
6907
- static const char* _upb_Decoder_DecodeKnownGroup(
6908
- upb_Decoder* d, const char* ptr, upb_Message* submsg,
6909
- const upb_MiniTableSub* subs, const upb_MiniTableField* field) {
7411
+ const char* _upb_Decoder_DecodeKnownGroup(upb_Decoder* d, const char* ptr,
7412
+ upb_Message* submsg,
7413
+ const upb_MiniTableSub* subs,
7414
+ const upb_MiniTableField* field) {
6910
7415
  const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field);
6911
7416
  UPB_ASSERT(subl);
6912
7417
  return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl,
@@ -6936,10 +7441,9 @@ static void _upb_Decoder_AddUnknownVarints(upb_Decoder* d, upb_Message* msg,
6936
7441
  }
6937
7442
 
6938
7443
  UPB_FORCEINLINE
6939
- static bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr,
6940
- upb_Message* msg, const upb_MiniTableEnum* e,
6941
- const upb_MiniTableField* field,
6942
- wireval* val) {
7444
+ bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr, upb_Message* msg,
7445
+ const upb_MiniTableEnum* e,
7446
+ const upb_MiniTableField* field, wireval* val) {
6943
7447
  const uint32_t v = val->uint32_val;
6944
7448
 
6945
7449
  if (UPB_LIKELY(upb_MiniTableEnum_CheckValue(e, v))) return true;
@@ -6973,9 +7477,10 @@ static const char* _upb_Decoder_DecodeEnumArray(upb_Decoder* d, const char* ptr,
6973
7477
  }
6974
7478
 
6975
7479
  UPB_FORCEINLINE
6976
- static const char* _upb_Decoder_DecodeFixedPacked(
6977
- upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val,
6978
- const upb_MiniTableField* field, int lg2) {
7480
+ const char* _upb_Decoder_DecodeFixedPacked(upb_Decoder* d, const char* ptr,
7481
+ upb_Array* arr, wireval* val,
7482
+ const upb_MiniTableField* field,
7483
+ int lg2) {
6979
7484
  int mask = (1 << lg2) - 1;
6980
7485
  size_t count = val->size >> lg2;
6981
7486
  if ((val->size & mask) != 0) {
@@ -7010,9 +7515,10 @@ static const char* _upb_Decoder_DecodeFixedPacked(
7010
7515
  }
7011
7516
 
7012
7517
  UPB_FORCEINLINE
7013
- static const char* _upb_Decoder_DecodeVarintPacked(
7014
- upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val,
7015
- const upb_MiniTableField* field, int lg2) {
7518
+ const char* _upb_Decoder_DecodeVarintPacked(upb_Decoder* d, const char* ptr,
7519
+ upb_Array* arr, wireval* val,
7520
+ const upb_MiniTableField* field,
7521
+ int lg2) {
7016
7522
  int scale = 1 << lg2;
7017
7523
  int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size);
7018
7524
  char* out = UPB_PTR_AT(upb_Array_MutableDataPtr(arr),
@@ -7255,7 +7761,7 @@ static const char* _upb_Decoder_DecodeToSubMessage(
7255
7761
  // Set presence if necessary.
7256
7762
  if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(field)) {
7257
7763
  UPB_PRIVATE(_upb_Message_SetHasbit)(msg, field);
7258
- } else if (UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(field)) {
7764
+ } else if (upb_MiniTableField_IsInOneof(field)) {
7259
7765
  // Oneof case
7260
7766
  uint32_t* oneof_case = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, field);
7261
7767
  if (op == kUpb_DecodeOp_SubMessage &&
@@ -7318,9 +7824,8 @@ const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr,
7318
7824
  }
7319
7825
 
7320
7826
  UPB_FORCEINLINE
7321
- static bool _upb_Decoder_TryFastDispatch(upb_Decoder* d, const char** ptr,
7322
- upb_Message* msg,
7323
- const upb_MiniTable* m) {
7827
+ bool _upb_Decoder_TryFastDispatch(upb_Decoder* d, const char** ptr,
7828
+ upb_Message* msg, const upb_MiniTable* m) {
7324
7829
  #if UPB_FASTTABLE
7325
7830
  if (m && m->UPB_PRIVATE(table_mask) != (unsigned char)-1) {
7326
7831
  uint16_t tag = _upb_FastDecoder_LoadTag(*ptr);
@@ -7558,9 +8063,8 @@ static int _upb_Decoder_GetVarintOp(const upb_MiniTableField* field) {
7558
8063
  }
7559
8064
 
7560
8065
  UPB_FORCEINLINE
7561
- static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt,
7562
- const upb_MiniTableField* field,
7563
- int* op) {
8066
+ void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt,
8067
+ const upb_MiniTableField* field, int* op) {
7564
8068
  // If sub-message is not linked, treat as unknown.
7565
8069
  if (field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension) return;
7566
8070
  const upb_MiniTable* mt_sub =
@@ -7586,9 +8090,8 @@ static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt,
7586
8090
  }
7587
8091
 
7588
8092
  UPB_FORCEINLINE
7589
- static void _upb_Decoder_MaybeVerifyUtf8(upb_Decoder* d,
7590
- const upb_MiniTableField* field,
7591
- int* op) {
8093
+ void _upb_Decoder_MaybeVerifyUtf8(upb_Decoder* d,
8094
+ const upb_MiniTableField* field, int* op) {
7592
8095
  if ((field->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) &&
7593
8096
  UPB_UNLIKELY(d->options & kUpb_DecodeOption_AlwaysValidateUtf8))
7594
8097
  *op = kUpb_DecodeOp_String;
@@ -7658,11 +8161,10 @@ static int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt,
7658
8161
  }
7659
8162
 
7660
8163
  UPB_FORCEINLINE
7661
- static const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr,
7662
- const upb_MiniTable* mt,
7663
- const upb_MiniTableField* field,
7664
- int wire_type, wireval* val,
7665
- int* op) {
8164
+ const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr,
8165
+ const upb_MiniTable* mt,
8166
+ const upb_MiniTableField* field,
8167
+ int wire_type, wireval* val, int* op) {
7666
8168
  static const unsigned kFixed32OkMask = (1 << kUpb_FieldType_Float) |
7667
8169
  (1 << kUpb_FieldType_Fixed32) |
7668
8170
  (1 << kUpb_FieldType_SFixed32);
@@ -7712,10 +8214,11 @@ static const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr,
7712
8214
  }
7713
8215
 
7714
8216
  UPB_FORCEINLINE
7715
- static const char* _upb_Decoder_DecodeKnownField(
7716
- upb_Decoder* d, const char* ptr, upb_Message* msg,
7717
- const upb_MiniTable* layout, const upb_MiniTableField* field, int op,
7718
- wireval* val) {
8217
+ const char* _upb_Decoder_DecodeKnownField(upb_Decoder* d, const char* ptr,
8218
+ upb_Message* msg,
8219
+ const upb_MiniTable* layout,
8220
+ const upb_MiniTableField* field,
8221
+ int op, wireval* val) {
7719
8222
  const upb_MiniTableSub* subs = layout->UPB_PRIVATE(subs);
7720
8223
  uint8_t mode = field->UPB_PRIVATE(mode);
7721
8224
 
@@ -7921,9 +8424,10 @@ static upb_DecodeStatus upb_Decoder_Decode(upb_Decoder* const decoder,
7921
8424
  }
7922
8425
 
7923
8426
  upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg,
7924
- const upb_MiniTable* m,
8427
+ const upb_MiniTable* mt,
7925
8428
  const upb_ExtensionRegistry* extreg, int options,
7926
8429
  upb_Arena* arena) {
8430
+ UPB_ASSERT(!upb_Message_IsFrozen(msg));
7927
8431
  upb_Decoder decoder;
7928
8432
  unsigned depth = (unsigned)options >> 16;
7929
8433
 
@@ -7945,7 +8449,42 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg,
7945
8449
  // (particularly parent_or_count).
7946
8450
  UPB_PRIVATE(_upb_Arena_SwapIn)(&decoder.arena, arena);
7947
8451
 
7948
- return upb_Decoder_Decode(&decoder, buf, msg, m, arena);
8452
+ return upb_Decoder_Decode(&decoder, buf, msg, mt, arena);
8453
+ }
8454
+
8455
+ upb_DecodeStatus upb_DecodeLengthPrefixed(const char* buf, size_t size,
8456
+ upb_Message* msg,
8457
+ size_t* num_bytes_read,
8458
+ const upb_MiniTable* mt,
8459
+ const upb_ExtensionRegistry* extreg,
8460
+ int options, upb_Arena* arena) {
8461
+ // To avoid needing to make a Decoder just to decode the initial length,
8462
+ // hand-decode the leading varint for the message length here.
8463
+ uint64_t msg_len = 0;
8464
+ for (size_t i = 0;; ++i) {
8465
+ if (i >= size || i > 9) {
8466
+ return kUpb_DecodeStatus_Malformed;
8467
+ }
8468
+ uint64_t b = *buf;
8469
+ buf++;
8470
+ msg_len += (b & 0x7f) << (i * 7);
8471
+ if ((b & 0x80) == 0) {
8472
+ *num_bytes_read = i + 1 + msg_len;
8473
+ break;
8474
+ }
8475
+ }
8476
+
8477
+ // If the total number of bytes we would read (= the bytes from the varint
8478
+ // plus however many bytes that varint says we should read) is larger then the
8479
+ // input buffer then error as malformed.
8480
+ if (*num_bytes_read > size) {
8481
+ return kUpb_DecodeStatus_Malformed;
8482
+ }
8483
+ if (msg_len > INT32_MAX) {
8484
+ return kUpb_DecodeStatus_Malformed;
8485
+ }
8486
+
8487
+ return upb_Decode(buf, msg_len, msg, mt, extreg, options, arena);
7949
8488
  }
7950
8489
 
7951
8490
  #undef OP_FIXPCK_LG2
@@ -8032,7 +8571,7 @@ static void encode_growbuffer(upb_encstate* e, size_t bytes) {
8032
8571
  /* Call to ensure that at least "bytes" bytes are available for writing at
8033
8572
  * e->ptr. Returns false if the bytes could not be allocated. */
8034
8573
  UPB_FORCEINLINE
8035
- static void encode_reserve(upb_encstate* e, size_t bytes) {
8574
+ void encode_reserve(upb_encstate* e, size_t bytes) {
8036
8575
  if ((size_t)(e->ptr - e->buf) < bytes) {
8037
8576
  encode_growbuffer(e, bytes);
8038
8577
  return;
@@ -8071,7 +8610,7 @@ static void encode_longvarint(upb_encstate* e, uint64_t val) {
8071
8610
  }
8072
8611
 
8073
8612
  UPB_FORCEINLINE
8074
- static void encode_varint(upb_encstate* e, uint64_t val) {
8613
+ void encode_varint(upb_encstate* e, uint64_t val) {
8075
8614
  if (val < 128 && e->ptr != e->buf) {
8076
8615
  --e->ptr;
8077
8616
  *e->ptr = val;
@@ -8101,7 +8640,7 @@ static void encode_tag(upb_encstate* e, uint32_t field_number,
8101
8640
 
8102
8641
  static void encode_fixedarray(upb_encstate* e, const upb_Array* arr,
8103
8642
  size_t elem_size, uint32_t tag) {
8104
- size_t bytes = arr->UPB_PRIVATE(size) * elem_size;
8643
+ size_t bytes = upb_Array_Size(arr) * elem_size;
8105
8644
  const char* data = upb_Array_DataPtr(arr);
8106
8645
  const char* ptr = data + bytes - elem_size;
8107
8646
 
@@ -8198,7 +8737,7 @@ static void encode_scalar(upb_encstate* e, const void* _field_mem,
8198
8737
  return;
8199
8738
  }
8200
8739
  if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded);
8201
- encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup);
8740
+ encode_tag(e, upb_MiniTableField_Number(f), kUpb_WireType_EndGroup);
8202
8741
  encode_TaggedMessagePtr(e, submsg, subm, &size);
8203
8742
  wire_type = kUpb_WireType_StartGroup;
8204
8743
  e->depth++;
@@ -8224,7 +8763,7 @@ static void encode_scalar(upb_encstate* e, const void* _field_mem,
8224
8763
  }
8225
8764
  #undef CASE
8226
8765
 
8227
- encode_tag(e, f->UPB_PRIVATE(number), wire_type);
8766
+ encode_tag(e, upb_MiniTableField_Number(f), wire_type);
8228
8767
  }
8229
8768
 
8230
8769
  static void encode_array(upb_encstate* e, const upb_Message* msg,
@@ -8234,14 +8773,14 @@ static void encode_array(upb_encstate* e, const upb_Message* msg,
8234
8773
  bool packed = upb_MiniTableField_IsPacked(f);
8235
8774
  size_t pre_len = e->limit - e->ptr;
8236
8775
 
8237
- if (arr == NULL || arr->UPB_PRIVATE(size) == 0) {
8776
+ if (arr == NULL || upb_Array_Size(arr) == 0) {
8238
8777
  return;
8239
8778
  }
8240
8779
 
8241
8780
  #define VARINT_CASE(ctype, encode) \
8242
8781
  { \
8243
8782
  const ctype* start = upb_Array_DataPtr(arr); \
8244
- const ctype* ptr = start + arr->UPB_PRIVATE(size); \
8783
+ const ctype* ptr = start + upb_Array_Size(arr); \
8245
8784
  uint32_t tag = \
8246
8785
  packed ? 0 : (f->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; \
8247
8786
  do { \
@@ -8286,34 +8825,34 @@ static void encode_array(upb_encstate* e, const upb_Message* msg,
8286
8825
  case kUpb_FieldType_String:
8287
8826
  case kUpb_FieldType_Bytes: {
8288
8827
  const upb_StringView* start = upb_Array_DataPtr(arr);
8289
- const upb_StringView* ptr = start + arr->UPB_PRIVATE(size);
8828
+ const upb_StringView* ptr = start + upb_Array_Size(arr);
8290
8829
  do {
8291
8830
  ptr--;
8292
8831
  encode_bytes(e, ptr->data, ptr->size);
8293
8832
  encode_varint(e, ptr->size);
8294
- encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited);
8833
+ encode_tag(e, upb_MiniTableField_Number(f), kUpb_WireType_Delimited);
8295
8834
  } while (ptr != start);
8296
8835
  return;
8297
8836
  }
8298
8837
  case kUpb_FieldType_Group: {
8299
8838
  const upb_TaggedMessagePtr* start = upb_Array_DataPtr(arr);
8300
- const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size);
8839
+ const upb_TaggedMessagePtr* ptr = start + upb_Array_Size(arr);
8301
8840
  const upb_MiniTable* subm =
8302
8841
  upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]);
8303
8842
  if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded);
8304
8843
  do {
8305
8844
  size_t size;
8306
8845
  ptr--;
8307
- encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup);
8846
+ encode_tag(e, upb_MiniTableField_Number(f), kUpb_WireType_EndGroup);
8308
8847
  encode_TaggedMessagePtr(e, *ptr, subm, &size);
8309
- encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_StartGroup);
8848
+ encode_tag(e, upb_MiniTableField_Number(f), kUpb_WireType_StartGroup);
8310
8849
  } while (ptr != start);
8311
8850
  e->depth++;
8312
8851
  return;
8313
8852
  }
8314
8853
  case kUpb_FieldType_Message: {
8315
8854
  const upb_TaggedMessagePtr* start = upb_Array_DataPtr(arr);
8316
- const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size);
8855
+ const upb_TaggedMessagePtr* ptr = start + upb_Array_Size(arr);
8317
8856
  const upb_MiniTable* subm =
8318
8857
  upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]);
8319
8858
  if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded);
@@ -8322,7 +8861,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg,
8322
8861
  ptr--;
8323
8862
  encode_TaggedMessagePtr(e, *ptr, subm, &size);
8324
8863
  encode_varint(e, size);
8325
- encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited);
8864
+ encode_tag(e, upb_MiniTableField_Number(f), kUpb_WireType_Delimited);
8326
8865
  } while (ptr != start);
8327
8866
  e->depth++;
8328
8867
  return;
@@ -8332,15 +8871,15 @@ static void encode_array(upb_encstate* e, const upb_Message* msg,
8332
8871
 
8333
8872
  if (packed) {
8334
8873
  encode_varint(e, e->limit - e->ptr - pre_len);
8335
- encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited);
8874
+ encode_tag(e, upb_MiniTableField_Number(f), kUpb_WireType_Delimited);
8336
8875
  }
8337
8876
  }
8338
8877
 
8339
8878
  static void encode_mapentry(upb_encstate* e, uint32_t number,
8340
8879
  const upb_MiniTable* layout,
8341
8880
  const upb_MapEntry* ent) {
8342
- const upb_MiniTableField* key_field = &layout->UPB_PRIVATE(fields)[0];
8343
- const upb_MiniTableField* val_field = &layout->UPB_PRIVATE(fields)[1];
8881
+ const upb_MiniTableField* key_field = upb_MiniTable_MapKey(layout);
8882
+ const upb_MiniTableField* val_field = upb_MiniTable_MapValue(layout);
8344
8883
  size_t pre_len = e->limit - e->ptr;
8345
8884
  size_t size;
8346
8885
  encode_scalar(e, &ent->v, layout->UPB_PRIVATE(subs), val_field);
@@ -8356,7 +8895,7 @@ static void encode_map(upb_encstate* e, const upb_Message* msg,
8356
8895
  const upb_Map* map = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), const upb_Map*);
8357
8896
  const upb_MiniTable* layout =
8358
8897
  upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]);
8359
- UPB_ASSERT(layout->UPB_PRIVATE(field_count) == 2);
8898
+ UPB_ASSERT(upb_MiniTable_FieldCount(layout) == 2);
8360
8899
 
8361
8900
  if (!map || !upb_Map_Size(map)) return;
8362
8901
 
@@ -8367,7 +8906,7 @@ static void encode_map(upb_encstate* e, const upb_Message* msg,
8367
8906
  map, &sorted);
8368
8907
  upb_MapEntry ent;
8369
8908
  while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) {
8370
- encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent);
8909
+ encode_mapentry(e, upb_MiniTableField_Number(f), layout, &ent);
8371
8910
  }
8372
8911
  _upb_mapsorter_popmap(&e->sorter, &sorted);
8373
8912
  } else {
@@ -8378,7 +8917,7 @@ static void encode_map(upb_encstate* e, const upb_Message* msg,
8378
8917
  upb_MapEntry ent;
8379
8918
  _upb_map_fromkey(key, &ent.k, map->key_size);
8380
8919
  _upb_map_fromvalue(val, &ent.v, map->val_size);
8381
- encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent);
8920
+ encode_mapentry(e, upb_MiniTableField_Number(f), layout, &ent);
8382
8921
  }
8383
8922
  }
8384
8923
  }
@@ -8418,7 +8957,7 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg,
8418
8957
  } else {
8419
8958
  // Field is in a oneof.
8420
8959
  return UPB_PRIVATE(_upb_Message_GetOneofCase)(msg, f) ==
8421
- f->UPB_PRIVATE(number);
8960
+ upb_MiniTableField_Number(f);
8422
8961
  }
8423
8962
  }
8424
8963
 
@@ -8444,7 +8983,7 @@ static void encode_field(upb_encstate* e, const upb_Message* msg,
8444
8983
  static void encode_msgset_item(upb_encstate* e, const upb_Extension* ext) {
8445
8984
  size_t size;
8446
8985
  encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_EndGroup);
8447
- encode_message(e, ext->data.ptr,
8986
+ encode_message(e, ext->data.msg_val,
8448
8987
  upb_MiniTableExtension_GetSubMessage(ext->ext), &size);
8449
8988
  encode_varint(e, size);
8450
8989
  encode_tag(e, kUpb_MsgSet_Message, kUpb_WireType_Delimited);
@@ -8508,7 +9047,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg,
8508
9047
  }
8509
9048
  }
8510
9049
 
8511
- if (m->UPB_PRIVATE(field_count)) {
9050
+ if (upb_MiniTable_FieldCount(m)) {
8512
9051
  const upb_MiniTableField* f =
8513
9052
  &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)];
8514
9053
  const upb_MiniTableField* first = &m->UPB_PRIVATE(fields)[0];
@@ -8526,14 +9065,18 @@ static void encode_message(upb_encstate* e, const upb_Message* msg,
8526
9065
  static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder,
8527
9066
  const upb_Message* const msg,
8528
9067
  const upb_MiniTable* const l,
8529
- char** const buf,
8530
- size_t* const size) {
9068
+ char** const buf, size_t* const size,
9069
+ bool prepend_len) {
8531
9070
  // Unfortunately we must continue to perform hackery here because there are
8532
9071
  // code paths which blindly copy the returned pointer without bothering to
8533
9072
  // check for errors until much later (b/235839510). So we still set *buf to
8534
9073
  // NULL on error and we still set it to non-NULL on a successful empty result.
8535
9074
  if (UPB_SETJMP(encoder->err) == 0) {
8536
- encode_message(encoder, msg, l, size);
9075
+ size_t encoded_msg_size;
9076
+ encode_message(encoder, msg, l, &encoded_msg_size);
9077
+ if (prepend_len) {
9078
+ encode_varint(encoder, encoded_msg_size);
9079
+ }
8537
9080
  *size = encoder->limit - encoder->ptr;
8538
9081
  if (*size == 0) {
8539
9082
  static char ch;
@@ -8552,9 +9095,10 @@ static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder,
8552
9095
  return encoder->status;
8553
9096
  }
8554
9097
 
8555
- upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l,
8556
- int options, upb_Arena* arena, char** buf,
8557
- size_t* size) {
9098
+ static upb_EncodeStatus _upb_Encode(const upb_Message* msg,
9099
+ const upb_MiniTable* l, int options,
9100
+ upb_Arena* arena, char** buf, size_t* size,
9101
+ bool prepend_len) {
8558
9102
  upb_encstate e;
8559
9103
  unsigned depth = (unsigned)options >> 16;
8560
9104
 
@@ -8567,7 +9111,20 @@ upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l,
8567
9111
  e.options = options;
8568
9112
  _upb_mapsorter_init(&e.sorter);
8569
9113
 
8570
- return upb_Encoder_Encode(&e, msg, l, buf, size);
9114
+ return upb_Encoder_Encode(&e, msg, l, buf, size, prepend_len);
9115
+ }
9116
+
9117
+ upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l,
9118
+ int options, upb_Arena* arena, char** buf,
9119
+ size_t* size) {
9120
+ return _upb_Encode(msg, l, options, arena, buf, size, false);
9121
+ }
9122
+
9123
+ upb_EncodeStatus upb_EncodeLengthPrefixed(const upb_Message* msg,
9124
+ const upb_MiniTable* l, int options,
9125
+ upb_Arena* arena, char** buf,
9126
+ size_t* size) {
9127
+ return _upb_Encode(msg, l, options, arena, buf, size, true);
8571
9128
  }
8572
9129
 
8573
9130
  // Fast decoder: ~3x the speed of decode.c, but requires x86-64/ARM64.
@@ -8617,7 +9174,7 @@ static const char* fastdecode_isdonefallback(UPB_PARSE_PARAMS) {
8617
9174
  }
8618
9175
 
8619
9176
  UPB_FORCEINLINE
8620
- static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) {
9177
+ const char* fastdecode_dispatch(UPB_PARSE_PARAMS) {
8621
9178
  int overrun;
8622
9179
  switch (upb_EpsCopyInputStream_IsDoneStatus(&d->input, ptr, &overrun)) {
8623
9180
  case kUpb_IsDoneStatus_Done:
@@ -8639,7 +9196,7 @@ static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) {
8639
9196
  }
8640
9197
 
8641
9198
  UPB_FORCEINLINE
8642
- static bool fastdecode_checktag(uint16_t data, int tagbytes) {
9199
+ bool fastdecode_checktag(uint16_t data, int tagbytes) {
8643
9200
  if (tagbytes == 1) {
8644
9201
  return (data & 0xff) == 0;
8645
9202
  } else {
@@ -8648,7 +9205,7 @@ static bool fastdecode_checktag(uint16_t data, int tagbytes) {
8648
9205
  }
8649
9206
 
8650
9207
  UPB_FORCEINLINE
8651
- static const char* fastdecode_longsize(const char* ptr, int* size) {
9208
+ const char* fastdecode_longsize(const char* ptr, int* size) {
8652
9209
  int i;
8653
9210
  UPB_ASSERT(*size & 0x80);
8654
9211
  *size &= 0xff;
@@ -8668,7 +9225,7 @@ static const char* fastdecode_longsize(const char* ptr, int* size) {
8668
9225
  }
8669
9226
 
8670
9227
  UPB_FORCEINLINE
8671
- static const char* fastdecode_delimited(
9228
+ const char* fastdecode_delimited(
8672
9229
  upb_Decoder* d, const char* ptr,
8673
9230
  upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) {
8674
9231
  ptr++;
@@ -8721,8 +9278,8 @@ typedef struct {
8721
9278
  } fastdecode_nextret;
8722
9279
 
8723
9280
  UPB_FORCEINLINE
8724
- static void* fastdecode_resizearr(upb_Decoder* d, void* dst,
8725
- fastdecode_arr* farr, int valbytes) {
9281
+ void* fastdecode_resizearr(upb_Decoder* d, void* dst, fastdecode_arr* farr,
9282
+ int valbytes) {
8726
9283
  if (UPB_UNLIKELY(dst == farr->end)) {
8727
9284
  size_t old_capacity = farr->arr->UPB_PRIVATE(capacity);
8728
9285
  size_t old_bytes = old_capacity * valbytes;
@@ -8740,7 +9297,7 @@ static void* fastdecode_resizearr(upb_Decoder* d, void* dst,
8740
9297
  }
8741
9298
 
8742
9299
  UPB_FORCEINLINE
8743
- static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) {
9300
+ bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) {
8744
9301
  if (tagbytes == 1) {
8745
9302
  return (uint8_t)tag == (uint8_t)data;
8746
9303
  } else {
@@ -8749,19 +9306,17 @@ static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) {
8749
9306
  }
8750
9307
 
8751
9308
  UPB_FORCEINLINE
8752
- static void fastdecode_commitarr(void* dst, fastdecode_arr* farr,
8753
- int valbytes) {
9309
+ void fastdecode_commitarr(void* dst, fastdecode_arr* farr, int valbytes) {
8754
9310
  farr->arr->UPB_PRIVATE(size) =
8755
9311
  (size_t)((char*)dst - (char*)upb_Array_MutableDataPtr(farr->arr)) /
8756
9312
  valbytes;
8757
9313
  }
8758
9314
 
8759
9315
  UPB_FORCEINLINE
8760
- static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst,
8761
- const char** ptr,
8762
- fastdecode_arr* farr,
8763
- uint64_t data, int tagbytes,
8764
- int valbytes) {
9316
+ fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst,
9317
+ const char** ptr,
9318
+ fastdecode_arr* farr, uint64_t data,
9319
+ int tagbytes, int valbytes) {
8765
9320
  fastdecode_nextret ret;
8766
9321
  dst = (char*)dst + valbytes;
8767
9322
 
@@ -8783,16 +9338,15 @@ static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst,
8783
9338
  }
8784
9339
 
8785
9340
  UPB_FORCEINLINE
8786
- static void* fastdecode_fieldmem(upb_Message* msg, uint64_t data) {
9341
+ void* fastdecode_fieldmem(upb_Message* msg, uint64_t data) {
8787
9342
  size_t ofs = data >> 48;
8788
9343
  return (char*)msg + ofs;
8789
9344
  }
8790
9345
 
8791
9346
  UPB_FORCEINLINE
8792
- static void* fastdecode_getfield(upb_Decoder* d, const char* ptr,
8793
- upb_Message* msg, uint64_t* data,
8794
- uint64_t* hasbits, fastdecode_arr* farr,
8795
- int valbytes, upb_card card) {
9347
+ void* fastdecode_getfield(upb_Decoder* d, const char* ptr, upb_Message* msg,
9348
+ uint64_t* data, uint64_t* hasbits,
9349
+ fastdecode_arr* farr, int valbytes, upb_card card) {
8796
9350
  switch (card) {
8797
9351
  case CARD_s: {
8798
9352
  uint8_t hasbit_index = *data >> 24;
@@ -8831,7 +9385,7 @@ static void* fastdecode_getfield(upb_Decoder* d, const char* ptr,
8831
9385
  }
8832
9386
 
8833
9387
  UPB_FORCEINLINE
8834
- static bool fastdecode_flippacked(uint64_t* data, int tagbytes) {
9388
+ bool fastdecode_flippacked(uint64_t* data, int tagbytes) {
8835
9389
  *data ^= (0x2 ^ 0x0); // Patch data to match packed wiretype.
8836
9390
  return fastdecode_checktag(*data, tagbytes);
8837
9391
  }
@@ -8847,7 +9401,7 @@ static bool fastdecode_flippacked(uint64_t* data, int tagbytes) {
8847
9401
  /* varint fields **************************************************************/
8848
9402
 
8849
9403
  UPB_FORCEINLINE
8850
- static uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) {
9404
+ uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) {
8851
9405
  if (valbytes == 1) {
8852
9406
  return val != 0;
8853
9407
  } else if (zigzag) {
@@ -8863,7 +9417,7 @@ static uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) {
8863
9417
  }
8864
9418
 
8865
9419
  UPB_FORCEINLINE
8866
- static const char* fastdecode_varint64(const char* ptr, uint64_t* val) {
9420
+ const char* fastdecode_varint64(const char* ptr, uint64_t* val) {
8867
9421
  ptr++;
8868
9422
  *val = (uint8_t)ptr[-1];
8869
9423
  if (UPB_UNLIKELY(*val & 0x80)) {
@@ -8938,8 +9492,8 @@ typedef struct {
8938
9492
  } fastdecode_varintdata;
8939
9493
 
8940
9494
  UPB_FORCEINLINE
8941
- static const char* fastdecode_topackedvarint(upb_EpsCopyInputStream* e,
8942
- const char* ptr, void* ctx) {
9495
+ const char* fastdecode_topackedvarint(upb_EpsCopyInputStream* e,
9496
+ const char* ptr, void* ctx) {
8943
9497
  upb_Decoder* d = (upb_Decoder*)e;
8944
9498
  fastdecode_varintdata* data = ctx;
8945
9499
  void* dst = data->dst;
@@ -9218,9 +9772,8 @@ static const char* fastdecode_longstring_noutf8(
9218
9772
  }
9219
9773
 
9220
9774
  UPB_FORCEINLINE
9221
- static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size,
9222
- int copy, char* data, size_t data_offset,
9223
- upb_StringView* dst) {
9775
+ void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, int copy,
9776
+ char* data, size_t data_offset, upb_StringView* dst) {
9224
9777
  d->arena.UPB_PRIVATE(ptr) += copy;
9225
9778
  dst->data = data + data_offset;
9226
9779
  UPB_UNPOISON_MEMORY_REGION(data, copy);
@@ -9451,8 +10004,8 @@ typedef struct {
9451
10004
  } fastdecode_submsgdata;
9452
10005
 
9453
10006
  UPB_FORCEINLINE
9454
- static const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e,
9455
- const char* ptr, void* ctx) {
10007
+ const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, const char* ptr,
10008
+ void* ctx) {
9456
10009
  upb_Decoder* d = (upb_Decoder*)e;
9457
10010
  fastdecode_submsgdata* submsg = ctx;
9458
10011
  ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0);
@@ -9570,8 +10123,7 @@ UPB_NOINLINE UPB_PRIVATE(_upb_WireReader_LongVarint)
9570
10123
  UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val) {
9571
10124
  UPB_PRIVATE(_upb_WireReader_LongVarint) ret = {NULL, 0};
9572
10125
  uint64_t byte;
9573
- int i;
9574
- for (i = 1; i < 10; i++) {
10126
+ for (int i = 1; i < 10; i++) {
9575
10127
  byte = (uint8_t)ptr[i];
9576
10128
  val += (byte - 1) << (i * 7);
9577
10129
  if (!(byte & 0x80)) {
@@ -10603,15 +11155,291 @@ int upb_Unicode_ToUTF8(uint32_t cp, char* out) {
10603
11155
  }
10604
11156
 
10605
11157
 
11158
+ #include <stdlib.h>
11159
+
11160
+
11161
+ // Must be last.
11162
+
11163
+ typedef struct upb_UnknownFields upb_UnknownFields;
11164
+
11165
+ typedef struct {
11166
+ uint32_t tag;
11167
+ union {
11168
+ uint64_t varint;
11169
+ uint64_t uint64;
11170
+ uint32_t uint32;
11171
+ upb_StringView delimited;
11172
+ upb_UnknownFields* group;
11173
+ } data;
11174
+ } upb_UnknownField;
11175
+
11176
+ struct upb_UnknownFields {
11177
+ size_t size;
11178
+ size_t capacity;
11179
+ upb_UnknownField* fields;
11180
+ };
11181
+
11182
+ typedef struct {
11183
+ upb_EpsCopyInputStream stream;
11184
+ upb_Arena* arena;
11185
+ upb_UnknownField* tmp;
11186
+ size_t tmp_size;
11187
+ int depth;
11188
+ upb_UnknownCompareResult status;
11189
+ jmp_buf err;
11190
+ } upb_UnknownField_Context;
11191
+
11192
+ UPB_NORETURN static void upb_UnknownFields_OutOfMemory(
11193
+ upb_UnknownField_Context* ctx) {
11194
+ ctx->status = kUpb_UnknownCompareResult_OutOfMemory;
11195
+ UPB_LONGJMP(ctx->err, 1);
11196
+ }
11197
+
11198
+ static void upb_UnknownFields_Grow(upb_UnknownField_Context* ctx,
11199
+ upb_UnknownField** base,
11200
+ upb_UnknownField** ptr,
11201
+ upb_UnknownField** end) {
11202
+ size_t old = (*ptr - *base);
11203
+ size_t new = UPB_MAX(4, old * 2);
11204
+
11205
+ *base = upb_Arena_Realloc(ctx->arena, *base, old * sizeof(**base),
11206
+ new * sizeof(**base));
11207
+ if (!*base) upb_UnknownFields_OutOfMemory(ctx);
11208
+
11209
+ *ptr = *base + old;
11210
+ *end = *base + new;
11211
+ }
11212
+
11213
+ // We have to implement our own sort here, since qsort() is not an in-order
11214
+ // sort. Here we use merge sort, the simplest in-order sort.
11215
+ static void upb_UnknownFields_Merge(upb_UnknownField* arr, size_t start,
11216
+ size_t mid, size_t end,
11217
+ upb_UnknownField* tmp) {
11218
+ memcpy(tmp, &arr[start], (end - start) * sizeof(*tmp));
11219
+
11220
+ upb_UnknownField* ptr1 = tmp;
11221
+ upb_UnknownField* end1 = &tmp[mid - start];
11222
+ upb_UnknownField* ptr2 = &tmp[mid - start];
11223
+ upb_UnknownField* end2 = &tmp[end - start];
11224
+ upb_UnknownField* out = &arr[start];
11225
+
11226
+ while (ptr1 < end1 && ptr2 < end2) {
11227
+ if (ptr1->tag <= ptr2->tag) {
11228
+ *out++ = *ptr1++;
11229
+ } else {
11230
+ *out++ = *ptr2++;
11231
+ }
11232
+ }
11233
+
11234
+ if (ptr1 < end1) {
11235
+ memcpy(out, ptr1, (end1 - ptr1) * sizeof(*out));
11236
+ } else if (ptr2 < end2) {
11237
+ memcpy(out, ptr1, (end2 - ptr2) * sizeof(*out));
11238
+ }
11239
+ }
11240
+
11241
+ static void upb_UnknownFields_SortRecursive(upb_UnknownField* arr, size_t start,
11242
+ size_t end, upb_UnknownField* tmp) {
11243
+ if (end - start > 1) {
11244
+ size_t mid = start + ((end - start) / 2);
11245
+ upb_UnknownFields_SortRecursive(arr, start, mid, tmp);
11246
+ upb_UnknownFields_SortRecursive(arr, mid, end, tmp);
11247
+ upb_UnknownFields_Merge(arr, start, mid, end, tmp);
11248
+ }
11249
+ }
11250
+
11251
+ static void upb_UnknownFields_Sort(upb_UnknownField_Context* ctx,
11252
+ upb_UnknownFields* fields) {
11253
+ if (ctx->tmp_size < fields->size) {
11254
+ const int oldsize = ctx->tmp_size * sizeof(*ctx->tmp);
11255
+ ctx->tmp_size = UPB_MAX(8, ctx->tmp_size);
11256
+ while (ctx->tmp_size < fields->size) ctx->tmp_size *= 2;
11257
+ const int newsize = ctx->tmp_size * sizeof(*ctx->tmp);
11258
+ ctx->tmp = upb_grealloc(ctx->tmp, oldsize, newsize);
11259
+ }
11260
+ upb_UnknownFields_SortRecursive(fields->fields, 0, fields->size, ctx->tmp);
11261
+ }
11262
+
11263
+ static upb_UnknownFields* upb_UnknownFields_DoBuild(
11264
+ upb_UnknownField_Context* ctx, const char** buf) {
11265
+ upb_UnknownField* arr_base = NULL;
11266
+ upb_UnknownField* arr_ptr = NULL;
11267
+ upb_UnknownField* arr_end = NULL;
11268
+ const char* ptr = *buf;
11269
+ uint32_t last_tag = 0;
11270
+ bool sorted = true;
11271
+ while (!upb_EpsCopyInputStream_IsDone(&ctx->stream, &ptr)) {
11272
+ uint32_t tag;
11273
+ ptr = upb_WireReader_ReadTag(ptr, &tag);
11274
+ UPB_ASSERT(tag <= UINT32_MAX);
11275
+ int wire_type = upb_WireReader_GetWireType(tag);
11276
+ if (wire_type == kUpb_WireType_EndGroup) break;
11277
+ if (tag < last_tag) sorted = false;
11278
+ last_tag = tag;
11279
+
11280
+ if (arr_ptr == arr_end) {
11281
+ upb_UnknownFields_Grow(ctx, &arr_base, &arr_ptr, &arr_end);
11282
+ }
11283
+ upb_UnknownField* field = arr_ptr;
11284
+ field->tag = tag;
11285
+ arr_ptr++;
11286
+
11287
+ switch (wire_type) {
11288
+ case kUpb_WireType_Varint:
11289
+ ptr = upb_WireReader_ReadVarint(ptr, &field->data.varint);
11290
+ break;
11291
+ case kUpb_WireType_64Bit:
11292
+ ptr = upb_WireReader_ReadFixed64(ptr, &field->data.uint64);
11293
+ break;
11294
+ case kUpb_WireType_32Bit:
11295
+ ptr = upb_WireReader_ReadFixed32(ptr, &field->data.uint32);
11296
+ break;
11297
+ case kUpb_WireType_Delimited: {
11298
+ int size;
11299
+ ptr = upb_WireReader_ReadSize(ptr, &size);
11300
+ const char* s_ptr = ptr;
11301
+ ptr = upb_EpsCopyInputStream_ReadStringAliased(&ctx->stream, &s_ptr,
11302
+ size);
11303
+ field->data.delimited.data = s_ptr;
11304
+ field->data.delimited.size = size;
11305
+ break;
11306
+ }
11307
+ case kUpb_WireType_StartGroup:
11308
+ if (--ctx->depth == 0) {
11309
+ ctx->status = kUpb_UnknownCompareResult_MaxDepthExceeded;
11310
+ UPB_LONGJMP(ctx->err, 1);
11311
+ }
11312
+ field->data.group = upb_UnknownFields_DoBuild(ctx, &ptr);
11313
+ ctx->depth++;
11314
+ break;
11315
+ default:
11316
+ UPB_UNREACHABLE();
11317
+ }
11318
+ }
11319
+
11320
+ *buf = ptr;
11321
+ upb_UnknownFields* ret = upb_Arena_Malloc(ctx->arena, sizeof(*ret));
11322
+ if (!ret) upb_UnknownFields_OutOfMemory(ctx);
11323
+ ret->fields = arr_base;
11324
+ ret->size = arr_ptr - arr_base;
11325
+ ret->capacity = arr_end - arr_base;
11326
+ if (!sorted) {
11327
+ upb_UnknownFields_Sort(ctx, ret);
11328
+ }
11329
+ return ret;
11330
+ }
11331
+
11332
+ // Builds a upb_UnknownFields data structure from the binary data in buf.
11333
+ static upb_UnknownFields* upb_UnknownFields_Build(upb_UnknownField_Context* ctx,
11334
+ const char* ptr,
11335
+ size_t size) {
11336
+ upb_EpsCopyInputStream_Init(&ctx->stream, &ptr, size, true);
11337
+ upb_UnknownFields* fields = upb_UnknownFields_DoBuild(ctx, &ptr);
11338
+ UPB_ASSERT(upb_EpsCopyInputStream_IsDone(&ctx->stream, &ptr) &&
11339
+ !upb_EpsCopyInputStream_IsError(&ctx->stream));
11340
+ return fields;
11341
+ }
11342
+
11343
+ // Compares two sorted upb_UnknownFields structures for equality.
11344
+ static bool upb_UnknownFields_IsEqual(const upb_UnknownFields* uf1,
11345
+ const upb_UnknownFields* uf2) {
11346
+ if (uf1->size != uf2->size) return false;
11347
+ for (size_t i = 0, n = uf1->size; i < n; i++) {
11348
+ upb_UnknownField* f1 = &uf1->fields[i];
11349
+ upb_UnknownField* f2 = &uf2->fields[i];
11350
+ if (f1->tag != f2->tag) return false;
11351
+ int wire_type = f1->tag & 7;
11352
+ switch (wire_type) {
11353
+ case kUpb_WireType_Varint:
11354
+ if (f1->data.varint != f2->data.varint) return false;
11355
+ break;
11356
+ case kUpb_WireType_64Bit:
11357
+ if (f1->data.uint64 != f2->data.uint64) return false;
11358
+ break;
11359
+ case kUpb_WireType_32Bit:
11360
+ if (f1->data.uint32 != f2->data.uint32) return false;
11361
+ break;
11362
+ case kUpb_WireType_Delimited:
11363
+ if (!upb_StringView_IsEqual(f1->data.delimited, f2->data.delimited)) {
11364
+ return false;
11365
+ }
11366
+ break;
11367
+ case kUpb_WireType_StartGroup:
11368
+ if (!upb_UnknownFields_IsEqual(f1->data.group, f2->data.group)) {
11369
+ return false;
11370
+ }
11371
+ break;
11372
+ default:
11373
+ UPB_UNREACHABLE();
11374
+ }
11375
+ }
11376
+ return true;
11377
+ }
11378
+
11379
+ static upb_UnknownCompareResult upb_UnknownField_DoCompare(
11380
+ upb_UnknownField_Context* ctx, const char* buf1, size_t size1,
11381
+ const char* buf2, size_t size2) {
11382
+ upb_UnknownCompareResult ret;
11383
+ // First build both unknown fields into a sorted data structure (similar
11384
+ // to the UnknownFieldSet in C++).
11385
+ upb_UnknownFields* uf1 = upb_UnknownFields_Build(ctx, buf1, size1);
11386
+ upb_UnknownFields* uf2 = upb_UnknownFields_Build(ctx, buf2, size2);
11387
+
11388
+ // Now perform the equality check on the sorted structures.
11389
+ if (upb_UnknownFields_IsEqual(uf1, uf2)) {
11390
+ ret = kUpb_UnknownCompareResult_Equal;
11391
+ } else {
11392
+ ret = kUpb_UnknownCompareResult_NotEqual;
11393
+ }
11394
+ return ret;
11395
+ }
11396
+
11397
+ static upb_UnknownCompareResult upb_UnknownField_Compare(
11398
+ upb_UnknownField_Context* const ctx, const char* const buf1,
11399
+ const size_t size1, const char* const buf2, const size_t size2) {
11400
+ upb_UnknownCompareResult ret;
11401
+ if (UPB_SETJMP(ctx->err) == 0) {
11402
+ ret = upb_UnknownField_DoCompare(ctx, buf1, size1, buf2, size2);
11403
+ } else {
11404
+ ret = ctx->status;
11405
+ UPB_ASSERT(ret != kUpb_UnknownCompareResult_Equal);
11406
+ }
11407
+
11408
+ upb_Arena_Free(ctx->arena);
11409
+ upb_gfree(ctx->tmp);
11410
+ return ret;
11411
+ }
11412
+
11413
+ upb_UnknownCompareResult UPB_PRIVATE(_upb_Message_UnknownFieldsAreEqual)(
11414
+ const char* buf1, size_t size1, const char* buf2, size_t size2,
11415
+ int max_depth) {
11416
+ if (size1 == 0 && size2 == 0) return kUpb_UnknownCompareResult_Equal;
11417
+ if (size1 == 0 || size2 == 0) return kUpb_UnknownCompareResult_NotEqual;
11418
+ if (memcmp(buf1, buf2, size1) == 0) return kUpb_UnknownCompareResult_Equal;
11419
+
11420
+ upb_UnknownField_Context ctx = {
11421
+ .arena = upb_Arena_New(),
11422
+ .depth = max_depth,
11423
+ .tmp = NULL,
11424
+ .tmp_size = 0,
11425
+ .status = kUpb_UnknownCompareResult_Equal,
11426
+ };
11427
+
11428
+ if (!ctx.arena) return kUpb_UnknownCompareResult_OutOfMemory;
11429
+
11430
+ return upb_UnknownField_Compare(&ctx, buf1, size1, buf2, size2);
11431
+ }
11432
+
11433
+
10606
11434
  #include <string.h>
10607
11435
 
10608
11436
 
10609
11437
  // Must be last.
10610
11438
 
10611
- const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getext)(
11439
+ const upb_Extension* UPB_PRIVATE(_upb_Message_Getext)(
10612
11440
  const struct upb_Message* msg, const upb_MiniTableExtension* e) {
10613
11441
  size_t n;
10614
- const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n);
11442
+ const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n);
10615
11443
 
10616
11444
  // For now we use linear search exclusively to find extensions.
10617
11445
  // If this becomes an issue due to messages with lots of extensions,
@@ -10625,11 +11453,11 @@ const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getext)(
10625
11453
  return NULL;
10626
11454
  }
10627
11455
 
10628
- const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(
11456
+ const upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(
10629
11457
  const struct upb_Message* msg, size_t* count) {
10630
- upb_Message_Internal* in = msg->internal;
11458
+ upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
10631
11459
  if (in) {
10632
- *count = (in->size - in->ext_begin) / sizeof(struct upb_Extension);
11460
+ *count = (in->size - in->ext_begin) / sizeof(upb_Extension);
10633
11461
  return UPB_PTR_AT(in, in->ext_begin, void);
10634
11462
  } else {
10635
11463
  *count = 0;
@@ -10637,17 +11465,16 @@ const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(
10637
11465
  }
10638
11466
  }
10639
11467
 
10640
- struct upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)(
11468
+ upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)(
10641
11469
  struct upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* a) {
10642
- struct upb_Extension* ext =
10643
- (struct upb_Extension*)UPB_PRIVATE(_upb_Message_Getext)(msg, e);
11470
+ upb_Extension* ext = (upb_Extension*)UPB_PRIVATE(_upb_Message_Getext)(msg, e);
10644
11471
  if (ext) return ext;
10645
- if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), a))
11472
+ if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(upb_Extension), a))
10646
11473
  return NULL;
10647
- upb_Message_Internal* in = msg->internal;
10648
- in->ext_begin -= sizeof(struct upb_Extension);
11474
+ upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
11475
+ in->ext_begin -= sizeof(upb_Extension);
10649
11476
  ext = UPB_PTR_AT(in, in->ext_begin, void);
10650
- memset(ext, 0, sizeof(struct upb_Extension));
11477
+ memset(ext, 0, sizeof(upb_Extension));
10651
11478
  ext->ext = e;
10652
11479
  return ext;
10653
11480
  }
@@ -10667,7 +11494,7 @@ bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need,
10667
11494
  upb_Arena* a) {
10668
11495
  const size_t overhead = sizeof(upb_Message_Internal);
10669
11496
 
10670
- upb_Message_Internal* in = msg->internal;
11497
+ upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
10671
11498
  if (!in) {
10672
11499
  // No internal data, allocate from scratch.
10673
11500
  size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + overhead));
@@ -10677,7 +11504,7 @@ bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need,
10677
11504
  in->size = size;
10678
11505
  in->unknown_end = overhead;
10679
11506
  in->ext_begin = size;
10680
- msg->internal = in;
11507
+ UPB_PRIVATE(_upb_Message_SetInternal)(msg, in);
10681
11508
  } else if (in->ext_begin - in->unknown_end < need) {
10682
11509
  // Internal data is too small, reallocate.
10683
11510
  size_t new_size = upb_Log2CeilingSize(in->size + need);
@@ -10693,13 +11520,30 @@ bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need,
10693
11520
  }
10694
11521
  in->ext_begin = new_ext_begin;
10695
11522
  in->size = new_size;
10696
- msg->internal = in;
11523
+ UPB_PRIVATE(_upb_Message_SetInternal)(msg, in);
10697
11524
  }
10698
11525
 
10699
11526
  UPB_ASSERT(in->ext_begin - in->unknown_end >= need);
10700
11527
  return true;
10701
11528
  }
10702
11529
 
11530
+ #if UPB_TRACING_ENABLED
11531
+ static void (*_new_message_trace_handler)(const upb_MiniTable*,
11532
+ const upb_Arena*);
11533
+
11534
+ void UPB_PRIVATE(upb_Message_SetNewMessageTraceHandler)(
11535
+ void (*new_message_trace_handler)(const upb_MiniTable*, const upb_Arena*)) {
11536
+ _new_message_trace_handler = new_message_trace_handler;
11537
+ }
11538
+
11539
+ void UPB_PRIVATE(upb_Message_LogNewMessage)(const upb_MiniTable* mini_table,
11540
+ const upb_Arena* arena) {
11541
+ if (_new_message_trace_handler) {
11542
+ _new_message_trace_handler(mini_table, arena);
11543
+ }
11544
+ }
11545
+ #endif
11546
+
10703
11547
 
10704
11548
  const char _kUpb_ToBase92[] = {
10705
11549
  ' ', '!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/',
@@ -11729,7 +12573,11 @@ const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i) {
11729
12573
  }
11730
12574
 
11731
12575
  bool upb_EnumDef_IsClosed(const upb_EnumDef* e) {
11732
- if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3) return false;
12576
+ if (UPB_TREAT_CLOSED_ENUMS_LIKE_OPEN) return false;
12577
+ return upb_EnumDef_IsSpecifiedAsClosed(e);
12578
+ }
12579
+
12580
+ bool upb_EnumDef_IsSpecifiedAsClosed(const upb_EnumDef* e) {
11733
12581
  return UPB_DESC(FeatureSet_enum_type)(e->resolved_features) ==
11734
12582
  UPB_DESC(FeatureSet_CLOSED);
11735
12583
  }
@@ -12035,15 +12883,10 @@ static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix,
12035
12883
  static void _upb_EnumValueDef_CheckZeroValue(upb_DefBuilder* ctx,
12036
12884
  const upb_EnumDef* e,
12037
12885
  const upb_EnumValueDef* v, int n) {
12038
- if (upb_EnumDef_IsClosed(e) || n == 0 || v[0].number == 0) return;
12039
-
12040
- // When the special UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 is enabled, we have to
12041
- // exempt proto2 enums from this check, even when we are treating them as
12886
+ // When the special UPB_TREAT_CLOSED_ENUMS_LIKE_OPEN is enabled, we have to
12887
+ // exempt closed enums from this check, even when we are treating them as
12042
12888
  // open.
12043
- if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 &&
12044
- upb_FileDef_Syntax(upb_EnumDef_File(e)) == kUpb_Syntax_Proto2) {
12045
- return;
12046
- }
12889
+ if (upb_EnumDef_IsSpecifiedAsClosed(e) || n == 0 || v[0].number == 0) return;
12047
12890
 
12048
12891
  _upb_DefBuilder_Errf(ctx, "for open enums, the first value must be zero (%s)",
12049
12892
  upb_EnumDef_FullName(e));
@@ -12225,27 +13068,16 @@ upb_CType upb_FieldDef_CType(const upb_FieldDef* f) {
12225
13068
  return upb_FieldType_CType(f->type_);
12226
13069
  }
12227
13070
 
12228
- upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) {
12229
- // TODO: remove once we can deprecate kUpb_FieldType_Group.
12230
- if (f->type_ == kUpb_FieldType_Message &&
12231
- UPB_DESC(FeatureSet_message_encoding)(f->resolved_features) ==
12232
- UPB_DESC(FeatureSet_DELIMITED)) {
12233
- return kUpb_FieldType_Group;
12234
- }
12235
- return f->type_;
12236
- }
13071
+ upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { return f->type_; }
12237
13072
 
12238
13073
  uint32_t upb_FieldDef_Index(const upb_FieldDef* f) { return f->index_; }
12239
13074
 
12240
- upb_Label upb_FieldDef_Label(const upb_FieldDef* f) {
12241
- // TODO: remove once we can deprecate kUpb_Label_Required.
12242
- if (UPB_DESC(FeatureSet_field_presence)(f->resolved_features) ==
12243
- UPB_DESC(FeatureSet_LEGACY_REQUIRED)) {
12244
- return kUpb_Label_Required;
12245
- }
12246
- return f->label_;
13075
+ uint32_t upb_FieldDef_LayoutIndex(const upb_FieldDef* f) {
13076
+ return f->layout_index;
12247
13077
  }
12248
13078
 
13079
+ upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { return f->label_; }
13080
+
12249
13081
  uint32_t upb_FieldDef_Number(const upb_FieldDef* f) { return f->number_; }
12250
13082
 
12251
13083
  bool upb_FieldDef_IsExtension(const upb_FieldDef* f) { return f->is_extension; }
@@ -12376,6 +13208,40 @@ bool _upb_FieldDef_ValidateUtf8(const upb_FieldDef* f) {
12376
13208
  UPB_DESC(FeatureSet_VERIFY);
12377
13209
  }
12378
13210
 
13211
+ bool _upb_FieldDef_IsGroupLike(const upb_FieldDef* f) {
13212
+ // Groups are always tag-delimited.
13213
+ if (UPB_DESC(FeatureSet_message_encoding)(upb_FieldDef_ResolvedFeatures(f)) !=
13214
+ UPB_DESC(FeatureSet_DELIMITED)) {
13215
+ return false;
13216
+ }
13217
+
13218
+ const upb_MessageDef* msg = upb_FieldDef_MessageSubDef(f);
13219
+
13220
+ // Group fields always are always the lowercase type name.
13221
+ const char* mname = upb_MessageDef_Name(msg);
13222
+ const char* fname = upb_FieldDef_Name(f);
13223
+ size_t name_size = strlen(fname);
13224
+ if (name_size != strlen(mname)) return false;
13225
+ for (size_t i = 0; i < name_size; ++i) {
13226
+ if ((mname[i] | 0x20) != fname[i]) {
13227
+ // Case-insensitive ascii comparison.
13228
+ return false;
13229
+ }
13230
+ }
13231
+
13232
+ if (upb_MessageDef_File(msg) != upb_FieldDef_File(f)) {
13233
+ return false;
13234
+ }
13235
+
13236
+ // Group messages are always defined in the same scope as the field. File
13237
+ // level extensions will compare NULL == NULL here, which is why the file
13238
+ // comparison above is necessary to ensure both come from the same file.
13239
+ return upb_FieldDef_IsExtension(f) ? upb_FieldDef_ExtensionScope(f) ==
13240
+ upb_MessageDef_ContainingType(msg)
13241
+ : upb_FieldDef_ContainingType(f) ==
13242
+ upb_MessageDef_ContainingType(msg);
13243
+ }
13244
+
12379
13245
  uint64_t _upb_FieldDef_Modifiers(const upb_FieldDef* f) {
12380
13246
  uint64_t out = upb_FieldDef_IsPacked(f) ? kUpb_FieldModifier_IsPacked : 0;
12381
13247
 
@@ -12707,7 +13573,6 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix,
12707
13573
 
12708
13574
  const upb_StringView name = UPB_DESC(FieldDescriptorProto_name)(field_proto);
12709
13575
  f->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name);
12710
- f->label_ = (int)UPB_DESC(FieldDescriptorProto_label)(field_proto);
12711
13576
  f->number_ = UPB_DESC(FieldDescriptorProto_number)(field_proto);
12712
13577
  f->is_proto3_optional =
12713
13578
  UPB_DESC(FieldDescriptorProto_proto3_optional)(field_proto);
@@ -12753,6 +13618,14 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix,
12753
13618
  f->resolved_features = _upb_DefBuilder_DoResolveFeatures(
12754
13619
  ctx, parent_features, unresolved_features, implicit);
12755
13620
 
13621
+ f->label_ = (int)UPB_DESC(FieldDescriptorProto_label)(field_proto);
13622
+ if (f->label_ == kUpb_Label_Optional &&
13623
+ // TODO: remove once we can deprecate kUpb_Label_Required.
13624
+ UPB_DESC(FeatureSet_field_presence)(f->resolved_features) ==
13625
+ UPB_DESC(FeatureSet_LEGACY_REQUIRED)) {
13626
+ f->label_ = kUpb_Label_Required;
13627
+ }
13628
+
12756
13629
  if (!UPB_DESC(FieldDescriptorProto_has_name)(field_proto)) {
12757
13630
  _upb_DefBuilder_Errf(ctx, "field has no name");
12758
13631
  }
@@ -12772,6 +13645,12 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix,
12772
13645
  UPB_DESC(FieldDescriptorProto_has_type_name)(field_proto);
12773
13646
 
12774
13647
  f->type_ = (int)UPB_DESC(FieldDescriptorProto_type)(field_proto);
13648
+ if (f->type_ == kUpb_FieldType_Message &&
13649
+ // TODO: remove once we can deprecate kUpb_FieldType_Group.
13650
+ UPB_DESC(FeatureSet_message_encoding)(f->resolved_features) ==
13651
+ UPB_DESC(FeatureSet_DELIMITED)) {
13652
+ f->type_ = kUpb_FieldType_Group;
13653
+ }
12775
13654
 
12776
13655
  if (has_type) {
12777
13656
  switch (f->type_) {
@@ -12821,10 +13700,11 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix,
12821
13700
 
12822
13701
  f->has_presence =
12823
13702
  (!upb_FieldDef_IsRepeated(f)) &&
12824
- (f->type_ == kUpb_FieldType_Message || f->type_ == kUpb_FieldType_Group ||
12825
- upb_FieldDef_ContainingOneof(f) ||
12826
- UPB_DESC(FeatureSet_field_presence)(f->resolved_features) !=
12827
- UPB_DESC(FeatureSet_IMPLICIT));
13703
+ (f->is_extension ||
13704
+ (f->type_ == kUpb_FieldType_Message ||
13705
+ f->type_ == kUpb_FieldType_Group || upb_FieldDef_ContainingOneof(f) ||
13706
+ UPB_DESC(FeatureSet_field_presence)(f->resolved_features) !=
13707
+ UPB_DESC(FeatureSet_IMPLICIT)));
12828
13708
  }
12829
13709
 
12830
13710
  static void _upb_FieldDef_CreateExt(upb_DefBuilder* ctx, const char* prefix,
@@ -13260,6 +14140,17 @@ const upb_MiniTableExtension* _upb_FileDef_ExtensionMiniTable(
13260
14140
  return f->ext_layouts[i];
13261
14141
  }
13262
14142
 
14143
+ // Note: Import cycles are not allowed so this will terminate.
14144
+ bool upb_FileDef_Resolves(const upb_FileDef* f, const char* path) {
14145
+ if (!strcmp(f->name, path)) return true;
14146
+
14147
+ for (int i = 0; i < upb_FileDef_PublicDependencyCount(f); i++) {
14148
+ const upb_FileDef* dep = upb_FileDef_PublicDependency(f, i);
14149
+ if (upb_FileDef_Resolves(dep, path)) return true;
14150
+ }
14151
+ return false;
14152
+ }
14153
+
13263
14154
  static char* strviewdup(upb_DefBuilder* ctx, upb_StringView view) {
13264
14155
  char* ret = upb_strdup2(view.data, view.size, _upb_DefBuilder_Arena(ctx));
13265
14156
  if (!ret) _upb_DefBuilder_OomErr(ctx);
@@ -13311,20 +14202,35 @@ const UPB_DESC(FeatureSet*)
13311
14202
  size_t n;
13312
14203
  const UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault)* const* d =
13313
14204
  UPB_DESC(FeatureSetDefaults_defaults)(defaults, &n);
13314
- const UPB_DESC(FeatureSet)* ret = NULL;
14205
+ const UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault)* result = NULL;
13315
14206
  for (size_t i = 0; i < n; i++) {
13316
14207
  if (UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_edition)(d[i]) >
13317
14208
  edition) {
13318
14209
  break;
13319
14210
  }
13320
- ret = UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_features)(d[i]);
14211
+ result = d[i];
13321
14212
  }
13322
- if (ret == NULL) {
14213
+ if (result == NULL) {
13323
14214
  _upb_DefBuilder_Errf(ctx, "No valid default found for edition %s",
13324
14215
  upb_FileDef_EditionName(edition));
13325
14216
  return NULL;
13326
14217
  }
13327
- return ret;
14218
+
14219
+ // Merge the fixed and overridable features to get the edition's default
14220
+ // feature set.
14221
+ const UPB_DESC(FeatureSet)* fixed = UPB_DESC(
14222
+ FeatureSetDefaults_FeatureSetEditionDefault_fixed_features)(result);
14223
+ const UPB_DESC(FeatureSet)* overridable = UPB_DESC(
14224
+ FeatureSetDefaults_FeatureSetEditionDefault_overridable_features)(result);
14225
+ if (!fixed && !overridable) {
14226
+ _upb_DefBuilder_Errf(ctx, "No valid default found for edition %s",
14227
+ upb_FileDef_EditionName(edition));
14228
+ return NULL;
14229
+ } else if (!fixed) {
14230
+ return overridable;
14231
+ }
14232
+ return _upb_DefBuilder_DoResolveFeatures(ctx, fixed, overridable,
14233
+ /*is_implicit=*/true);
13328
14234
  }
13329
14235
 
13330
14236
  // Allocate and initialize one file def, and add it to the context object.
@@ -14026,7 +14932,15 @@ make:
14026
14932
 
14027
14933
  bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f,
14028
14934
  upb_MessageValue val, upb_Arena* a) {
14029
- return upb_Message_SetField(msg, upb_FieldDef_MiniTable(f), val, a);
14935
+ const upb_MiniTableField* m_f = upb_FieldDef_MiniTable(f);
14936
+
14937
+ if (upb_MiniTableField_IsExtension(m_f)) {
14938
+ return upb_Message_SetExtension(msg, (const upb_MiniTableExtension*)m_f,
14939
+ &val, a);
14940
+ } else {
14941
+ upb_Message_SetBaseField(msg, m_f, &val);
14942
+ return true;
14943
+ }
14030
14944
  }
14031
14945
 
14032
14946
  void upb_Message_ClearFieldByDef(upb_Message* msg, const upb_FieldDef* f) {
@@ -14046,19 +14960,20 @@ void upb_Message_ClearByDef(upb_Message* msg, const upb_MessageDef* m) {
14046
14960
  bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m,
14047
14961
  const upb_DefPool* ext_pool, const upb_FieldDef** out_f,
14048
14962
  upb_MessageValue* out_val, size_t* iter) {
14963
+ const upb_MiniTable* mt = upb_MessageDef_MiniTable(m);
14049
14964
  size_t i = *iter;
14050
- size_t n = upb_MessageDef_FieldCount(m);
14965
+ size_t n = upb_MiniTable_FieldCount(mt);
14966
+ const upb_MessageValue zero = {0};
14051
14967
  UPB_UNUSED(ext_pool);
14052
14968
 
14053
14969
  // Iterate over normal fields, returning the first one that is set.
14054
14970
  while (++i < n) {
14055
- const upb_FieldDef* f = upb_MessageDef_Field(m, i);
14056
- const upb_MiniTableField* field = upb_FieldDef_MiniTable(f);
14057
- upb_MessageValue val = upb_Message_GetFieldByDef(msg, f);
14971
+ const upb_MiniTableField* field = upb_MiniTable_GetFieldByIndex(mt, i);
14972
+ upb_MessageValue val = upb_Message_GetField(msg, field, zero);
14058
14973
 
14059
14974
  // Skip field if unset or empty.
14060
14975
  if (upb_MiniTableField_HasPresence(field)) {
14061
- if (!upb_Message_HasFieldByDef(msg, f)) continue;
14976
+ if (!upb_Message_HasBaseField(msg, field)) continue;
14062
14977
  } else {
14063
14978
  switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) {
14064
14979
  case kUpb_FieldMode_Map:
@@ -14075,7 +14990,8 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m,
14075
14990
  }
14076
14991
 
14077
14992
  *out_val = val;
14078
- *out_f = f;
14993
+ *out_f =
14994
+ upb_MessageDef_FindFieldByNumber(m, upb_MiniTableField_Number(field));
14079
14995
  *iter = i;
14080
14996
  return true;
14081
14997
  }
@@ -14539,7 +15455,10 @@ void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m,
14539
15455
  _upb_MessageDef_Insert(m, shortname, shortnamelen, field_v, ctx->arena);
14540
15456
  if (!ok) _upb_DefBuilder_OomErr(ctx);
14541
15457
 
14542
- if (strcmp(shortname, json_name) != 0 &&
15458
+ bool skip_json_conflicts =
15459
+ UPB_DESC(MessageOptions_deprecated_legacy_json_field_conflicts)(
15460
+ upb_MessageDef_Options(m));
15461
+ if (!skip_json_conflicts && strcmp(shortname, json_name) != 0 &&
14543
15462
  UPB_DESC(FeatureSet_json_format)(m->resolved_features) ==
14544
15463
  UPB_DESC(FeatureSet_ALLOW) &&
14545
15464
  upb_strtable_lookup(&m->ntof, json_name, &v)) {
@@ -14549,14 +15468,16 @@ void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m,
14549
15468
  }
14550
15469
 
14551
15470
  if (upb_strtable_lookup(&m->jtof, json_name, &v)) {
14552
- _upb_DefBuilder_Errf(ctx, "duplicate json_name (%s)", json_name);
15471
+ if (!skip_json_conflicts) {
15472
+ _upb_DefBuilder_Errf(ctx, "duplicate json_name (%s)", json_name);
15473
+ }
15474
+ } else {
15475
+ const size_t json_size = strlen(json_name);
15476
+ ok = upb_strtable_insert(&m->jtof, json_name, json_size,
15477
+ upb_value_constptr(f), ctx->arena);
15478
+ if (!ok) _upb_DefBuilder_OomErr(ctx);
14553
15479
  }
14554
15480
 
14555
- const size_t json_size = strlen(json_name);
14556
- ok = upb_strtable_insert(&m->jtof, json_name, json_size,
14557
- upb_value_constptr(f), ctx->arena);
14558
- if (!ok) _upb_DefBuilder_OomErr(ctx);
14559
-
14560
15481
  if (upb_inttable_lookup(&m->itof, field_number, NULL)) {
14561
15482
  _upb_DefBuilder_Errf(ctx, "duplicate field number (%u)", field_number);
14562
15483
  }
@@ -14570,7 +15491,7 @@ void _upb_MessageDef_CreateMiniTable(upb_DefBuilder* ctx, upb_MessageDef* m) {
14570
15491
  m->layout = _upb_MessageDef_MakeMiniTable(ctx, m);
14571
15492
  } else {
14572
15493
  m->layout = upb_MiniTableFile_Message(ctx->layout, ctx->msg_count++);
14573
- UPB_ASSERT(m->field_count == m->layout->UPB_PRIVATE(field_count));
15494
+ UPB_ASSERT(m->field_count == upb_MiniTable_FieldCount(m->layout));
14574
15495
 
14575
15496
  // We don't need the result of this call, but it will assign layout_index
14576
15497
  // for all the fields in O(n lg n) time.
@@ -14628,7 +15549,7 @@ void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx,
14628
15549
  for (int i = 0; i < m->field_count; i++) {
14629
15550
  const upb_FieldDef* f = upb_MessageDef_Field(m, i);
14630
15551
  const int layout_index = _upb_FieldDef_LayoutIndex(f);
14631
- UPB_ASSERT(layout_index < m->layout->UPB_PRIVATE(field_count));
15552
+ UPB_ASSERT(layout_index < upb_MiniTable_FieldCount(m->layout));
14632
15553
  const upb_MiniTableField* mt_f =
14633
15554
  &m->layout->UPB_PRIVATE(fields)[layout_index];
14634
15555
  UPB_ASSERT(upb_FieldDef_Type(f) == upb_MiniTableField_Type(mt_f));
@@ -15394,7 +16315,7 @@ upb_ServiceDef* _upb_ServiceDefs_New(upb_DefBuilder* ctx, int n,
15394
16315
  #undef UPB_ASAN
15395
16316
  #undef UPB_ASAN_GUARD_SIZE
15396
16317
  #undef UPB_CLANG_ASAN
15397
- #undef UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3
16318
+ #undef UPB_TREAT_CLOSED_ENUMS_LIKE_OPEN
15398
16319
  #undef UPB_DEPRECATED
15399
16320
  #undef UPB_GNUC_MIN
15400
16321
  #undef UPB_DESCRIPTOR_UPB_H_FILENAME