google-protobuf 4.26.1-arm64-darwin → 4.27.0-arm64-darwin
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of google-protobuf might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/ext/google/protobuf_c/defs.c +327 -1
- data/ext/google/protobuf_c/glue.c +16 -0
- data/ext/google/protobuf_c/message.c +4 -15
- data/ext/google/protobuf_c/message.h +0 -4
- data/ext/google/protobuf_c/ruby-upb.c +1207 -284
- data/ext/google/protobuf_c/ruby-upb.h +1208 -825
- data/ext/google/protobuf_c/shared_convert.c +5 -2
- data/ext/google/protobuf_c/shared_message.c +0 -30
- data/ext/google/protobuf_c/shared_message.h +0 -4
- data/lib/google/3.0/protobuf_c.bundle +0 -0
- data/lib/google/3.1/protobuf_c.bundle +0 -0
- data/lib/google/3.2/protobuf_c.bundle +0 -0
- data/lib/google/3.3/protobuf_c.bundle +0 -0
- data/lib/google/protobuf/descriptor_pb.rb +2 -1
- data/lib/google/protobuf/ffi/descriptor.rb +3 -1
- data/lib/google/protobuf/ffi/descriptor_pool.rb +3 -1
- data/lib/google/protobuf/ffi/enum_descriptor.rb +3 -1
- data/lib/google/protobuf/ffi/ffi.rb +0 -5
- data/lib/google/protobuf/ffi/field_descriptor.rb +4 -2
- data/lib/google/protobuf/ffi/file_descriptor.rb +3 -1
- data/lib/google/protobuf/ffi/internal/convert.rb +1 -1
- data/lib/google/protobuf/ffi/method_descriptor.rb +114 -0
- data/lib/google/protobuf/ffi/oneof_descriptor.rb +3 -1
- data/lib/google/protobuf/ffi/service_descriptor.rb +107 -0
- data/lib/google/protobuf/repeated_field.rb +3 -3
- data/lib/google/protobuf_ffi.rb +2 -0
- metadata +20 -5
- data/lib/google/2.7/protobuf_c.bundle +0 -0
@@ -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
|
309
|
-
#define
|
308
|
+
#ifdef UPB_DISABLE_CLOSED_ENUM_CHECKING
|
309
|
+
#define UPB_TREAT_CLOSED_ENUMS_LIKE_OPEN 1
|
310
310
|
#else
|
311
|
-
#define
|
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[
|
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[
|
894
|
-
{1, 12, 64,
|
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,
|
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,
|
903
|
-
{19, 32, 0,
|
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
|
-
{
|
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(
|
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
|
-
{
|
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},
|
@@ -1064,22 +1154,27 @@ const upb_MiniTable google__protobuf__EnumOptions_msg_init = {
|
|
1064
1154
|
})
|
1065
1155
|
};
|
1066
1156
|
|
1067
|
-
static const upb_MiniTableSub google_protobuf_EnumValueOptions_submsgs[
|
1157
|
+
static const upb_MiniTableSub google_protobuf_EnumValueOptions_submsgs[3] = {
|
1068
1158
|
{.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSet_msg_init},
|
1159
|
+
{.UPB_PRIVATE(submsg) = &google__protobuf__FieldOptions__FeatureSupport_msg_init},
|
1069
1160
|
{.UPB_PRIVATE(submsg) = &google__protobuf__UninterpretedOption_msg_init},
|
1070
1161
|
};
|
1071
1162
|
|
1072
|
-
static const upb_MiniTableField google_protobuf_EnumValueOptions__fields[
|
1163
|
+
static const upb_MiniTableField google_protobuf_EnumValueOptions__fields[5] = {
|
1073
1164
|
{1, 9, 64, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)},
|
1074
1165
|
{2, UPB_SIZE(12, 16), 65, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
|
1075
1166
|
{3, UPB_SIZE(16, 10), 66, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)},
|
1076
|
-
{
|
1167
|
+
{4, UPB_SIZE(20, 24), 67, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
|
1168
|
+
{999, UPB_SIZE(24, 32), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
|
1077
1169
|
};
|
1078
1170
|
|
1079
1171
|
const upb_MiniTable google__protobuf__EnumValueOptions_msg_init = {
|
1080
1172
|
&google_protobuf_EnumValueOptions_submsgs[0],
|
1081
1173
|
&google_protobuf_EnumValueOptions__fields[0],
|
1082
|
-
UPB_SIZE(
|
1174
|
+
UPB_SIZE(32, 40), 5, kUpb_ExtMode_Extendable, 4, UPB_FASTTABLE_MASK(248), 0,
|
1175
|
+
#ifdef UPB_TRACING_ENABLED
|
1176
|
+
"google.protobuf.EnumValueOptions",
|
1177
|
+
#endif
|
1083
1178
|
UPB_FASTTABLE_INIT({
|
1084
1179
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
1085
1180
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
@@ -1104,7 +1199,7 @@ const upb_MiniTable google__protobuf__EnumValueOptions_msg_init = {
|
|
1104
1199
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
1105
1200
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
1106
1201
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
1107
|
-
{
|
1202
|
+
{0x002000003f023eba, &upb_prm_2bt_max128b},
|
1108
1203
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
1109
1204
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
1110
1205
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
@@ -1131,6 +1226,9 @@ const upb_MiniTable google__protobuf__ServiceOptions_msg_init = {
|
|
1131
1226
|
&google_protobuf_ServiceOptions_submsgs[0],
|
1132
1227
|
&google_protobuf_ServiceOptions__fields[0],
|
1133
1228
|
UPB_SIZE(24, 32), 3, kUpb_ExtMode_Extendable, 0, UPB_FASTTABLE_MASK(248), 0,
|
1229
|
+
#ifdef UPB_TRACING_ENABLED
|
1230
|
+
"google.protobuf.ServiceOptions",
|
1231
|
+
#endif
|
1134
1232
|
UPB_FASTTABLE_INIT({
|
1135
1233
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
1136
1234
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
@@ -1184,6 +1282,9 @@ const upb_MiniTable google__protobuf__MethodOptions_msg_init = {
|
|
1184
1282
|
&google_protobuf_MethodOptions_submsgs[0],
|
1185
1283
|
&google_protobuf_MethodOptions__fields[0],
|
1186
1284
|
UPB_SIZE(24, 32), 4, kUpb_ExtMode_Extendable, 0, UPB_FASTTABLE_MASK(248), 0,
|
1285
|
+
#ifdef UPB_TRACING_ENABLED
|
1286
|
+
"google.protobuf.MethodOptions",
|
1287
|
+
#endif
|
1187
1288
|
UPB_FASTTABLE_INIT({
|
1188
1289
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
1189
1290
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
@@ -1238,6 +1339,9 @@ const upb_MiniTable google__protobuf__UninterpretedOption_msg_init = {
|
|
1238
1339
|
&google_protobuf_UninterpretedOption_submsgs[0],
|
1239
1340
|
&google_protobuf_UninterpretedOption__fields[0],
|
1240
1341
|
UPB_SIZE(64, 96), 7, kUpb_ExtMode_NonExtendable, 0, UPB_FASTTABLE_MASK(24), 0,
|
1342
|
+
#ifdef UPB_TRACING_ENABLED
|
1343
|
+
"google.protobuf.UninterpretedOption",
|
1344
|
+
#endif
|
1241
1345
|
UPB_FASTTABLE_INIT({
|
1242
1346
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
1243
1347
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
@@ -1255,6 +1359,9 @@ const upb_MiniTable google__protobuf__UninterpretedOption__NamePart_msg_init = {
|
|
1255
1359
|
NULL,
|
1256
1360
|
&google_protobuf_UninterpretedOption_NamePart__fields[0],
|
1257
1361
|
UPB_SIZE(24, 32), 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(255), 2,
|
1362
|
+
#ifdef UPB_TRACING_ENABLED
|
1363
|
+
"google.protobuf.UninterpretedOption.NamePart",
|
1364
|
+
#endif
|
1258
1365
|
};
|
1259
1366
|
|
1260
1367
|
static const upb_MiniTableSub google_protobuf_FeatureSet_submsgs[6] = {
|
@@ -1279,6 +1386,9 @@ const upb_MiniTable google__protobuf__FeatureSet_msg_init = {
|
|
1279
1386
|
&google_protobuf_FeatureSet_submsgs[0],
|
1280
1387
|
&google_protobuf_FeatureSet__fields[0],
|
1281
1388
|
40, 6, kUpb_ExtMode_Extendable, 6, UPB_FASTTABLE_MASK(255), 0,
|
1389
|
+
#ifdef UPB_TRACING_ENABLED
|
1390
|
+
"google.protobuf.FeatureSet",
|
1391
|
+
#endif
|
1282
1392
|
};
|
1283
1393
|
|
1284
1394
|
static const upb_MiniTableSub google_protobuf_FeatureSetDefaults_submsgs[3] = {
|
@@ -1297,26 +1407,34 @@ const upb_MiniTable google__protobuf__FeatureSetDefaults_msg_init = {
|
|
1297
1407
|
&google_protobuf_FeatureSetDefaults_submsgs[0],
|
1298
1408
|
&google_protobuf_FeatureSetDefaults__fields[0],
|
1299
1409
|
UPB_SIZE(24, 32), 3, kUpb_ExtMode_NonExtendable, 1, UPB_FASTTABLE_MASK(8), 0,
|
1410
|
+
#ifdef UPB_TRACING_ENABLED
|
1411
|
+
"google.protobuf.FeatureSetDefaults",
|
1412
|
+
#endif
|
1300
1413
|
UPB_FASTTABLE_INIT({
|
1301
1414
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
1302
1415
|
{0x001800003f00000a, &upb_prm_1bt_max64b},
|
1303
1416
|
})
|
1304
1417
|
};
|
1305
1418
|
|
1306
|
-
static const upb_MiniTableSub google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_submsgs[
|
1419
|
+
static const upb_MiniTableSub google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_submsgs[3] = {
|
1420
|
+
{.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSet_msg_init},
|
1307
1421
|
{.UPB_PRIVATE(submsg) = &google__protobuf__FeatureSet_msg_init},
|
1308
1422
|
{.UPB_PRIVATE(subenum) = &google_protobuf_Edition_enum_init},
|
1309
1423
|
};
|
1310
1424
|
|
1311
|
-
static const upb_MiniTableField google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault__fields[
|
1312
|
-
{
|
1313
|
-
{
|
1425
|
+
static const upb_MiniTableField google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault__fields[3] = {
|
1426
|
+
{3, 12, 64, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
|
1427
|
+
{4, 16, 65, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
|
1428
|
+
{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
1429
|
};
|
1315
1430
|
|
1316
1431
|
const upb_MiniTable google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init = {
|
1317
1432
|
&google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_submsgs[0],
|
1318
1433
|
&google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault__fields[0],
|
1319
|
-
24,
|
1434
|
+
UPB_SIZE(24, 32), 3, kUpb_ExtMode_NonExtendable, 0, UPB_FASTTABLE_MASK(255), 0,
|
1435
|
+
#ifdef UPB_TRACING_ENABLED
|
1436
|
+
"google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault",
|
1437
|
+
#endif
|
1320
1438
|
};
|
1321
1439
|
|
1322
1440
|
static const upb_MiniTableSub google_protobuf_SourceCodeInfo_submsgs[1] = {
|
@@ -1331,6 +1449,9 @@ const upb_MiniTable google__protobuf__SourceCodeInfo_msg_init = {
|
|
1331
1449
|
&google_protobuf_SourceCodeInfo_submsgs[0],
|
1332
1450
|
&google_protobuf_SourceCodeInfo__fields[0],
|
1333
1451
|
16, 1, kUpb_ExtMode_NonExtendable, 1, UPB_FASTTABLE_MASK(8), 0,
|
1452
|
+
#ifdef UPB_TRACING_ENABLED
|
1453
|
+
"google.protobuf.SourceCodeInfo",
|
1454
|
+
#endif
|
1334
1455
|
UPB_FASTTABLE_INIT({
|
1335
1456
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
1336
1457
|
{0x000800003f00000a, &upb_prm_1bt_max128b},
|
@@ -1349,6 +1470,9 @@ const upb_MiniTable google__protobuf__SourceCodeInfo__Location_msg_init = {
|
|
1349
1470
|
NULL,
|
1350
1471
|
&google_protobuf_SourceCodeInfo_Location__fields[0],
|
1351
1472
|
UPB_SIZE(40, 72), 5, kUpb_ExtMode_NonExtendable, 4, UPB_FASTTABLE_MASK(56), 0,
|
1473
|
+
#ifdef UPB_TRACING_ENABLED
|
1474
|
+
"google.protobuf.SourceCodeInfo.Location",
|
1475
|
+
#endif
|
1352
1476
|
UPB_FASTTABLE_INIT({
|
1353
1477
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
1354
1478
|
{0x001000003f00000a, &upb_ppv4_1bt},
|
@@ -1373,6 +1497,9 @@ const upb_MiniTable google__protobuf__GeneratedCodeInfo_msg_init = {
|
|
1373
1497
|
&google_protobuf_GeneratedCodeInfo_submsgs[0],
|
1374
1498
|
&google_protobuf_GeneratedCodeInfo__fields[0],
|
1375
1499
|
16, 1, kUpb_ExtMode_NonExtendable, 1, UPB_FASTTABLE_MASK(8), 0,
|
1500
|
+
#ifdef UPB_TRACING_ENABLED
|
1501
|
+
"google.protobuf.GeneratedCodeInfo",
|
1502
|
+
#endif
|
1376
1503
|
UPB_FASTTABLE_INIT({
|
1377
1504
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
1378
1505
|
{0x000800003f00000a, &upb_prm_1bt_max64b},
|
@@ -1395,13 +1522,16 @@ const upb_MiniTable google__protobuf__GeneratedCodeInfo__Annotation_msg_init = {
|
|
1395
1522
|
&google_protobuf_GeneratedCodeInfo_Annotation_submsgs[0],
|
1396
1523
|
&google_protobuf_GeneratedCodeInfo_Annotation__fields[0],
|
1397
1524
|
UPB_SIZE(40, 48), 5, kUpb_ExtMode_NonExtendable, 5, UPB_FASTTABLE_MASK(8), 0,
|
1525
|
+
#ifdef UPB_TRACING_ENABLED
|
1526
|
+
"google.protobuf.GeneratedCodeInfo.Annotation",
|
1527
|
+
#endif
|
1398
1528
|
UPB_FASTTABLE_INIT({
|
1399
1529
|
{0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
|
1400
1530
|
{0x001800003f00000a, &upb_ppv4_1bt},
|
1401
1531
|
})
|
1402
1532
|
};
|
1403
1533
|
|
1404
|
-
static const upb_MiniTable *messages_layout[
|
1534
|
+
static const upb_MiniTable *messages_layout[33] = {
|
1405
1535
|
&google__protobuf__FileDescriptorSet_msg_init,
|
1406
1536
|
&google__protobuf__FileDescriptorProto_msg_init,
|
1407
1537
|
&google__protobuf__DescriptorProto_msg_init,
|
@@ -1420,6 +1550,7 @@ static const upb_MiniTable *messages_layout[32] = {
|
|
1420
1550
|
&google__protobuf__MessageOptions_msg_init,
|
1421
1551
|
&google__protobuf__FieldOptions_msg_init,
|
1422
1552
|
&google__protobuf__FieldOptions__EditionDefault_msg_init,
|
1553
|
+
&google__protobuf__FieldOptions__FeatureSupport_msg_init,
|
1423
1554
|
&google__protobuf__OneofOptions_msg_init,
|
1424
1555
|
&google__protobuf__EnumOptions_msg_init,
|
1425
1556
|
&google__protobuf__EnumValueOptions_msg_init,
|
@@ -1438,10 +1569,11 @@ static const upb_MiniTable *messages_layout[32] = {
|
|
1438
1569
|
|
1439
1570
|
const upb_MiniTableEnum google_protobuf_Edition_enum_init = {
|
1440
1571
|
64,
|
1441
|
-
|
1572
|
+
9,
|
1442
1573
|
{
|
1443
1574
|
0x7,
|
1444
1575
|
0x0,
|
1576
|
+
0x384,
|
1445
1577
|
0x3e6,
|
1446
1578
|
0x3e7,
|
1447
1579
|
0x3e8,
|
@@ -1621,7 +1753,7 @@ const upb_MiniTableFile google_protobuf_descriptor_proto_upb_file_layout = {
|
|
1621
1753
|
messages_layout,
|
1622
1754
|
enums_layout,
|
1623
1755
|
NULL,
|
1624
|
-
|
1756
|
+
33,
|
1625
1757
|
17,
|
1626
1758
|
0,
|
1627
1759
|
};
|
@@ -3131,6 +3263,7 @@ static bool upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg,
|
|
3131
3263
|
bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg,
|
3132
3264
|
const upb_MessageDef* m, const upb_DefPool* symtab,
|
3133
3265
|
int options, upb_Arena* arena, upb_Status* status) {
|
3266
|
+
UPB_ASSERT(!upb_Message_IsFrozen(msg));
|
3134
3267
|
jsondec d;
|
3135
3268
|
|
3136
3269
|
if (size == 0) return true;
|
@@ -3941,6 +4074,10 @@ static void* upb_global_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize,
|
|
3941
4074
|
upb_alloc upb_alloc_global = {&upb_global_allocfunc};
|
3942
4075
|
|
3943
4076
|
|
4077
|
+
#ifdef UPB_TRACING_ENABLED
|
4078
|
+
#include <stdatomic.h>
|
4079
|
+
#endif
|
4080
|
+
|
3944
4081
|
#include <stddef.h>
|
3945
4082
|
#include <stdint.h>
|
3946
4083
|
|
@@ -4047,6 +4184,38 @@ static bool _upb_ArenaInternal_HasInitialBlock(upb_ArenaInternal* ai) {
|
|
4047
4184
|
return ai->block_alloc & 0x1;
|
4048
4185
|
}
|
4049
4186
|
|
4187
|
+
#ifdef UPB_TRACING_ENABLED
|
4188
|
+
static void (*_init_arena_trace_handler)(const upb_Arena*, size_t size) = NULL;
|
4189
|
+
static void (*_fuse_arena_trace_handler)(const upb_Arena*,
|
4190
|
+
const upb_Arena*) = NULL;
|
4191
|
+
static void (*_free_arena_trace_handler)(const upb_Arena*) = NULL;
|
4192
|
+
|
4193
|
+
void upb_Arena_SetTraceHandler(
|
4194
|
+
void (*initArenaTraceHandler)(const upb_Arena*, size_t size),
|
4195
|
+
void (*fuseArenaTraceHandler)(const upb_Arena*, const upb_Arena*),
|
4196
|
+
void (*freeArenaTraceHandler)(const upb_Arena*)) {
|
4197
|
+
_init_arena_trace_handler = initArenaTraceHandler;
|
4198
|
+
_fuse_arena_trace_handler = fuseArenaTraceHandler;
|
4199
|
+
_free_arena_trace_handler = freeArenaTraceHandler;
|
4200
|
+
}
|
4201
|
+
|
4202
|
+
void upb_Arena_LogInit(const upb_Arena* arena, size_t size) {
|
4203
|
+
if (_init_arena_trace_handler) {
|
4204
|
+
_init_arena_trace_handler(arena, size);
|
4205
|
+
}
|
4206
|
+
}
|
4207
|
+
void upb_Arena_LogFuse(const upb_Arena* arena1, const upb_Arena* arena2) {
|
4208
|
+
if (_fuse_arena_trace_handler) {
|
4209
|
+
_fuse_arena_trace_handler(arena1, arena2);
|
4210
|
+
}
|
4211
|
+
}
|
4212
|
+
void upb_Arena_LogFree(const upb_Arena* arena) {
|
4213
|
+
if (_free_arena_trace_handler) {
|
4214
|
+
_free_arena_trace_handler(arena);
|
4215
|
+
}
|
4216
|
+
}
|
4217
|
+
#endif // UPB_TRACING_ENABLED
|
4218
|
+
|
4050
4219
|
static upb_ArenaRoot _upb_Arena_FindRoot(upb_Arena* a) {
|
4051
4220
|
upb_ArenaInternal* ai = upb_Arena_Internal(a);
|
4052
4221
|
uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire);
|
@@ -4104,6 +4273,21 @@ size_t upb_Arena_SpaceAllocated(upb_Arena* arena, size_t* fused_count) {
|
|
4104
4273
|
return memsize;
|
4105
4274
|
}
|
4106
4275
|
|
4276
|
+
bool UPB_PRIVATE(_upb_Arena_Contains)(const upb_Arena* a, void* ptr) {
|
4277
|
+
upb_ArenaInternal* ai = upb_Arena_Internal(a);
|
4278
|
+
UPB_ASSERT(ai);
|
4279
|
+
|
4280
|
+
upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_relaxed);
|
4281
|
+
while (block) {
|
4282
|
+
uintptr_t beg = (uintptr_t)block;
|
4283
|
+
uintptr_t end = beg + block->size;
|
4284
|
+
if ((uintptr_t)ptr >= beg && (uintptr_t)ptr < end) return true;
|
4285
|
+
block = upb_Atomic_Load(&block->next, memory_order_relaxed);
|
4286
|
+
}
|
4287
|
+
|
4288
|
+
return false;
|
4289
|
+
}
|
4290
|
+
|
4107
4291
|
uint32_t upb_Arena_DebugRefCount(upb_Arena* a) {
|
4108
4292
|
upb_ArenaInternal* ai = upb_Arena_Internal(a);
|
4109
4293
|
// These loads could probably be relaxed, but given that this is debug-only,
|
@@ -4195,7 +4379,13 @@ upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) {
|
|
4195
4379
|
n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_ArenaState));
|
4196
4380
|
|
4197
4381
|
if (UPB_UNLIKELY(n < sizeof(upb_ArenaState))) {
|
4382
|
+
#ifdef UPB_TRACING_ENABLED
|
4383
|
+
upb_Arena* ret = _upb_Arena_InitSlow(alloc);
|
4384
|
+
upb_Arena_LogInit(ret, n);
|
4385
|
+
return ret;
|
4386
|
+
#else
|
4198
4387
|
return _upb_Arena_InitSlow(alloc);
|
4388
|
+
#endif
|
4199
4389
|
}
|
4200
4390
|
|
4201
4391
|
a = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), upb_ArenaState);
|
@@ -4208,13 +4398,14 @@ upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) {
|
|
4208
4398
|
a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 1);
|
4209
4399
|
a->head.UPB_PRIVATE(ptr) = mem;
|
4210
4400
|
a->head.UPB_PRIVATE(end) = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), char);
|
4211
|
-
|
4401
|
+
#ifdef UPB_TRACING_ENABLED
|
4402
|
+
upb_Arena_LogInit(&a->head, n);
|
4403
|
+
#endif
|
4212
4404
|
return &a->head;
|
4213
4405
|
}
|
4214
4406
|
|
4215
4407
|
static void _upb_Arena_DoFree(upb_ArenaInternal* ai) {
|
4216
4408
|
UPB_ASSERT(_upb_Arena_RefCountFromTagged(ai->parent_or_count) == 1);
|
4217
|
-
|
4218
4409
|
while (ai != NULL) {
|
4219
4410
|
// Load first since arena itself is likely from one of its blocks.
|
4220
4411
|
upb_ArenaInternal* next_arena =
|
@@ -4245,6 +4436,9 @@ retry:
|
|
4245
4436
|
// expensive then direct loads. As an optimization, we only do RMW ops
|
4246
4437
|
// when we need to update things for other threads to see.
|
4247
4438
|
if (poc == _upb_Arena_TaggedFromRefcount(1)) {
|
4439
|
+
#ifdef UPB_TRACING_ENABLED
|
4440
|
+
upb_Arena_LogFree(a);
|
4441
|
+
#endif
|
4248
4442
|
_upb_Arena_DoFree(ai);
|
4249
4443
|
return;
|
4250
4444
|
}
|
@@ -4364,6 +4558,10 @@ static bool _upb_Arena_FixupRefs(upb_ArenaInternal* new_root,
|
|
4364
4558
|
bool upb_Arena_Fuse(upb_Arena* a1, upb_Arena* a2) {
|
4365
4559
|
if (a1 == a2) return true; // trivial fuse
|
4366
4560
|
|
4561
|
+
#ifdef UPB_TRACING_ENABLED
|
4562
|
+
upb_Arena_LogFuse(a1, a2);
|
4563
|
+
#endif
|
4564
|
+
|
4367
4565
|
upb_ArenaInternal* ai1 = upb_Arena_Internal(a1);
|
4368
4566
|
upb_ArenaInternal* ai2 = upb_Arena_Internal(a2);
|
4369
4567
|
|
@@ -4430,18 +4628,19 @@ void UPB_PRIVATE(_upb_Arena_SwapOut)(upb_Arena* des, const upb_Arena* src) {
|
|
4430
4628
|
|
4431
4629
|
// Must be last.
|
4432
4630
|
|
4433
|
-
bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable*
|
4631
|
+
bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* m,
|
4434
4632
|
const upb_MiniTableField* f,
|
4435
4633
|
upb_Message* map_entry_message, upb_Arena* arena) {
|
4634
|
+
UPB_ASSERT(!upb_Message_IsFrozen(map_entry_message));
|
4635
|
+
|
4436
4636
|
// TODO: use a variant of upb_MiniTable_GetSubMessageTable() here.
|
4437
4637
|
const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message(
|
4438
|
-
|
4638
|
+
m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]);
|
4439
4639
|
UPB_ASSERT(map_entry_mini_table);
|
4440
|
-
UPB_ASSERT(map_entry_mini_table->UPB_PRIVATE(field_count) == 2);
|
4441
4640
|
const upb_MiniTableField* map_entry_key_field =
|
4442
|
-
|
4641
|
+
upb_MiniTable_MapKey(map_entry_mini_table);
|
4443
4642
|
const upb_MiniTableField* map_entry_value_field =
|
4444
|
-
|
4643
|
+
upb_MiniTable_MapValue(map_entry_mini_table);
|
4445
4644
|
// Map key/value cannot have explicit defaults,
|
4446
4645
|
// hence assuming a zero default is valid.
|
4447
4646
|
upb_MessageValue default_val;
|
@@ -4466,31 +4665,33 @@ upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) {
|
|
4466
4665
|
}
|
4467
4666
|
|
4468
4667
|
upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) {
|
4668
|
+
UPB_ASSERT(i < upb_Array_Size(arr));
|
4469
4669
|
upb_MessageValue ret;
|
4470
4670
|
const char* data = upb_Array_DataPtr(arr);
|
4471
4671
|
const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr);
|
4472
|
-
UPB_ASSERT(i < arr->UPB_PRIVATE(size));
|
4473
4672
|
memcpy(&ret, data + (i << lg2), 1 << lg2);
|
4474
4673
|
return ret;
|
4475
4674
|
}
|
4476
4675
|
|
4477
4676
|
upb_MutableMessageValue upb_Array_GetMutable(upb_Array* arr, size_t i) {
|
4677
|
+
UPB_ASSERT(i < upb_Array_Size(arr));
|
4478
4678
|
upb_MutableMessageValue ret;
|
4479
4679
|
char* data = upb_Array_MutableDataPtr(arr);
|
4480
4680
|
const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr);
|
4481
|
-
UPB_ASSERT(i < arr->UPB_PRIVATE(size));
|
4482
4681
|
memcpy(&ret, data + (i << lg2), 1 << lg2);
|
4483
4682
|
return ret;
|
4484
4683
|
}
|
4485
4684
|
|
4486
4685
|
void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) {
|
4686
|
+
UPB_ASSERT(!upb_Array_IsFrozen(arr));
|
4687
|
+
UPB_ASSERT(i < upb_Array_Size(arr));
|
4487
4688
|
char* data = upb_Array_MutableDataPtr(arr);
|
4488
4689
|
const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr);
|
4489
|
-
UPB_ASSERT(i < arr->UPB_PRIVATE(size));
|
4490
4690
|
memcpy(data + (i << lg2), &val, 1 << lg2);
|
4491
4691
|
}
|
4492
4692
|
|
4493
4693
|
bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) {
|
4694
|
+
UPB_ASSERT(!upb_Array_IsFrozen(arr));
|
4494
4695
|
UPB_ASSERT(arena);
|
4495
4696
|
if (!UPB_PRIVATE(_upb_Array_ResizeUninitialized)(
|
4496
4697
|
arr, arr->UPB_PRIVATE(size) + 1, arena)) {
|
@@ -4502,6 +4703,7 @@ bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) {
|
|
4502
4703
|
|
4503
4704
|
void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx,
|
4504
4705
|
size_t count) {
|
4706
|
+
UPB_ASSERT(!upb_Array_IsFrozen(arr));
|
4505
4707
|
const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr);
|
4506
4708
|
char* data = upb_Array_MutableDataPtr(arr);
|
4507
4709
|
memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2);
|
@@ -4509,6 +4711,7 @@ void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx,
|
|
4509
4711
|
|
4510
4712
|
bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count,
|
4511
4713
|
upb_Arena* arena) {
|
4714
|
+
UPB_ASSERT(!upb_Array_IsFrozen(arr));
|
4512
4715
|
UPB_ASSERT(arena);
|
4513
4716
|
UPB_ASSERT(i <= arr->UPB_PRIVATE(size));
|
4514
4717
|
UPB_ASSERT(count + arr->UPB_PRIVATE(size) >= count);
|
@@ -4526,6 +4729,7 @@ bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count,
|
|
4526
4729
|
* |------------|XXXXXXXX|--------|
|
4527
4730
|
*/
|
4528
4731
|
void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) {
|
4732
|
+
UPB_ASSERT(!upb_Array_IsFrozen(arr));
|
4529
4733
|
const size_t end = i + count;
|
4530
4734
|
UPB_ASSERT(i <= end);
|
4531
4735
|
UPB_ASSERT(end <= arr->UPB_PRIVATE(size));
|
@@ -4534,6 +4738,7 @@ void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) {
|
|
4534
4738
|
}
|
4535
4739
|
|
4536
4740
|
bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) {
|
4741
|
+
UPB_ASSERT(!upb_Array_IsFrozen(arr));
|
4537
4742
|
const size_t oldsize = arr->UPB_PRIVATE(size);
|
4538
4743
|
if (UPB_UNLIKELY(
|
4539
4744
|
!UPB_PRIVATE(_upb_Array_ResizeUninitialized)(arr, size, arena))) {
|
@@ -4567,6 +4772,20 @@ bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity,
|
|
4567
4772
|
return true;
|
4568
4773
|
}
|
4569
4774
|
|
4775
|
+
void upb_Array_Freeze(upb_Array* arr, const upb_MiniTable* m) {
|
4776
|
+
if (upb_Array_IsFrozen(arr)) return;
|
4777
|
+
UPB_PRIVATE(_upb_Array_ShallowFreeze)(arr);
|
4778
|
+
|
4779
|
+
if (m) {
|
4780
|
+
const size_t size = upb_Array_Size(arr);
|
4781
|
+
|
4782
|
+
for (size_t i = 0; i < size; i++) {
|
4783
|
+
upb_MessageValue val = upb_Array_Get(arr, i);
|
4784
|
+
upb_Message_Freeze((upb_Message*)val.msg_val, m);
|
4785
|
+
}
|
4786
|
+
}
|
4787
|
+
}
|
4788
|
+
|
4570
4789
|
|
4571
4790
|
#include <stddef.h>
|
4572
4791
|
#include <stdint.h>
|
@@ -4583,19 +4802,20 @@ const upb_MiniTableExtension* upb_Message_ExtensionByIndex(
|
|
4583
4802
|
return ext[index].ext;
|
4584
4803
|
}
|
4585
4804
|
|
4586
|
-
const
|
4587
|
-
|
4805
|
+
const upb_MiniTableExtension* upb_Message_FindExtensionByNumber(
|
4806
|
+
const upb_Message* msg, uint32_t field_number) {
|
4588
4807
|
size_t count;
|
4589
4808
|
const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count);
|
4590
4809
|
|
4591
|
-
|
4592
|
-
|
4593
|
-
|
4810
|
+
for (; count--; ext++) {
|
4811
|
+
const upb_MiniTableExtension* e = ext->ext;
|
4812
|
+
if (upb_MiniTableExtension_Number(e) == field_number) return e;
|
4594
4813
|
}
|
4595
4814
|
return NULL;
|
4596
4815
|
}
|
4597
4816
|
|
4598
4817
|
|
4818
|
+
#include <stdint.h>
|
4599
4819
|
#include <string.h>
|
4600
4820
|
|
4601
4821
|
|
@@ -4694,6 +4914,20 @@ upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter) {
|
|
4694
4914
|
return ret;
|
4695
4915
|
}
|
4696
4916
|
|
4917
|
+
void upb_Map_Freeze(upb_Map* map, const upb_MiniTable* m) {
|
4918
|
+
if (upb_Map_IsFrozen(map)) return;
|
4919
|
+
UPB_PRIVATE(_upb_Map_ShallowFreeze)(map);
|
4920
|
+
|
4921
|
+
if (m) {
|
4922
|
+
size_t iter = kUpb_Map_Begin;
|
4923
|
+
upb_MessageValue key, val;
|
4924
|
+
|
4925
|
+
while (upb_Map_Next(map, &key, &val, &iter)) {
|
4926
|
+
upb_Message_Freeze((upb_Message*)val.msg_val, m);
|
4927
|
+
}
|
4928
|
+
}
|
4929
|
+
}
|
4930
|
+
|
4697
4931
|
// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE /////////////////////////
|
4698
4932
|
|
4699
4933
|
upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) {
|
@@ -4703,6 +4937,7 @@ upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) {
|
|
4703
4937
|
upb_strtable_init(&map->table, 4, a);
|
4704
4938
|
map->key_size = key_size;
|
4705
4939
|
map->val_size = value_size;
|
4940
|
+
map->UPB_PRIVATE(is_frozen) = false;
|
4706
4941
|
|
4707
4942
|
return map;
|
4708
4943
|
}
|
@@ -4866,22 +5101,24 @@ upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* a) {
|
|
4866
5101
|
|
4867
5102
|
bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data,
|
4868
5103
|
size_t len, upb_Arena* arena) {
|
5104
|
+
UPB_ASSERT(!upb_Message_IsFrozen(msg));
|
4869
5105
|
if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, len, arena)) return false;
|
4870
|
-
upb_Message_Internal* in = msg
|
5106
|
+
upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
|
4871
5107
|
memcpy(UPB_PTR_AT(in, in->unknown_end, char), data, len);
|
4872
5108
|
in->unknown_end += len;
|
4873
5109
|
return true;
|
4874
5110
|
}
|
4875
5111
|
|
4876
5112
|
void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) {
|
4877
|
-
|
5113
|
+
UPB_ASSERT(!upb_Message_IsFrozen(msg));
|
5114
|
+
upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
|
4878
5115
|
if (in) {
|
4879
5116
|
in->unknown_end = message_overhead;
|
4880
5117
|
}
|
4881
5118
|
}
|
4882
5119
|
|
4883
5120
|
const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) {
|
4884
|
-
upb_Message_Internal* in = msg
|
5121
|
+
upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
|
4885
5122
|
if (in) {
|
4886
5123
|
*len = in->unknown_end - message_overhead;
|
4887
5124
|
return (char*)(in + 1);
|
@@ -4892,7 +5129,8 @@ const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) {
|
|
4892
5129
|
}
|
4893
5130
|
|
4894
5131
|
void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) {
|
4895
|
-
|
5132
|
+
UPB_ASSERT(!upb_Message_IsFrozen(msg));
|
5133
|
+
upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
|
4896
5134
|
const char* internal_unknown_end = UPB_PTR_AT(in, in->unknown_end, char);
|
4897
5135
|
|
4898
5136
|
#ifndef NDEBUG
|
@@ -4916,35 +5154,296 @@ size_t upb_Message_ExtensionCount(const upb_Message* msg) {
|
|
4916
5154
|
return count;
|
4917
5155
|
}
|
4918
5156
|
|
5157
|
+
void upb_Message_Freeze(upb_Message* msg, const upb_MiniTable* m) {
|
5158
|
+
if (upb_Message_IsFrozen(msg)) return;
|
5159
|
+
UPB_PRIVATE(_upb_Message_ShallowFreeze)(msg);
|
4919
5160
|
|
4920
|
-
|
5161
|
+
// Base Fields.
|
5162
|
+
const size_t field_count = upb_MiniTable_FieldCount(m);
|
5163
|
+
|
5164
|
+
for (size_t i = 0; i < field_count; i++) {
|
5165
|
+
const upb_MiniTableField* f = upb_MiniTable_GetFieldByIndex(m, i);
|
5166
|
+
const upb_MiniTable* m2 = upb_MiniTable_SubMessage(m, f);
|
5167
|
+
|
5168
|
+
switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(f)) {
|
5169
|
+
case kUpb_FieldMode_Array: {
|
5170
|
+
upb_Array* arr = upb_Message_GetMutableArray(msg, f);
|
5171
|
+
if (arr) upb_Array_Freeze(arr, m2);
|
5172
|
+
break;
|
5173
|
+
}
|
5174
|
+
case kUpb_FieldMode_Map: {
|
5175
|
+
upb_Map* map = upb_Message_GetMutableMap(msg, f);
|
5176
|
+
if (map) {
|
5177
|
+
const upb_MiniTableField* f2 = upb_MiniTable_MapValue(m2);
|
5178
|
+
const upb_MiniTable* m3 = upb_MiniTable_SubMessage(m2, f2);
|
5179
|
+
upb_Map_Freeze(map, m3);
|
5180
|
+
}
|
5181
|
+
break;
|
5182
|
+
}
|
5183
|
+
case kUpb_FieldMode_Scalar: {
|
5184
|
+
if (m2) {
|
5185
|
+
upb_Message* msg2 = upb_Message_GetMutableMessage(msg, f);
|
5186
|
+
if (msg2) upb_Message_Freeze(msg2, m2);
|
5187
|
+
}
|
5188
|
+
break;
|
5189
|
+
}
|
5190
|
+
}
|
5191
|
+
}
|
5192
|
+
|
5193
|
+
// Extensions.
|
5194
|
+
size_t ext_count;
|
5195
|
+
const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &ext_count);
|
5196
|
+
|
5197
|
+
for (size_t i = 0; i < ext_count; i++) {
|
5198
|
+
const upb_MiniTableExtension* e = ext[i].ext;
|
5199
|
+
const upb_MiniTableField* f = &e->UPB_PRIVATE(field);
|
5200
|
+
const upb_MiniTable* m2 = upb_MiniTableExtension_GetSubMessage(e);
|
5201
|
+
|
5202
|
+
upb_MessageValue val;
|
5203
|
+
memcpy(&val, &ext[i].data, sizeof(upb_MessageValue));
|
5204
|
+
|
5205
|
+
switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(f)) {
|
5206
|
+
case kUpb_FieldMode_Array: {
|
5207
|
+
upb_Array* arr = (upb_Array*)val.array_val;
|
5208
|
+
if (arr) upb_Array_Freeze(arr, m2);
|
5209
|
+
break;
|
5210
|
+
}
|
5211
|
+
case kUpb_FieldMode_Map:
|
5212
|
+
UPB_UNREACHABLE(); // Maps cannot be extensions.
|
5213
|
+
break;
|
5214
|
+
case kUpb_FieldMode_Scalar:
|
5215
|
+
if (upb_MiniTableField_IsSubMessage(f)) {
|
5216
|
+
upb_Message* msg2 = (upb_Message*)val.msg_val;
|
5217
|
+
if (msg2) upb_Message_Freeze(msg2, m2);
|
5218
|
+
}
|
5219
|
+
break;
|
5220
|
+
}
|
5221
|
+
}
|
5222
|
+
}
|
5223
|
+
|
5224
|
+
|
5225
|
+
#include <stddef.h>
|
4921
5226
|
|
4922
5227
|
|
4923
5228
|
// Must be last.
|
4924
5229
|
|
4925
|
-
|
4926
|
-
|
4927
|
-
|
4928
|
-
|
5230
|
+
#define kUpb_BaseField_Begin ((size_t)-1)
|
5231
|
+
#define kUpb_Extension_Begin ((size_t)-1)
|
5232
|
+
|
5233
|
+
#ifdef __cplusplus
|
5234
|
+
extern "C" {
|
5235
|
+
#endif
|
5236
|
+
|
5237
|
+
static bool _upb_Message_NextBaseField(const upb_Message* msg,
|
5238
|
+
const upb_MiniTable* m,
|
5239
|
+
const upb_MiniTableField** out_f,
|
5240
|
+
upb_MessageValue* out_v, size_t* iter) {
|
5241
|
+
const size_t count = upb_MiniTable_FieldCount(m);
|
5242
|
+
size_t i = *iter;
|
5243
|
+
|
5244
|
+
while (++i < count) {
|
5245
|
+
const upb_MiniTableField* f = upb_MiniTable_GetFieldByIndex(m, i);
|
5246
|
+
const void* src = UPB_PRIVATE(_upb_Message_DataPtr)(msg, f);
|
5247
|
+
|
5248
|
+
upb_MessageValue val;
|
5249
|
+
UPB_PRIVATE(_upb_MiniTableField_DataCopy)(f, &val, src);
|
5250
|
+
|
5251
|
+
// Skip field if unset or empty.
|
5252
|
+
if (upb_MiniTableField_HasPresence(f)) {
|
5253
|
+
if (!upb_Message_HasBaseField(msg, f)) continue;
|
5254
|
+
} else {
|
5255
|
+
if (UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(f, src)) continue;
|
5256
|
+
|
5257
|
+
if (upb_MiniTableField_IsArray(f)) {
|
5258
|
+
if (upb_Array_Size(val.array_val) == 0) continue;
|
5259
|
+
} else if (upb_MiniTableField_IsMap(f)) {
|
5260
|
+
if (upb_Map_Size(val.map_val) == 0) continue;
|
5261
|
+
}
|
5262
|
+
}
|
5263
|
+
|
5264
|
+
*out_f = f;
|
5265
|
+
*out_v = val;
|
5266
|
+
*iter = i;
|
5267
|
+
return true;
|
5268
|
+
}
|
5269
|
+
|
5270
|
+
return false;
|
5271
|
+
}
|
5272
|
+
|
5273
|
+
static bool _upb_Message_NextExtension(const upb_Message* msg,
|
5274
|
+
const upb_MiniTable* m,
|
5275
|
+
const upb_MiniTableExtension** out_e,
|
5276
|
+
upb_MessageValue* out_v, size_t* iter) {
|
5277
|
+
size_t count;
|
5278
|
+
const upb_Extension* exts = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count);
|
5279
|
+
size_t i = *iter;
|
5280
|
+
|
5281
|
+
if (++i < count) {
|
5282
|
+
*out_e = exts[i].ext;
|
5283
|
+
*out_v = exts[i].data;
|
5284
|
+
*iter = i;
|
5285
|
+
return true;
|
5286
|
+
}
|
5287
|
+
|
5288
|
+
return false;
|
5289
|
+
}
|
5290
|
+
|
5291
|
+
bool upb_Message_IsEmpty(const upb_Message* msg, const upb_MiniTable* m) {
|
5292
|
+
if (upb_Message_ExtensionCount(msg)) return false;
|
5293
|
+
|
5294
|
+
const upb_MiniTableField* f;
|
5295
|
+
upb_MessageValue v;
|
5296
|
+
size_t iter = kUpb_BaseField_Begin;
|
5297
|
+
return !_upb_Message_NextBaseField(msg, m, &f, &v, &iter);
|
5298
|
+
}
|
5299
|
+
|
5300
|
+
static bool _upb_Array_IsEqual(const upb_Array* arr1, const upb_Array* arr2,
|
5301
|
+
upb_CType ctype, const upb_MiniTable* m,
|
5302
|
+
int options) {
|
5303
|
+
// Check for trivial equality.
|
5304
|
+
if (arr1 == arr2) return true;
|
5305
|
+
|
5306
|
+
// Must have identical element counts.
|
5307
|
+
const size_t size1 = arr1 ? upb_Array_Size(arr1) : 0;
|
5308
|
+
const size_t size2 = arr2 ? upb_Array_Size(arr2) : 0;
|
5309
|
+
if (size1 != size2) return false;
|
5310
|
+
|
5311
|
+
for (size_t i = 0; i < size1; i++) {
|
5312
|
+
const upb_MessageValue val1 = upb_Array_Get(arr1, i);
|
5313
|
+
const upb_MessageValue val2 = upb_Array_Get(arr2, i);
|
5314
|
+
|
5315
|
+
if (!upb_MessageValue_IsEqual(val1, val2, ctype, m, options)) return false;
|
5316
|
+
}
|
5317
|
+
|
5318
|
+
return true;
|
5319
|
+
}
|
5320
|
+
|
5321
|
+
static bool _upb_Map_IsEqual(const upb_Map* map1, const upb_Map* map2,
|
5322
|
+
const upb_MiniTable* m, int options) {
|
5323
|
+
// Check for trivial equality.
|
5324
|
+
if (map1 == map2) return true;
|
5325
|
+
|
5326
|
+
// Must have identical element counts.
|
5327
|
+
size_t size1 = map1 ? upb_Map_Size(map1) : 0;
|
5328
|
+
size_t size2 = map2 ? upb_Map_Size(map2) : 0;
|
5329
|
+
if (size1 != size2) return false;
|
5330
|
+
|
5331
|
+
const upb_MiniTableField* f = upb_MiniTable_MapValue(m);
|
5332
|
+
const upb_MiniTable* m2_value = upb_MiniTable_SubMessage(m, f);
|
5333
|
+
const upb_CType ctype = upb_MiniTableField_CType(f);
|
5334
|
+
|
5335
|
+
upb_MessageValue key, val1, val2;
|
5336
|
+
size_t iter = kUpb_Map_Begin;
|
5337
|
+
while (upb_Map_Next(map1, &key, &val1, &iter)) {
|
5338
|
+
if (!upb_Map_Get(map2, key, &val2)) return false;
|
5339
|
+
if (!upb_MessageValue_IsEqual(val1, val2, ctype, m2_value, options))
|
5340
|
+
return false;
|
5341
|
+
}
|
5342
|
+
|
5343
|
+
return true;
|
5344
|
+
}
|
5345
|
+
|
5346
|
+
static bool _upb_Message_BaseFieldsAreEqual(const upb_Message* msg1,
|
5347
|
+
const upb_Message* msg2,
|
5348
|
+
const upb_MiniTable* m,
|
5349
|
+
int options) {
|
5350
|
+
// Iterate over all base fields for each message.
|
5351
|
+
// The order will always match if the messages are equal.
|
5352
|
+
size_t iter1 = kUpb_BaseField_Begin;
|
5353
|
+
size_t iter2 = kUpb_BaseField_Begin;
|
5354
|
+
|
5355
|
+
for (;;) {
|
5356
|
+
const upb_MiniTableField *f1, *f2;
|
5357
|
+
upb_MessageValue val1, val2;
|
4929
5358
|
|
4930
|
-
|
4931
|
-
|
5359
|
+
const bool got1 = _upb_Message_NextBaseField(msg1, m, &f1, &val1, &iter1);
|
5360
|
+
const bool got2 = _upb_Message_NextBaseField(msg2, m, &f2, &val2, &iter2);
|
4932
5361
|
|
4933
|
-
|
4934
|
-
|
4935
|
-
|
4936
|
-
upb_EncodeStatus status1 = upb_Encode(msg1, m, opts, a, &data1, &size1);
|
4937
|
-
upb_EncodeStatus status2 = upb_Encode(msg2, m, opts, a, &data2, &size2);
|
5362
|
+
if (got1 != got2) return false; // Must have identical field counts.
|
5363
|
+
if (!got1) return true; // Loop termination condition.
|
5364
|
+
if (f1 != f2) return false; // Must have identical fields set.
|
4938
5365
|
|
4939
|
-
|
4940
|
-
|
4941
|
-
|
5366
|
+
const upb_MiniTable* subm = upb_MiniTable_SubMessage(m, f1);
|
5367
|
+
const upb_CType ctype = upb_MiniTableField_CType(f1);
|
5368
|
+
|
5369
|
+
bool eq;
|
5370
|
+
switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(f1)) {
|
5371
|
+
case kUpb_FieldMode_Array:
|
5372
|
+
eq = _upb_Array_IsEqual(val1.array_val, val2.array_val, ctype, subm,
|
5373
|
+
options);
|
5374
|
+
break;
|
5375
|
+
case kUpb_FieldMode_Map:
|
5376
|
+
eq = _upb_Map_IsEqual(val1.map_val, val2.map_val, subm, options);
|
5377
|
+
break;
|
5378
|
+
case kUpb_FieldMode_Scalar:
|
5379
|
+
eq = upb_MessageValue_IsEqual(val1, val2, ctype, subm, options);
|
5380
|
+
break;
|
5381
|
+
}
|
5382
|
+
if (!eq) return false;
|
5383
|
+
}
|
5384
|
+
}
|
5385
|
+
|
5386
|
+
static bool _upb_Message_ExtensionsAreEqual(const upb_Message* msg1,
|
5387
|
+
const upb_Message* msg2,
|
5388
|
+
const upb_MiniTable* m,
|
5389
|
+
int options) {
|
5390
|
+
// Must have identical extension counts.
|
5391
|
+
if (upb_Message_ExtensionCount(msg1) != upb_Message_ExtensionCount(msg2)) {
|
4942
5392
|
return false;
|
4943
5393
|
}
|
4944
5394
|
|
4945
|
-
const
|
4946
|
-
|
4947
|
-
|
5395
|
+
const upb_MiniTableExtension* e;
|
5396
|
+
upb_MessageValue val1;
|
5397
|
+
|
5398
|
+
// Iterate over all extensions for msg1, and search msg2 for each extension.
|
5399
|
+
size_t iter1 = kUpb_Extension_Begin;
|
5400
|
+
while (_upb_Message_NextExtension(msg1, m, &e, &val1, &iter1)) {
|
5401
|
+
const upb_Extension* ext2 = UPB_PRIVATE(_upb_Message_Getext)(msg2, e);
|
5402
|
+
if (!ext2) return false;
|
5403
|
+
|
5404
|
+
const upb_MessageValue val2 = ext2->data;
|
5405
|
+
const upb_MiniTableField* f = &e->UPB_PRIVATE(field);
|
5406
|
+
const upb_MiniTable* subm = upb_MiniTableField_IsSubMessage(f)
|
5407
|
+
? upb_MiniTableExtension_GetSubMessage(e)
|
5408
|
+
: NULL;
|
5409
|
+
const upb_CType ctype = upb_MiniTableField_CType(f);
|
5410
|
+
|
5411
|
+
bool eq;
|
5412
|
+
switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(f)) {
|
5413
|
+
case kUpb_FieldMode_Array:
|
5414
|
+
eq = _upb_Array_IsEqual(val1.array_val, val2.array_val, ctype, subm,
|
5415
|
+
options);
|
5416
|
+
break;
|
5417
|
+
case kUpb_FieldMode_Map:
|
5418
|
+
UPB_UNREACHABLE(); // Maps cannot be extensions.
|
5419
|
+
break;
|
5420
|
+
case kUpb_FieldMode_Scalar: {
|
5421
|
+
eq = upb_MessageValue_IsEqual(val1, val2, ctype, subm, options);
|
5422
|
+
break;
|
5423
|
+
}
|
5424
|
+
}
|
5425
|
+
if (!eq) return false;
|
5426
|
+
}
|
5427
|
+
return true;
|
5428
|
+
}
|
5429
|
+
|
5430
|
+
bool upb_Message_IsEqual(const upb_Message* msg1, const upb_Message* msg2,
|
5431
|
+
const upb_MiniTable* m, int options) {
|
5432
|
+
if (UPB_UNLIKELY(msg1 == msg2)) return true;
|
5433
|
+
|
5434
|
+
if (!_upb_Message_BaseFieldsAreEqual(msg1, msg2, m, options)) return false;
|
5435
|
+
if (!_upb_Message_ExtensionsAreEqual(msg1, msg2, m, options)) return false;
|
5436
|
+
|
5437
|
+
if (!(options & kUpb_CompareOption_IncludeUnknownFields)) return true;
|
5438
|
+
|
5439
|
+
// Check the unknown fields.
|
5440
|
+
size_t usize1, usize2;
|
5441
|
+
const char* uf1 = upb_Message_GetUnknown(msg1, &usize1);
|
5442
|
+
const char* uf2 = upb_Message_GetUnknown(msg2, &usize2);
|
5443
|
+
|
5444
|
+
// The wire encoder enforces a maximum depth of 100 so we match that here.
|
5445
|
+
return UPB_PRIVATE(_upb_Message_UnknownFieldsAreEqual)(
|
5446
|
+
uf1, usize1, uf2, usize2, 100) == kUpb_UnknownCompareResult_Equal;
|
4948
5447
|
}
|
4949
5448
|
|
4950
5449
|
|
@@ -5018,7 +5517,7 @@ upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type,
|
|
5018
5517
|
size_t iter = kUpb_Map_Begin;
|
5019
5518
|
while (upb_Map_Next(map, &key, &val, &iter)) {
|
5020
5519
|
const upb_MiniTableField* value_field =
|
5021
|
-
|
5520
|
+
upb_MiniTable_MapValue(map_entry_table);
|
5022
5521
|
const upb_MiniTable* value_sub =
|
5023
5522
|
upb_MiniTableField_CType(value_field) == kUpb_CType_Message
|
5024
5523
|
? upb_MiniTable_GetSubMessageTable(map_entry_table, value_field)
|
@@ -5044,10 +5543,9 @@ static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map,
|
|
5044
5543
|
mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]);
|
5045
5544
|
UPB_ASSERT(map_entry_table);
|
5046
5545
|
|
5047
|
-
const upb_MiniTableField* key_field =
|
5048
|
-
&map_entry_table->UPB_PRIVATE(fields)[0];
|
5546
|
+
const upb_MiniTableField* key_field = upb_MiniTable_MapKey(map_entry_table);
|
5049
5547
|
const upb_MiniTableField* value_field =
|
5050
|
-
|
5548
|
+
upb_MiniTable_MapValue(map_entry_table);
|
5051
5549
|
|
5052
5550
|
upb_Map* cloned_map = upb_Map_DeepClone(
|
5053
5551
|
map, upb_MiniTableField_CType(key_field),
|
@@ -5055,13 +5553,13 @@ static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map,
|
|
5055
5553
|
if (!cloned_map) {
|
5056
5554
|
return NULL;
|
5057
5555
|
}
|
5058
|
-
|
5556
|
+
upb_Message_SetBaseField(clone, f, &cloned_map);
|
5059
5557
|
return cloned_map;
|
5060
5558
|
}
|
5061
5559
|
|
5062
5560
|
upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type,
|
5063
5561
|
const upb_MiniTable* sub, upb_Arena* arena) {
|
5064
|
-
const size_t size = array
|
5562
|
+
const size_t size = upb_Array_Size(array);
|
5065
5563
|
const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(value_type);
|
5066
5564
|
upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, lg2);
|
5067
5565
|
if (!cloned_array) {
|
@@ -5093,7 +5591,7 @@ static bool upb_Message_Array_DeepClone(const upb_Array* array,
|
|
5093
5591
|
arena);
|
5094
5592
|
|
5095
5593
|
// Clear out upb_Array* due to parent memcpy.
|
5096
|
-
|
5594
|
+
upb_Message_SetBaseField(clone, field, &cloned_array);
|
5097
5595
|
return true;
|
5098
5596
|
}
|
5099
5597
|
|
@@ -5102,8 +5600,7 @@ static bool upb_Clone_ExtensionValue(
|
|
5102
5600
|
upb_Extension* dest, upb_Arena* arena) {
|
5103
5601
|
dest->data = source->data;
|
5104
5602
|
return upb_Clone_MessageValue(
|
5105
|
-
&dest->data,
|
5106
|
-
upb_MiniTableField_CType(&mini_table_ext->UPB_PRIVATE(field)),
|
5603
|
+
&dest->data, upb_MiniTableExtension_CType(mini_table_ext),
|
5107
5604
|
upb_MiniTableExtension_GetSubMessage(mini_table_ext), arena);
|
5108
5605
|
}
|
5109
5606
|
|
@@ -5113,8 +5610,9 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
|
|
5113
5610
|
upb_StringView empty_string = upb_StringView_FromDataAndSize(NULL, 0);
|
5114
5611
|
// Only copy message area skipping upb_Message_Internal.
|
5115
5612
|
memcpy(dst + 1, src + 1, mini_table->UPB_PRIVATE(size) - sizeof(upb_Message));
|
5116
|
-
for (
|
5117
|
-
const upb_MiniTableField* field =
|
5613
|
+
for (int i = 0; i < upb_MiniTable_FieldCount(mini_table); ++i) {
|
5614
|
+
const upb_MiniTableField* field =
|
5615
|
+
upb_MiniTable_GetFieldByIndex(mini_table, i);
|
5118
5616
|
if (upb_MiniTableField_IsScalar(field)) {
|
5119
5617
|
switch (upb_MiniTableField_CType(field)) {
|
5120
5618
|
case kUpb_CType_Message: {
|
@@ -5188,7 +5686,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
|
|
5188
5686
|
return NULL;
|
5189
5687
|
}
|
5190
5688
|
} else {
|
5191
|
-
upb_Array* msg_array = (upb_Array*)msg_ext->data.
|
5689
|
+
upb_Array* msg_array = (upb_Array*)msg_ext->data.array_val;
|
5192
5690
|
UPB_ASSERT(msg_array);
|
5193
5691
|
upb_Array* cloned_array = upb_Array_DeepClone(
|
5194
5692
|
msg_array, upb_MiniTableField_CType(field),
|
@@ -5196,7 +5694,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
|
|
5196
5694
|
if (!cloned_array) {
|
5197
5695
|
return NULL;
|
5198
5696
|
}
|
5199
|
-
dst_ext->data.
|
5697
|
+
dst_ext->data.array_val = cloned_array;
|
5200
5698
|
}
|
5201
5699
|
}
|
5202
5700
|
|
@@ -5348,9 +5846,9 @@ static upb_MiniTableEnum* upb_MtDecoder_BuildMiniTableEnum(
|
|
5348
5846
|
return upb_MtDecoder_DoBuildMiniTableEnum(decoder, data, len);
|
5349
5847
|
}
|
5350
5848
|
|
5351
|
-
upb_MiniTableEnum*
|
5352
|
-
|
5353
|
-
|
5849
|
+
upb_MiniTableEnum* upb_MiniTableEnum_Build(const char* data, size_t len,
|
5850
|
+
upb_Arena* arena,
|
5851
|
+
upb_Status* status) {
|
5354
5852
|
upb_MdEnumDecoder decoder = {
|
5355
5853
|
.base =
|
5356
5854
|
{
|
@@ -5391,7 +5889,7 @@ typedef enum {
|
|
5391
5889
|
kUpb_LayoutItemType_Max = kUpb_LayoutItemType_Field,
|
5392
5890
|
} upb_LayoutItemType;
|
5393
5891
|
|
5394
|
-
#define kUpb_LayoutItem_IndexSentinel ((uint16_t)-1)
|
5892
|
+
#define kUpb_LayoutItem_IndexSentinel ((uint16_t) - 1)
|
5395
5893
|
|
5396
5894
|
typedef struct {
|
5397
5895
|
// Index of the corresponding field. When this is a oneof field, the field's
|
@@ -5588,6 +6086,12 @@ static void upb_MtDecoder_ModifyField(upb_MtDecoder* d,
|
|
5588
6086
|
upb_MiniTableField_Number(field));
|
5589
6087
|
}
|
5590
6088
|
|
6089
|
+
if (singular && upb_MiniTableField_IsSubMessage(field)) {
|
6090
|
+
upb_MdDecoder_ErrorJmp(&d->base,
|
6091
|
+
"Field %" PRIu32 " cannot be a singular submessage",
|
6092
|
+
upb_MiniTableField_Number(field));
|
6093
|
+
}
|
6094
|
+
|
5591
6095
|
if (singular) field->UPB_PRIVATE(offset) = kNoPresence;
|
5592
6096
|
if (required) {
|
5593
6097
|
field->UPB_PRIVATE(offset) = kRequiredPresence;
|
@@ -6074,6 +6578,11 @@ static upb_MiniTable* upb_MtDecoder_DoBuildMiniTableWithBuf(
|
|
6074
6578
|
decoder->table->UPB_PRIVATE(dense_below) = 0;
|
6075
6579
|
decoder->table->UPB_PRIVATE(table_mask) = -1;
|
6076
6580
|
decoder->table->UPB_PRIVATE(required_count) = 0;
|
6581
|
+
#if UPB_TRACING_ENABLED
|
6582
|
+
// MiniTables built from MiniDescriptors will not be able to vend the message
|
6583
|
+
// name unless it is explicitly set with upb_MiniTable_SetFullName().
|
6584
|
+
decoder->table->UPB_PRIVATE(full_name) = 0;
|
6585
|
+
#endif
|
6077
6586
|
|
6078
6587
|
// Strip off and verify the version tag.
|
6079
6588
|
if (!len--) goto done;
|
@@ -6292,13 +6801,13 @@ bool upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTableField* field,
|
|
6292
6801
|
return true;
|
6293
6802
|
}
|
6294
6803
|
|
6295
|
-
uint32_t upb_MiniTable_GetSubList(const upb_MiniTable*
|
6804
|
+
uint32_t upb_MiniTable_GetSubList(const upb_MiniTable* m,
|
6296
6805
|
const upb_MiniTableField** subs) {
|
6297
6806
|
uint32_t msg_count = 0;
|
6298
6807
|
uint32_t enum_count = 0;
|
6299
6808
|
|
6300
|
-
for (int i = 0; i <
|
6301
|
-
const upb_MiniTableField* f =
|
6809
|
+
for (int i = 0; i < upb_MiniTable_FieldCount(m); i++) {
|
6810
|
+
const upb_MiniTableField* f = upb_MiniTable_GetFieldByIndex(m, i);
|
6302
6811
|
if (upb_MiniTableField_CType(f) == kUpb_CType_Message) {
|
6303
6812
|
*subs = f;
|
6304
6813
|
++subs;
|
@@ -6306,9 +6815,9 @@ uint32_t upb_MiniTable_GetSubList(const upb_MiniTable* mt,
|
|
6306
6815
|
}
|
6307
6816
|
}
|
6308
6817
|
|
6309
|
-
for (int i = 0; i <
|
6310
|
-
const upb_MiniTableField* f =
|
6311
|
-
if (
|
6818
|
+
for (int i = 0; i < upb_MiniTable_FieldCount(m); i++) {
|
6819
|
+
const upb_MiniTableField* f = upb_MiniTable_GetFieldByIndex(m, i);
|
6820
|
+
if (upb_MiniTableField_IsClosedEnum(f)) {
|
6312
6821
|
*subs = f;
|
6313
6822
|
++subs;
|
6314
6823
|
enum_count++;
|
@@ -6321,36 +6830,34 @@ uint32_t upb_MiniTable_GetSubList(const upb_MiniTable* mt,
|
|
6321
6830
|
// The list of sub_tables and sub_enums must exactly match the number and order
|
6322
6831
|
// of sub-message fields and sub-enum fields given by upb_MiniTable_GetSubList()
|
6323
6832
|
// above.
|
6324
|
-
bool upb_MiniTable_Link(upb_MiniTable*
|
6833
|
+
bool upb_MiniTable_Link(upb_MiniTable* m, const upb_MiniTable** sub_tables,
|
6325
6834
|
size_t sub_table_count,
|
6326
6835
|
const upb_MiniTableEnum** sub_enums,
|
6327
6836
|
size_t sub_enum_count) {
|
6328
6837
|
uint32_t msg_count = 0;
|
6329
6838
|
uint32_t enum_count = 0;
|
6330
6839
|
|
6331
|
-
for (int i = 0; i <
|
6332
|
-
upb_MiniTableField* f =
|
6840
|
+
for (int i = 0; i < upb_MiniTable_FieldCount(m); i++) {
|
6841
|
+
upb_MiniTableField* f =
|
6842
|
+
(upb_MiniTableField*)upb_MiniTable_GetFieldByIndex(m, i);
|
6333
6843
|
if (upb_MiniTableField_CType(f) == kUpb_CType_Message) {
|
6334
6844
|
const upb_MiniTable* sub = sub_tables[msg_count++];
|
6335
6845
|
if (msg_count > sub_table_count) return false;
|
6336
|
-
if (sub
|
6337
|
-
if (!upb_MiniTable_SetSubMessage(mt, f, sub)) return false;
|
6338
|
-
}
|
6846
|
+
if (sub && !upb_MiniTable_SetSubMessage(m, f, sub)) return false;
|
6339
6847
|
}
|
6340
6848
|
}
|
6341
6849
|
|
6342
|
-
for (int i = 0; i <
|
6343
|
-
upb_MiniTableField* f =
|
6850
|
+
for (int i = 0; i < upb_MiniTable_FieldCount(m); i++) {
|
6851
|
+
upb_MiniTableField* f =
|
6852
|
+
(upb_MiniTableField*)upb_MiniTable_GetFieldByIndex(m, i);
|
6344
6853
|
if (upb_MiniTableField_IsClosedEnum(f)) {
|
6345
6854
|
const upb_MiniTableEnum* sub = sub_enums[enum_count++];
|
6346
6855
|
if (enum_count > sub_enum_count) return false;
|
6347
|
-
if (sub
|
6348
|
-
if (!upb_MiniTable_SetSubEnum(mt, f, sub)) return false;
|
6349
|
-
}
|
6856
|
+
if (sub && !upb_MiniTable_SetSubEnum(m, f, sub)) return false;
|
6350
6857
|
}
|
6351
6858
|
}
|
6352
6859
|
|
6353
|
-
return
|
6860
|
+
return (msg_count == sub_table_count) && (enum_count == sub_enum_count);
|
6354
6861
|
}
|
6355
6862
|
|
6356
6863
|
|
@@ -6705,8 +7212,7 @@ static _upb_DecodeLongVarintReturn _upb_Decoder_DecodeLongVarint(
|
|
6705
7212
|
const char* ptr, uint64_t val) {
|
6706
7213
|
_upb_DecodeLongVarintReturn ret = {NULL, 0};
|
6707
7214
|
uint64_t byte;
|
6708
|
-
int i;
|
6709
|
-
for (i = 1; i < 10; i++) {
|
7215
|
+
for (int i = 1; i < 10; i++) {
|
6710
7216
|
byte = (uint8_t)ptr[i];
|
6711
7217
|
val += (byte - 1) << (i * 7);
|
6712
7218
|
if (!(byte & 0x80)) {
|
@@ -6719,8 +7225,8 @@ static _upb_DecodeLongVarintReturn _upb_Decoder_DecodeLongVarint(
|
|
6719
7225
|
}
|
6720
7226
|
|
6721
7227
|
UPB_FORCEINLINE
|
6722
|
-
|
6723
|
-
|
7228
|
+
const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr,
|
7229
|
+
uint64_t* val) {
|
6724
7230
|
uint64_t byte = (uint8_t)*ptr;
|
6725
7231
|
if (UPB_LIKELY((byte & 0x80) == 0)) {
|
6726
7232
|
*val = byte;
|
@@ -6734,8 +7240,8 @@ static const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr,
|
|
6734
7240
|
}
|
6735
7241
|
|
6736
7242
|
UPB_FORCEINLINE
|
6737
|
-
|
6738
|
-
|
7243
|
+
const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr,
|
7244
|
+
uint32_t* val) {
|
6739
7245
|
uint64_t byte = (uint8_t)*ptr;
|
6740
7246
|
if (UPB_LIKELY((byte & 0x80) == 0)) {
|
6741
7247
|
*val = byte;
|
@@ -6752,8 +7258,8 @@ static const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr,
|
|
6752
7258
|
}
|
6753
7259
|
|
6754
7260
|
UPB_FORCEINLINE
|
6755
|
-
|
6756
|
-
|
7261
|
+
const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr,
|
7262
|
+
uint32_t* size) {
|
6757
7263
|
uint64_t size64;
|
6758
7264
|
ptr = _upb_Decoder_DecodeVarint(d, ptr, &size64);
|
6759
7265
|
if (size64 >= INT32_MAX ||
|
@@ -6855,11 +7361,10 @@ static const char* _upb_Decoder_ReadString(upb_Decoder* d, const char* ptr,
|
|
6855
7361
|
}
|
6856
7362
|
|
6857
7363
|
UPB_FORCEINLINE
|
6858
|
-
|
6859
|
-
|
6860
|
-
|
6861
|
-
|
6862
|
-
uint32_t expected_end_group) {
|
7364
|
+
const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d, const char* ptr,
|
7365
|
+
upb_Message* submsg,
|
7366
|
+
const upb_MiniTable* subl,
|
7367
|
+
uint32_t expected_end_group) {
|
6863
7368
|
if (--d->depth < 0) {
|
6864
7369
|
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded);
|
6865
7370
|
}
|
@@ -6872,9 +7377,11 @@ static const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d,
|
|
6872
7377
|
}
|
6873
7378
|
|
6874
7379
|
UPB_FORCEINLINE
|
6875
|
-
|
6876
|
-
|
6877
|
-
|
7380
|
+
const char* _upb_Decoder_DecodeSubMessage(upb_Decoder* d, const char* ptr,
|
7381
|
+
upb_Message* submsg,
|
7382
|
+
const upb_MiniTableSub* subs,
|
7383
|
+
const upb_MiniTableField* field,
|
7384
|
+
int size) {
|
6878
7385
|
int saved_delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, size);
|
6879
7386
|
const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field);
|
6880
7387
|
UPB_ASSERT(subl);
|
@@ -6884,10 +7391,10 @@ static const char* _upb_Decoder_DecodeSubMessage(
|
|
6884
7391
|
}
|
6885
7392
|
|
6886
7393
|
UPB_FORCEINLINE
|
6887
|
-
|
6888
|
-
|
6889
|
-
|
6890
|
-
|
7394
|
+
const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr,
|
7395
|
+
upb_Message* submsg,
|
7396
|
+
const upb_MiniTable* subl,
|
7397
|
+
uint32_t number) {
|
6891
7398
|
if (_upb_Decoder_IsDone(d, &ptr)) {
|
6892
7399
|
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
|
6893
7400
|
}
|
@@ -6897,16 +7404,16 @@ static const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr,
|
|
6897
7404
|
}
|
6898
7405
|
|
6899
7406
|
UPB_FORCEINLINE
|
6900
|
-
|
6901
|
-
|
6902
|
-
uint32_t number) {
|
7407
|
+
const char* _upb_Decoder_DecodeUnknownGroup(upb_Decoder* d, const char* ptr,
|
7408
|
+
uint32_t number) {
|
6903
7409
|
return _upb_Decoder_DecodeGroup(d, ptr, NULL, NULL, number);
|
6904
7410
|
}
|
6905
7411
|
|
6906
7412
|
UPB_FORCEINLINE
|
6907
|
-
|
6908
|
-
|
6909
|
-
|
7413
|
+
const char* _upb_Decoder_DecodeKnownGroup(upb_Decoder* d, const char* ptr,
|
7414
|
+
upb_Message* submsg,
|
7415
|
+
const upb_MiniTableSub* subs,
|
7416
|
+
const upb_MiniTableField* field) {
|
6910
7417
|
const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field);
|
6911
7418
|
UPB_ASSERT(subl);
|
6912
7419
|
return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl,
|
@@ -6936,10 +7443,9 @@ static void _upb_Decoder_AddUnknownVarints(upb_Decoder* d, upb_Message* msg,
|
|
6936
7443
|
}
|
6937
7444
|
|
6938
7445
|
UPB_FORCEINLINE
|
6939
|
-
|
6940
|
-
|
6941
|
-
|
6942
|
-
wireval* val) {
|
7446
|
+
bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr, upb_Message* msg,
|
7447
|
+
const upb_MiniTableEnum* e,
|
7448
|
+
const upb_MiniTableField* field, wireval* val) {
|
6943
7449
|
const uint32_t v = val->uint32_val;
|
6944
7450
|
|
6945
7451
|
if (UPB_LIKELY(upb_MiniTableEnum_CheckValue(e, v))) return true;
|
@@ -6973,9 +7479,10 @@ static const char* _upb_Decoder_DecodeEnumArray(upb_Decoder* d, const char* ptr,
|
|
6973
7479
|
}
|
6974
7480
|
|
6975
7481
|
UPB_FORCEINLINE
|
6976
|
-
|
6977
|
-
|
6978
|
-
|
7482
|
+
const char* _upb_Decoder_DecodeFixedPacked(upb_Decoder* d, const char* ptr,
|
7483
|
+
upb_Array* arr, wireval* val,
|
7484
|
+
const upb_MiniTableField* field,
|
7485
|
+
int lg2) {
|
6979
7486
|
int mask = (1 << lg2) - 1;
|
6980
7487
|
size_t count = val->size >> lg2;
|
6981
7488
|
if ((val->size & mask) != 0) {
|
@@ -7010,9 +7517,10 @@ static const char* _upb_Decoder_DecodeFixedPacked(
|
|
7010
7517
|
}
|
7011
7518
|
|
7012
7519
|
UPB_FORCEINLINE
|
7013
|
-
|
7014
|
-
|
7015
|
-
|
7520
|
+
const char* _upb_Decoder_DecodeVarintPacked(upb_Decoder* d, const char* ptr,
|
7521
|
+
upb_Array* arr, wireval* val,
|
7522
|
+
const upb_MiniTableField* field,
|
7523
|
+
int lg2) {
|
7016
7524
|
int scale = 1 << lg2;
|
7017
7525
|
int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size);
|
7018
7526
|
char* out = UPB_PTR_AT(upb_Array_MutableDataPtr(arr),
|
@@ -7255,7 +7763,7 @@ static const char* _upb_Decoder_DecodeToSubMessage(
|
|
7255
7763
|
// Set presence if necessary.
|
7256
7764
|
if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(field)) {
|
7257
7765
|
UPB_PRIVATE(_upb_Message_SetHasbit)(msg, field);
|
7258
|
-
} else if (
|
7766
|
+
} else if (upb_MiniTableField_IsInOneof(field)) {
|
7259
7767
|
// Oneof case
|
7260
7768
|
uint32_t* oneof_case = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, field);
|
7261
7769
|
if (op == kUpb_DecodeOp_SubMessage &&
|
@@ -7318,9 +7826,8 @@ const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr,
|
|
7318
7826
|
}
|
7319
7827
|
|
7320
7828
|
UPB_FORCEINLINE
|
7321
|
-
|
7322
|
-
|
7323
|
-
const upb_MiniTable* m) {
|
7829
|
+
bool _upb_Decoder_TryFastDispatch(upb_Decoder* d, const char** ptr,
|
7830
|
+
upb_Message* msg, const upb_MiniTable* m) {
|
7324
7831
|
#if UPB_FASTTABLE
|
7325
7832
|
if (m && m->UPB_PRIVATE(table_mask) != (unsigned char)-1) {
|
7326
7833
|
uint16_t tag = _upb_FastDecoder_LoadTag(*ptr);
|
@@ -7558,9 +8065,8 @@ static int _upb_Decoder_GetVarintOp(const upb_MiniTableField* field) {
|
|
7558
8065
|
}
|
7559
8066
|
|
7560
8067
|
UPB_FORCEINLINE
|
7561
|
-
|
7562
|
-
|
7563
|
-
int* op) {
|
8068
|
+
void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt,
|
8069
|
+
const upb_MiniTableField* field, int* op) {
|
7564
8070
|
// If sub-message is not linked, treat as unknown.
|
7565
8071
|
if (field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension) return;
|
7566
8072
|
const upb_MiniTable* mt_sub =
|
@@ -7586,9 +8092,8 @@ static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt,
|
|
7586
8092
|
}
|
7587
8093
|
|
7588
8094
|
UPB_FORCEINLINE
|
7589
|
-
|
7590
|
-
|
7591
|
-
int* op) {
|
8095
|
+
void _upb_Decoder_MaybeVerifyUtf8(upb_Decoder* d,
|
8096
|
+
const upb_MiniTableField* field, int* op) {
|
7592
8097
|
if ((field->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) &&
|
7593
8098
|
UPB_UNLIKELY(d->options & kUpb_DecodeOption_AlwaysValidateUtf8))
|
7594
8099
|
*op = kUpb_DecodeOp_String;
|
@@ -7658,11 +8163,10 @@ static int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt,
|
|
7658
8163
|
}
|
7659
8164
|
|
7660
8165
|
UPB_FORCEINLINE
|
7661
|
-
|
7662
|
-
|
7663
|
-
|
7664
|
-
|
7665
|
-
int* op) {
|
8166
|
+
const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr,
|
8167
|
+
const upb_MiniTable* mt,
|
8168
|
+
const upb_MiniTableField* field,
|
8169
|
+
int wire_type, wireval* val, int* op) {
|
7666
8170
|
static const unsigned kFixed32OkMask = (1 << kUpb_FieldType_Float) |
|
7667
8171
|
(1 << kUpb_FieldType_Fixed32) |
|
7668
8172
|
(1 << kUpb_FieldType_SFixed32);
|
@@ -7712,10 +8216,11 @@ static const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr,
|
|
7712
8216
|
}
|
7713
8217
|
|
7714
8218
|
UPB_FORCEINLINE
|
7715
|
-
|
7716
|
-
|
7717
|
-
|
7718
|
-
|
8219
|
+
const char* _upb_Decoder_DecodeKnownField(upb_Decoder* d, const char* ptr,
|
8220
|
+
upb_Message* msg,
|
8221
|
+
const upb_MiniTable* layout,
|
8222
|
+
const upb_MiniTableField* field,
|
8223
|
+
int op, wireval* val) {
|
7719
8224
|
const upb_MiniTableSub* subs = layout->UPB_PRIVATE(subs);
|
7720
8225
|
uint8_t mode = field->UPB_PRIVATE(mode);
|
7721
8226
|
|
@@ -7921,9 +8426,10 @@ static upb_DecodeStatus upb_Decoder_Decode(upb_Decoder* const decoder,
|
|
7921
8426
|
}
|
7922
8427
|
|
7923
8428
|
upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg,
|
7924
|
-
const upb_MiniTable*
|
8429
|
+
const upb_MiniTable* mt,
|
7925
8430
|
const upb_ExtensionRegistry* extreg, int options,
|
7926
8431
|
upb_Arena* arena) {
|
8432
|
+
UPB_ASSERT(!upb_Message_IsFrozen(msg));
|
7927
8433
|
upb_Decoder decoder;
|
7928
8434
|
unsigned depth = (unsigned)options >> 16;
|
7929
8435
|
|
@@ -7945,7 +8451,42 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg,
|
|
7945
8451
|
// (particularly parent_or_count).
|
7946
8452
|
UPB_PRIVATE(_upb_Arena_SwapIn)(&decoder.arena, arena);
|
7947
8453
|
|
7948
|
-
return upb_Decoder_Decode(&decoder, buf, msg,
|
8454
|
+
return upb_Decoder_Decode(&decoder, buf, msg, mt, arena);
|
8455
|
+
}
|
8456
|
+
|
8457
|
+
upb_DecodeStatus upb_DecodeLengthPrefixed(const char* buf, size_t size,
|
8458
|
+
upb_Message* msg,
|
8459
|
+
size_t* num_bytes_read,
|
8460
|
+
const upb_MiniTable* mt,
|
8461
|
+
const upb_ExtensionRegistry* extreg,
|
8462
|
+
int options, upb_Arena* arena) {
|
8463
|
+
// To avoid needing to make a Decoder just to decode the initial length,
|
8464
|
+
// hand-decode the leading varint for the message length here.
|
8465
|
+
uint64_t msg_len = 0;
|
8466
|
+
for (size_t i = 0;; ++i) {
|
8467
|
+
if (i >= size || i > 9) {
|
8468
|
+
return kUpb_DecodeStatus_Malformed;
|
8469
|
+
}
|
8470
|
+
uint64_t b = *buf;
|
8471
|
+
buf++;
|
8472
|
+
msg_len += (b & 0x7f) << (i * 7);
|
8473
|
+
if ((b & 0x80) == 0) {
|
8474
|
+
*num_bytes_read = i + 1 + msg_len;
|
8475
|
+
break;
|
8476
|
+
}
|
8477
|
+
}
|
8478
|
+
|
8479
|
+
// If the total number of bytes we would read (= the bytes from the varint
|
8480
|
+
// plus however many bytes that varint says we should read) is larger then the
|
8481
|
+
// input buffer then error as malformed.
|
8482
|
+
if (*num_bytes_read > size) {
|
8483
|
+
return kUpb_DecodeStatus_Malformed;
|
8484
|
+
}
|
8485
|
+
if (msg_len > INT32_MAX) {
|
8486
|
+
return kUpb_DecodeStatus_Malformed;
|
8487
|
+
}
|
8488
|
+
|
8489
|
+
return upb_Decode(buf, msg_len, msg, mt, extreg, options, arena);
|
7949
8490
|
}
|
7950
8491
|
|
7951
8492
|
#undef OP_FIXPCK_LG2
|
@@ -8032,7 +8573,7 @@ static void encode_growbuffer(upb_encstate* e, size_t bytes) {
|
|
8032
8573
|
/* Call to ensure that at least "bytes" bytes are available for writing at
|
8033
8574
|
* e->ptr. Returns false if the bytes could not be allocated. */
|
8034
8575
|
UPB_FORCEINLINE
|
8035
|
-
|
8576
|
+
void encode_reserve(upb_encstate* e, size_t bytes) {
|
8036
8577
|
if ((size_t)(e->ptr - e->buf) < bytes) {
|
8037
8578
|
encode_growbuffer(e, bytes);
|
8038
8579
|
return;
|
@@ -8071,7 +8612,7 @@ static void encode_longvarint(upb_encstate* e, uint64_t val) {
|
|
8071
8612
|
}
|
8072
8613
|
|
8073
8614
|
UPB_FORCEINLINE
|
8074
|
-
|
8615
|
+
void encode_varint(upb_encstate* e, uint64_t val) {
|
8075
8616
|
if (val < 128 && e->ptr != e->buf) {
|
8076
8617
|
--e->ptr;
|
8077
8618
|
*e->ptr = val;
|
@@ -8101,7 +8642,7 @@ static void encode_tag(upb_encstate* e, uint32_t field_number,
|
|
8101
8642
|
|
8102
8643
|
static void encode_fixedarray(upb_encstate* e, const upb_Array* arr,
|
8103
8644
|
size_t elem_size, uint32_t tag) {
|
8104
|
-
size_t bytes = arr
|
8645
|
+
size_t bytes = upb_Array_Size(arr) * elem_size;
|
8105
8646
|
const char* data = upb_Array_DataPtr(arr);
|
8106
8647
|
const char* ptr = data + bytes - elem_size;
|
8107
8648
|
|
@@ -8198,7 +8739,7 @@ static void encode_scalar(upb_encstate* e, const void* _field_mem,
|
|
8198
8739
|
return;
|
8199
8740
|
}
|
8200
8741
|
if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded);
|
8201
|
-
encode_tag(e, f
|
8742
|
+
encode_tag(e, upb_MiniTableField_Number(f), kUpb_WireType_EndGroup);
|
8202
8743
|
encode_TaggedMessagePtr(e, submsg, subm, &size);
|
8203
8744
|
wire_type = kUpb_WireType_StartGroup;
|
8204
8745
|
e->depth++;
|
@@ -8224,7 +8765,7 @@ static void encode_scalar(upb_encstate* e, const void* _field_mem,
|
|
8224
8765
|
}
|
8225
8766
|
#undef CASE
|
8226
8767
|
|
8227
|
-
encode_tag(e, f
|
8768
|
+
encode_tag(e, upb_MiniTableField_Number(f), wire_type);
|
8228
8769
|
}
|
8229
8770
|
|
8230
8771
|
static void encode_array(upb_encstate* e, const upb_Message* msg,
|
@@ -8234,14 +8775,14 @@ static void encode_array(upb_encstate* e, const upb_Message* msg,
|
|
8234
8775
|
bool packed = upb_MiniTableField_IsPacked(f);
|
8235
8776
|
size_t pre_len = e->limit - e->ptr;
|
8236
8777
|
|
8237
|
-
if (arr == NULL || arr
|
8778
|
+
if (arr == NULL || upb_Array_Size(arr) == 0) {
|
8238
8779
|
return;
|
8239
8780
|
}
|
8240
8781
|
|
8241
8782
|
#define VARINT_CASE(ctype, encode) \
|
8242
8783
|
{ \
|
8243
8784
|
const ctype* start = upb_Array_DataPtr(arr); \
|
8244
|
-
const ctype* ptr = start + arr
|
8785
|
+
const ctype* ptr = start + upb_Array_Size(arr); \
|
8245
8786
|
uint32_t tag = \
|
8246
8787
|
packed ? 0 : (f->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; \
|
8247
8788
|
do { \
|
@@ -8286,34 +8827,34 @@ static void encode_array(upb_encstate* e, const upb_Message* msg,
|
|
8286
8827
|
case kUpb_FieldType_String:
|
8287
8828
|
case kUpb_FieldType_Bytes: {
|
8288
8829
|
const upb_StringView* start = upb_Array_DataPtr(arr);
|
8289
|
-
const upb_StringView* ptr = start + arr
|
8830
|
+
const upb_StringView* ptr = start + upb_Array_Size(arr);
|
8290
8831
|
do {
|
8291
8832
|
ptr--;
|
8292
8833
|
encode_bytes(e, ptr->data, ptr->size);
|
8293
8834
|
encode_varint(e, ptr->size);
|
8294
|
-
encode_tag(e, f
|
8835
|
+
encode_tag(e, upb_MiniTableField_Number(f), kUpb_WireType_Delimited);
|
8295
8836
|
} while (ptr != start);
|
8296
8837
|
return;
|
8297
8838
|
}
|
8298
8839
|
case kUpb_FieldType_Group: {
|
8299
8840
|
const upb_TaggedMessagePtr* start = upb_Array_DataPtr(arr);
|
8300
|
-
const upb_TaggedMessagePtr* ptr = start + arr
|
8841
|
+
const upb_TaggedMessagePtr* ptr = start + upb_Array_Size(arr);
|
8301
8842
|
const upb_MiniTable* subm =
|
8302
8843
|
upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]);
|
8303
8844
|
if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded);
|
8304
8845
|
do {
|
8305
8846
|
size_t size;
|
8306
8847
|
ptr--;
|
8307
|
-
encode_tag(e, f
|
8848
|
+
encode_tag(e, upb_MiniTableField_Number(f), kUpb_WireType_EndGroup);
|
8308
8849
|
encode_TaggedMessagePtr(e, *ptr, subm, &size);
|
8309
|
-
encode_tag(e, f
|
8850
|
+
encode_tag(e, upb_MiniTableField_Number(f), kUpb_WireType_StartGroup);
|
8310
8851
|
} while (ptr != start);
|
8311
8852
|
e->depth++;
|
8312
8853
|
return;
|
8313
8854
|
}
|
8314
8855
|
case kUpb_FieldType_Message: {
|
8315
8856
|
const upb_TaggedMessagePtr* start = upb_Array_DataPtr(arr);
|
8316
|
-
const upb_TaggedMessagePtr* ptr = start + arr
|
8857
|
+
const upb_TaggedMessagePtr* ptr = start + upb_Array_Size(arr);
|
8317
8858
|
const upb_MiniTable* subm =
|
8318
8859
|
upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]);
|
8319
8860
|
if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded);
|
@@ -8322,7 +8863,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg,
|
|
8322
8863
|
ptr--;
|
8323
8864
|
encode_TaggedMessagePtr(e, *ptr, subm, &size);
|
8324
8865
|
encode_varint(e, size);
|
8325
|
-
encode_tag(e, f
|
8866
|
+
encode_tag(e, upb_MiniTableField_Number(f), kUpb_WireType_Delimited);
|
8326
8867
|
} while (ptr != start);
|
8327
8868
|
e->depth++;
|
8328
8869
|
return;
|
@@ -8332,15 +8873,15 @@ static void encode_array(upb_encstate* e, const upb_Message* msg,
|
|
8332
8873
|
|
8333
8874
|
if (packed) {
|
8334
8875
|
encode_varint(e, e->limit - e->ptr - pre_len);
|
8335
|
-
encode_tag(e, f
|
8876
|
+
encode_tag(e, upb_MiniTableField_Number(f), kUpb_WireType_Delimited);
|
8336
8877
|
}
|
8337
8878
|
}
|
8338
8879
|
|
8339
8880
|
static void encode_mapentry(upb_encstate* e, uint32_t number,
|
8340
8881
|
const upb_MiniTable* layout,
|
8341
8882
|
const upb_MapEntry* ent) {
|
8342
|
-
const upb_MiniTableField* key_field =
|
8343
|
-
const upb_MiniTableField* val_field =
|
8883
|
+
const upb_MiniTableField* key_field = upb_MiniTable_MapKey(layout);
|
8884
|
+
const upb_MiniTableField* val_field = upb_MiniTable_MapValue(layout);
|
8344
8885
|
size_t pre_len = e->limit - e->ptr;
|
8345
8886
|
size_t size;
|
8346
8887
|
encode_scalar(e, &ent->v, layout->UPB_PRIVATE(subs), val_field);
|
@@ -8356,7 +8897,7 @@ static void encode_map(upb_encstate* e, const upb_Message* msg,
|
|
8356
8897
|
const upb_Map* map = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), const upb_Map*);
|
8357
8898
|
const upb_MiniTable* layout =
|
8358
8899
|
upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]);
|
8359
|
-
UPB_ASSERT(layout
|
8900
|
+
UPB_ASSERT(upb_MiniTable_FieldCount(layout) == 2);
|
8360
8901
|
|
8361
8902
|
if (!map || !upb_Map_Size(map)) return;
|
8362
8903
|
|
@@ -8367,7 +8908,7 @@ static void encode_map(upb_encstate* e, const upb_Message* msg,
|
|
8367
8908
|
map, &sorted);
|
8368
8909
|
upb_MapEntry ent;
|
8369
8910
|
while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) {
|
8370
|
-
encode_mapentry(e, f
|
8911
|
+
encode_mapentry(e, upb_MiniTableField_Number(f), layout, &ent);
|
8371
8912
|
}
|
8372
8913
|
_upb_mapsorter_popmap(&e->sorter, &sorted);
|
8373
8914
|
} else {
|
@@ -8378,7 +8919,7 @@ static void encode_map(upb_encstate* e, const upb_Message* msg,
|
|
8378
8919
|
upb_MapEntry ent;
|
8379
8920
|
_upb_map_fromkey(key, &ent.k, map->key_size);
|
8380
8921
|
_upb_map_fromvalue(val, &ent.v, map->val_size);
|
8381
|
-
encode_mapentry(e, f
|
8922
|
+
encode_mapentry(e, upb_MiniTableField_Number(f), layout, &ent);
|
8382
8923
|
}
|
8383
8924
|
}
|
8384
8925
|
}
|
@@ -8418,7 +8959,7 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg,
|
|
8418
8959
|
} else {
|
8419
8960
|
// Field is in a oneof.
|
8420
8961
|
return UPB_PRIVATE(_upb_Message_GetOneofCase)(msg, f) ==
|
8421
|
-
f
|
8962
|
+
upb_MiniTableField_Number(f);
|
8422
8963
|
}
|
8423
8964
|
}
|
8424
8965
|
|
@@ -8444,7 +8985,7 @@ static void encode_field(upb_encstate* e, const upb_Message* msg,
|
|
8444
8985
|
static void encode_msgset_item(upb_encstate* e, const upb_Extension* ext) {
|
8445
8986
|
size_t size;
|
8446
8987
|
encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_EndGroup);
|
8447
|
-
encode_message(e, ext->data.
|
8988
|
+
encode_message(e, ext->data.msg_val,
|
8448
8989
|
upb_MiniTableExtension_GetSubMessage(ext->ext), &size);
|
8449
8990
|
encode_varint(e, size);
|
8450
8991
|
encode_tag(e, kUpb_MsgSet_Message, kUpb_WireType_Delimited);
|
@@ -8508,7 +9049,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg,
|
|
8508
9049
|
}
|
8509
9050
|
}
|
8510
9051
|
|
8511
|
-
if (m
|
9052
|
+
if (upb_MiniTable_FieldCount(m)) {
|
8512
9053
|
const upb_MiniTableField* f =
|
8513
9054
|
&m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)];
|
8514
9055
|
const upb_MiniTableField* first = &m->UPB_PRIVATE(fields)[0];
|
@@ -8526,14 +9067,18 @@ static void encode_message(upb_encstate* e, const upb_Message* msg,
|
|
8526
9067
|
static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder,
|
8527
9068
|
const upb_Message* const msg,
|
8528
9069
|
const upb_MiniTable* const l,
|
8529
|
-
char** const buf,
|
8530
|
-
|
9070
|
+
char** const buf, size_t* const size,
|
9071
|
+
bool prepend_len) {
|
8531
9072
|
// Unfortunately we must continue to perform hackery here because there are
|
8532
9073
|
// code paths which blindly copy the returned pointer without bothering to
|
8533
9074
|
// check for errors until much later (b/235839510). So we still set *buf to
|
8534
9075
|
// NULL on error and we still set it to non-NULL on a successful empty result.
|
8535
9076
|
if (UPB_SETJMP(encoder->err) == 0) {
|
8536
|
-
|
9077
|
+
size_t encoded_msg_size;
|
9078
|
+
encode_message(encoder, msg, l, &encoded_msg_size);
|
9079
|
+
if (prepend_len) {
|
9080
|
+
encode_varint(encoder, encoded_msg_size);
|
9081
|
+
}
|
8537
9082
|
*size = encoder->limit - encoder->ptr;
|
8538
9083
|
if (*size == 0) {
|
8539
9084
|
static char ch;
|
@@ -8552,9 +9097,10 @@ static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder,
|
|
8552
9097
|
return encoder->status;
|
8553
9098
|
}
|
8554
9099
|
|
8555
|
-
upb_EncodeStatus
|
8556
|
-
|
8557
|
-
|
9100
|
+
static upb_EncodeStatus _upb_Encode(const upb_Message* msg,
|
9101
|
+
const upb_MiniTable* l, int options,
|
9102
|
+
upb_Arena* arena, char** buf, size_t* size,
|
9103
|
+
bool prepend_len) {
|
8558
9104
|
upb_encstate e;
|
8559
9105
|
unsigned depth = (unsigned)options >> 16;
|
8560
9106
|
|
@@ -8567,7 +9113,20 @@ upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l,
|
|
8567
9113
|
e.options = options;
|
8568
9114
|
_upb_mapsorter_init(&e.sorter);
|
8569
9115
|
|
8570
|
-
return upb_Encoder_Encode(&e, msg, l, buf, size);
|
9116
|
+
return upb_Encoder_Encode(&e, msg, l, buf, size, prepend_len);
|
9117
|
+
}
|
9118
|
+
|
9119
|
+
upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l,
|
9120
|
+
int options, upb_Arena* arena, char** buf,
|
9121
|
+
size_t* size) {
|
9122
|
+
return _upb_Encode(msg, l, options, arena, buf, size, false);
|
9123
|
+
}
|
9124
|
+
|
9125
|
+
upb_EncodeStatus upb_EncodeLengthPrefixed(const upb_Message* msg,
|
9126
|
+
const upb_MiniTable* l, int options,
|
9127
|
+
upb_Arena* arena, char** buf,
|
9128
|
+
size_t* size) {
|
9129
|
+
return _upb_Encode(msg, l, options, arena, buf, size, true);
|
8571
9130
|
}
|
8572
9131
|
|
8573
9132
|
// Fast decoder: ~3x the speed of decode.c, but requires x86-64/ARM64.
|
@@ -8617,7 +9176,7 @@ static const char* fastdecode_isdonefallback(UPB_PARSE_PARAMS) {
|
|
8617
9176
|
}
|
8618
9177
|
|
8619
9178
|
UPB_FORCEINLINE
|
8620
|
-
|
9179
|
+
const char* fastdecode_dispatch(UPB_PARSE_PARAMS) {
|
8621
9180
|
int overrun;
|
8622
9181
|
switch (upb_EpsCopyInputStream_IsDoneStatus(&d->input, ptr, &overrun)) {
|
8623
9182
|
case kUpb_IsDoneStatus_Done:
|
@@ -8639,7 +9198,7 @@ static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) {
|
|
8639
9198
|
}
|
8640
9199
|
|
8641
9200
|
UPB_FORCEINLINE
|
8642
|
-
|
9201
|
+
bool fastdecode_checktag(uint16_t data, int tagbytes) {
|
8643
9202
|
if (tagbytes == 1) {
|
8644
9203
|
return (data & 0xff) == 0;
|
8645
9204
|
} else {
|
@@ -8648,7 +9207,7 @@ static bool fastdecode_checktag(uint16_t data, int tagbytes) {
|
|
8648
9207
|
}
|
8649
9208
|
|
8650
9209
|
UPB_FORCEINLINE
|
8651
|
-
|
9210
|
+
const char* fastdecode_longsize(const char* ptr, int* size) {
|
8652
9211
|
int i;
|
8653
9212
|
UPB_ASSERT(*size & 0x80);
|
8654
9213
|
*size &= 0xff;
|
@@ -8668,7 +9227,7 @@ static const char* fastdecode_longsize(const char* ptr, int* size) {
|
|
8668
9227
|
}
|
8669
9228
|
|
8670
9229
|
UPB_FORCEINLINE
|
8671
|
-
|
9230
|
+
const char* fastdecode_delimited(
|
8672
9231
|
upb_Decoder* d, const char* ptr,
|
8673
9232
|
upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) {
|
8674
9233
|
ptr++;
|
@@ -8721,8 +9280,8 @@ typedef struct {
|
|
8721
9280
|
} fastdecode_nextret;
|
8722
9281
|
|
8723
9282
|
UPB_FORCEINLINE
|
8724
|
-
|
8725
|
-
|
9283
|
+
void* fastdecode_resizearr(upb_Decoder* d, void* dst, fastdecode_arr* farr,
|
9284
|
+
int valbytes) {
|
8726
9285
|
if (UPB_UNLIKELY(dst == farr->end)) {
|
8727
9286
|
size_t old_capacity = farr->arr->UPB_PRIVATE(capacity);
|
8728
9287
|
size_t old_bytes = old_capacity * valbytes;
|
@@ -8740,7 +9299,7 @@ static void* fastdecode_resizearr(upb_Decoder* d, void* dst,
|
|
8740
9299
|
}
|
8741
9300
|
|
8742
9301
|
UPB_FORCEINLINE
|
8743
|
-
|
9302
|
+
bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) {
|
8744
9303
|
if (tagbytes == 1) {
|
8745
9304
|
return (uint8_t)tag == (uint8_t)data;
|
8746
9305
|
} else {
|
@@ -8749,19 +9308,17 @@ static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) {
|
|
8749
9308
|
}
|
8750
9309
|
|
8751
9310
|
UPB_FORCEINLINE
|
8752
|
-
|
8753
|
-
int valbytes) {
|
9311
|
+
void fastdecode_commitarr(void* dst, fastdecode_arr* farr, int valbytes) {
|
8754
9312
|
farr->arr->UPB_PRIVATE(size) =
|
8755
9313
|
(size_t)((char*)dst - (char*)upb_Array_MutableDataPtr(farr->arr)) /
|
8756
9314
|
valbytes;
|
8757
9315
|
}
|
8758
9316
|
|
8759
9317
|
UPB_FORCEINLINE
|
8760
|
-
|
8761
|
-
|
8762
|
-
|
8763
|
-
|
8764
|
-
int valbytes) {
|
9318
|
+
fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst,
|
9319
|
+
const char** ptr,
|
9320
|
+
fastdecode_arr* farr, uint64_t data,
|
9321
|
+
int tagbytes, int valbytes) {
|
8765
9322
|
fastdecode_nextret ret;
|
8766
9323
|
dst = (char*)dst + valbytes;
|
8767
9324
|
|
@@ -8783,16 +9340,15 @@ static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst,
|
|
8783
9340
|
}
|
8784
9341
|
|
8785
9342
|
UPB_FORCEINLINE
|
8786
|
-
|
9343
|
+
void* fastdecode_fieldmem(upb_Message* msg, uint64_t data) {
|
8787
9344
|
size_t ofs = data >> 48;
|
8788
9345
|
return (char*)msg + ofs;
|
8789
9346
|
}
|
8790
9347
|
|
8791
9348
|
UPB_FORCEINLINE
|
8792
|
-
|
8793
|
-
|
8794
|
-
|
8795
|
-
int valbytes, upb_card card) {
|
9349
|
+
void* fastdecode_getfield(upb_Decoder* d, const char* ptr, upb_Message* msg,
|
9350
|
+
uint64_t* data, uint64_t* hasbits,
|
9351
|
+
fastdecode_arr* farr, int valbytes, upb_card card) {
|
8796
9352
|
switch (card) {
|
8797
9353
|
case CARD_s: {
|
8798
9354
|
uint8_t hasbit_index = *data >> 24;
|
@@ -8831,7 +9387,7 @@ static void* fastdecode_getfield(upb_Decoder* d, const char* ptr,
|
|
8831
9387
|
}
|
8832
9388
|
|
8833
9389
|
UPB_FORCEINLINE
|
8834
|
-
|
9390
|
+
bool fastdecode_flippacked(uint64_t* data, int tagbytes) {
|
8835
9391
|
*data ^= (0x2 ^ 0x0); // Patch data to match packed wiretype.
|
8836
9392
|
return fastdecode_checktag(*data, tagbytes);
|
8837
9393
|
}
|
@@ -8847,7 +9403,7 @@ static bool fastdecode_flippacked(uint64_t* data, int tagbytes) {
|
|
8847
9403
|
/* varint fields **************************************************************/
|
8848
9404
|
|
8849
9405
|
UPB_FORCEINLINE
|
8850
|
-
|
9406
|
+
uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) {
|
8851
9407
|
if (valbytes == 1) {
|
8852
9408
|
return val != 0;
|
8853
9409
|
} else if (zigzag) {
|
@@ -8863,7 +9419,7 @@ static uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) {
|
|
8863
9419
|
}
|
8864
9420
|
|
8865
9421
|
UPB_FORCEINLINE
|
8866
|
-
|
9422
|
+
const char* fastdecode_varint64(const char* ptr, uint64_t* val) {
|
8867
9423
|
ptr++;
|
8868
9424
|
*val = (uint8_t)ptr[-1];
|
8869
9425
|
if (UPB_UNLIKELY(*val & 0x80)) {
|
@@ -8938,8 +9494,8 @@ typedef struct {
|
|
8938
9494
|
} fastdecode_varintdata;
|
8939
9495
|
|
8940
9496
|
UPB_FORCEINLINE
|
8941
|
-
|
8942
|
-
|
9497
|
+
const char* fastdecode_topackedvarint(upb_EpsCopyInputStream* e,
|
9498
|
+
const char* ptr, void* ctx) {
|
8943
9499
|
upb_Decoder* d = (upb_Decoder*)e;
|
8944
9500
|
fastdecode_varintdata* data = ctx;
|
8945
9501
|
void* dst = data->dst;
|
@@ -9218,9 +9774,8 @@ static const char* fastdecode_longstring_noutf8(
|
|
9218
9774
|
}
|
9219
9775
|
|
9220
9776
|
UPB_FORCEINLINE
|
9221
|
-
|
9222
|
-
|
9223
|
-
upb_StringView* dst) {
|
9777
|
+
void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, int copy,
|
9778
|
+
char* data, size_t data_offset, upb_StringView* dst) {
|
9224
9779
|
d->arena.UPB_PRIVATE(ptr) += copy;
|
9225
9780
|
dst->data = data + data_offset;
|
9226
9781
|
UPB_UNPOISON_MEMORY_REGION(data, copy);
|
@@ -9451,8 +10006,8 @@ typedef struct {
|
|
9451
10006
|
} fastdecode_submsgdata;
|
9452
10007
|
|
9453
10008
|
UPB_FORCEINLINE
|
9454
|
-
|
9455
|
-
|
10009
|
+
const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, const char* ptr,
|
10010
|
+
void* ctx) {
|
9456
10011
|
upb_Decoder* d = (upb_Decoder*)e;
|
9457
10012
|
fastdecode_submsgdata* submsg = ctx;
|
9458
10013
|
ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0);
|
@@ -9570,8 +10125,7 @@ UPB_NOINLINE UPB_PRIVATE(_upb_WireReader_LongVarint)
|
|
9570
10125
|
UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val) {
|
9571
10126
|
UPB_PRIVATE(_upb_WireReader_LongVarint) ret = {NULL, 0};
|
9572
10127
|
uint64_t byte;
|
9573
|
-
int i;
|
9574
|
-
for (i = 1; i < 10; i++) {
|
10128
|
+
for (int i = 1; i < 10; i++) {
|
9575
10129
|
byte = (uint8_t)ptr[i];
|
9576
10130
|
val += (byte - 1) << (i * 7);
|
9577
10131
|
if (!(byte & 0x80)) {
|
@@ -10603,15 +11157,291 @@ int upb_Unicode_ToUTF8(uint32_t cp, char* out) {
|
|
10603
11157
|
}
|
10604
11158
|
|
10605
11159
|
|
11160
|
+
#include <stdlib.h>
|
11161
|
+
|
11162
|
+
|
11163
|
+
// Must be last.
|
11164
|
+
|
11165
|
+
typedef struct upb_UnknownFields upb_UnknownFields;
|
11166
|
+
|
11167
|
+
typedef struct {
|
11168
|
+
uint32_t tag;
|
11169
|
+
union {
|
11170
|
+
uint64_t varint;
|
11171
|
+
uint64_t uint64;
|
11172
|
+
uint32_t uint32;
|
11173
|
+
upb_StringView delimited;
|
11174
|
+
upb_UnknownFields* group;
|
11175
|
+
} data;
|
11176
|
+
} upb_UnknownField;
|
11177
|
+
|
11178
|
+
struct upb_UnknownFields {
|
11179
|
+
size_t size;
|
11180
|
+
size_t capacity;
|
11181
|
+
upb_UnknownField* fields;
|
11182
|
+
};
|
11183
|
+
|
11184
|
+
typedef struct {
|
11185
|
+
upb_EpsCopyInputStream stream;
|
11186
|
+
upb_Arena* arena;
|
11187
|
+
upb_UnknownField* tmp;
|
11188
|
+
size_t tmp_size;
|
11189
|
+
int depth;
|
11190
|
+
upb_UnknownCompareResult status;
|
11191
|
+
jmp_buf err;
|
11192
|
+
} upb_UnknownField_Context;
|
11193
|
+
|
11194
|
+
UPB_NORETURN static void upb_UnknownFields_OutOfMemory(
|
11195
|
+
upb_UnknownField_Context* ctx) {
|
11196
|
+
ctx->status = kUpb_UnknownCompareResult_OutOfMemory;
|
11197
|
+
UPB_LONGJMP(ctx->err, 1);
|
11198
|
+
}
|
11199
|
+
|
11200
|
+
static void upb_UnknownFields_Grow(upb_UnknownField_Context* ctx,
|
11201
|
+
upb_UnknownField** base,
|
11202
|
+
upb_UnknownField** ptr,
|
11203
|
+
upb_UnknownField** end) {
|
11204
|
+
size_t old = (*ptr - *base);
|
11205
|
+
size_t new = UPB_MAX(4, old * 2);
|
11206
|
+
|
11207
|
+
*base = upb_Arena_Realloc(ctx->arena, *base, old * sizeof(**base),
|
11208
|
+
new * sizeof(**base));
|
11209
|
+
if (!*base) upb_UnknownFields_OutOfMemory(ctx);
|
11210
|
+
|
11211
|
+
*ptr = *base + old;
|
11212
|
+
*end = *base + new;
|
11213
|
+
}
|
11214
|
+
|
11215
|
+
// We have to implement our own sort here, since qsort() is not an in-order
|
11216
|
+
// sort. Here we use merge sort, the simplest in-order sort.
|
11217
|
+
static void upb_UnknownFields_Merge(upb_UnknownField* arr, size_t start,
|
11218
|
+
size_t mid, size_t end,
|
11219
|
+
upb_UnknownField* tmp) {
|
11220
|
+
memcpy(tmp, &arr[start], (end - start) * sizeof(*tmp));
|
11221
|
+
|
11222
|
+
upb_UnknownField* ptr1 = tmp;
|
11223
|
+
upb_UnknownField* end1 = &tmp[mid - start];
|
11224
|
+
upb_UnknownField* ptr2 = &tmp[mid - start];
|
11225
|
+
upb_UnknownField* end2 = &tmp[end - start];
|
11226
|
+
upb_UnknownField* out = &arr[start];
|
11227
|
+
|
11228
|
+
while (ptr1 < end1 && ptr2 < end2) {
|
11229
|
+
if (ptr1->tag <= ptr2->tag) {
|
11230
|
+
*out++ = *ptr1++;
|
11231
|
+
} else {
|
11232
|
+
*out++ = *ptr2++;
|
11233
|
+
}
|
11234
|
+
}
|
11235
|
+
|
11236
|
+
if (ptr1 < end1) {
|
11237
|
+
memcpy(out, ptr1, (end1 - ptr1) * sizeof(*out));
|
11238
|
+
} else if (ptr2 < end2) {
|
11239
|
+
memcpy(out, ptr1, (end2 - ptr2) * sizeof(*out));
|
11240
|
+
}
|
11241
|
+
}
|
11242
|
+
|
11243
|
+
static void upb_UnknownFields_SortRecursive(upb_UnknownField* arr, size_t start,
|
11244
|
+
size_t end, upb_UnknownField* tmp) {
|
11245
|
+
if (end - start > 1) {
|
11246
|
+
size_t mid = start + ((end - start) / 2);
|
11247
|
+
upb_UnknownFields_SortRecursive(arr, start, mid, tmp);
|
11248
|
+
upb_UnknownFields_SortRecursive(arr, mid, end, tmp);
|
11249
|
+
upb_UnknownFields_Merge(arr, start, mid, end, tmp);
|
11250
|
+
}
|
11251
|
+
}
|
11252
|
+
|
11253
|
+
static void upb_UnknownFields_Sort(upb_UnknownField_Context* ctx,
|
11254
|
+
upb_UnknownFields* fields) {
|
11255
|
+
if (ctx->tmp_size < fields->size) {
|
11256
|
+
const int oldsize = ctx->tmp_size * sizeof(*ctx->tmp);
|
11257
|
+
ctx->tmp_size = UPB_MAX(8, ctx->tmp_size);
|
11258
|
+
while (ctx->tmp_size < fields->size) ctx->tmp_size *= 2;
|
11259
|
+
const int newsize = ctx->tmp_size * sizeof(*ctx->tmp);
|
11260
|
+
ctx->tmp = upb_grealloc(ctx->tmp, oldsize, newsize);
|
11261
|
+
}
|
11262
|
+
upb_UnknownFields_SortRecursive(fields->fields, 0, fields->size, ctx->tmp);
|
11263
|
+
}
|
11264
|
+
|
11265
|
+
static upb_UnknownFields* upb_UnknownFields_DoBuild(
|
11266
|
+
upb_UnknownField_Context* ctx, const char** buf) {
|
11267
|
+
upb_UnknownField* arr_base = NULL;
|
11268
|
+
upb_UnknownField* arr_ptr = NULL;
|
11269
|
+
upb_UnknownField* arr_end = NULL;
|
11270
|
+
const char* ptr = *buf;
|
11271
|
+
uint32_t last_tag = 0;
|
11272
|
+
bool sorted = true;
|
11273
|
+
while (!upb_EpsCopyInputStream_IsDone(&ctx->stream, &ptr)) {
|
11274
|
+
uint32_t tag;
|
11275
|
+
ptr = upb_WireReader_ReadTag(ptr, &tag);
|
11276
|
+
UPB_ASSERT(tag <= UINT32_MAX);
|
11277
|
+
int wire_type = upb_WireReader_GetWireType(tag);
|
11278
|
+
if (wire_type == kUpb_WireType_EndGroup) break;
|
11279
|
+
if (tag < last_tag) sorted = false;
|
11280
|
+
last_tag = tag;
|
11281
|
+
|
11282
|
+
if (arr_ptr == arr_end) {
|
11283
|
+
upb_UnknownFields_Grow(ctx, &arr_base, &arr_ptr, &arr_end);
|
11284
|
+
}
|
11285
|
+
upb_UnknownField* field = arr_ptr;
|
11286
|
+
field->tag = tag;
|
11287
|
+
arr_ptr++;
|
11288
|
+
|
11289
|
+
switch (wire_type) {
|
11290
|
+
case kUpb_WireType_Varint:
|
11291
|
+
ptr = upb_WireReader_ReadVarint(ptr, &field->data.varint);
|
11292
|
+
break;
|
11293
|
+
case kUpb_WireType_64Bit:
|
11294
|
+
ptr = upb_WireReader_ReadFixed64(ptr, &field->data.uint64);
|
11295
|
+
break;
|
11296
|
+
case kUpb_WireType_32Bit:
|
11297
|
+
ptr = upb_WireReader_ReadFixed32(ptr, &field->data.uint32);
|
11298
|
+
break;
|
11299
|
+
case kUpb_WireType_Delimited: {
|
11300
|
+
int size;
|
11301
|
+
ptr = upb_WireReader_ReadSize(ptr, &size);
|
11302
|
+
const char* s_ptr = ptr;
|
11303
|
+
ptr = upb_EpsCopyInputStream_ReadStringAliased(&ctx->stream, &s_ptr,
|
11304
|
+
size);
|
11305
|
+
field->data.delimited.data = s_ptr;
|
11306
|
+
field->data.delimited.size = size;
|
11307
|
+
break;
|
11308
|
+
}
|
11309
|
+
case kUpb_WireType_StartGroup:
|
11310
|
+
if (--ctx->depth == 0) {
|
11311
|
+
ctx->status = kUpb_UnknownCompareResult_MaxDepthExceeded;
|
11312
|
+
UPB_LONGJMP(ctx->err, 1);
|
11313
|
+
}
|
11314
|
+
field->data.group = upb_UnknownFields_DoBuild(ctx, &ptr);
|
11315
|
+
ctx->depth++;
|
11316
|
+
break;
|
11317
|
+
default:
|
11318
|
+
UPB_UNREACHABLE();
|
11319
|
+
}
|
11320
|
+
}
|
11321
|
+
|
11322
|
+
*buf = ptr;
|
11323
|
+
upb_UnknownFields* ret = upb_Arena_Malloc(ctx->arena, sizeof(*ret));
|
11324
|
+
if (!ret) upb_UnknownFields_OutOfMemory(ctx);
|
11325
|
+
ret->fields = arr_base;
|
11326
|
+
ret->size = arr_ptr - arr_base;
|
11327
|
+
ret->capacity = arr_end - arr_base;
|
11328
|
+
if (!sorted) {
|
11329
|
+
upb_UnknownFields_Sort(ctx, ret);
|
11330
|
+
}
|
11331
|
+
return ret;
|
11332
|
+
}
|
11333
|
+
|
11334
|
+
// Builds a upb_UnknownFields data structure from the binary data in buf.
|
11335
|
+
static upb_UnknownFields* upb_UnknownFields_Build(upb_UnknownField_Context* ctx,
|
11336
|
+
const char* ptr,
|
11337
|
+
size_t size) {
|
11338
|
+
upb_EpsCopyInputStream_Init(&ctx->stream, &ptr, size, true);
|
11339
|
+
upb_UnknownFields* fields = upb_UnknownFields_DoBuild(ctx, &ptr);
|
11340
|
+
UPB_ASSERT(upb_EpsCopyInputStream_IsDone(&ctx->stream, &ptr) &&
|
11341
|
+
!upb_EpsCopyInputStream_IsError(&ctx->stream));
|
11342
|
+
return fields;
|
11343
|
+
}
|
11344
|
+
|
11345
|
+
// Compares two sorted upb_UnknownFields structures for equality.
|
11346
|
+
static bool upb_UnknownFields_IsEqual(const upb_UnknownFields* uf1,
|
11347
|
+
const upb_UnknownFields* uf2) {
|
11348
|
+
if (uf1->size != uf2->size) return false;
|
11349
|
+
for (size_t i = 0, n = uf1->size; i < n; i++) {
|
11350
|
+
upb_UnknownField* f1 = &uf1->fields[i];
|
11351
|
+
upb_UnknownField* f2 = &uf2->fields[i];
|
11352
|
+
if (f1->tag != f2->tag) return false;
|
11353
|
+
int wire_type = f1->tag & 7;
|
11354
|
+
switch (wire_type) {
|
11355
|
+
case kUpb_WireType_Varint:
|
11356
|
+
if (f1->data.varint != f2->data.varint) return false;
|
11357
|
+
break;
|
11358
|
+
case kUpb_WireType_64Bit:
|
11359
|
+
if (f1->data.uint64 != f2->data.uint64) return false;
|
11360
|
+
break;
|
11361
|
+
case kUpb_WireType_32Bit:
|
11362
|
+
if (f1->data.uint32 != f2->data.uint32) return false;
|
11363
|
+
break;
|
11364
|
+
case kUpb_WireType_Delimited:
|
11365
|
+
if (!upb_StringView_IsEqual(f1->data.delimited, f2->data.delimited)) {
|
11366
|
+
return false;
|
11367
|
+
}
|
11368
|
+
break;
|
11369
|
+
case kUpb_WireType_StartGroup:
|
11370
|
+
if (!upb_UnknownFields_IsEqual(f1->data.group, f2->data.group)) {
|
11371
|
+
return false;
|
11372
|
+
}
|
11373
|
+
break;
|
11374
|
+
default:
|
11375
|
+
UPB_UNREACHABLE();
|
11376
|
+
}
|
11377
|
+
}
|
11378
|
+
return true;
|
11379
|
+
}
|
11380
|
+
|
11381
|
+
static upb_UnknownCompareResult upb_UnknownField_DoCompare(
|
11382
|
+
upb_UnknownField_Context* ctx, const char* buf1, size_t size1,
|
11383
|
+
const char* buf2, size_t size2) {
|
11384
|
+
upb_UnknownCompareResult ret;
|
11385
|
+
// First build both unknown fields into a sorted data structure (similar
|
11386
|
+
// to the UnknownFieldSet in C++).
|
11387
|
+
upb_UnknownFields* uf1 = upb_UnknownFields_Build(ctx, buf1, size1);
|
11388
|
+
upb_UnknownFields* uf2 = upb_UnknownFields_Build(ctx, buf2, size2);
|
11389
|
+
|
11390
|
+
// Now perform the equality check on the sorted structures.
|
11391
|
+
if (upb_UnknownFields_IsEqual(uf1, uf2)) {
|
11392
|
+
ret = kUpb_UnknownCompareResult_Equal;
|
11393
|
+
} else {
|
11394
|
+
ret = kUpb_UnknownCompareResult_NotEqual;
|
11395
|
+
}
|
11396
|
+
return ret;
|
11397
|
+
}
|
11398
|
+
|
11399
|
+
static upb_UnknownCompareResult upb_UnknownField_Compare(
|
11400
|
+
upb_UnknownField_Context* const ctx, const char* const buf1,
|
11401
|
+
const size_t size1, const char* const buf2, const size_t size2) {
|
11402
|
+
upb_UnknownCompareResult ret;
|
11403
|
+
if (UPB_SETJMP(ctx->err) == 0) {
|
11404
|
+
ret = upb_UnknownField_DoCompare(ctx, buf1, size1, buf2, size2);
|
11405
|
+
} else {
|
11406
|
+
ret = ctx->status;
|
11407
|
+
UPB_ASSERT(ret != kUpb_UnknownCompareResult_Equal);
|
11408
|
+
}
|
11409
|
+
|
11410
|
+
upb_Arena_Free(ctx->arena);
|
11411
|
+
upb_gfree(ctx->tmp);
|
11412
|
+
return ret;
|
11413
|
+
}
|
11414
|
+
|
11415
|
+
upb_UnknownCompareResult UPB_PRIVATE(_upb_Message_UnknownFieldsAreEqual)(
|
11416
|
+
const char* buf1, size_t size1, const char* buf2, size_t size2,
|
11417
|
+
int max_depth) {
|
11418
|
+
if (size1 == 0 && size2 == 0) return kUpb_UnknownCompareResult_Equal;
|
11419
|
+
if (size1 == 0 || size2 == 0) return kUpb_UnknownCompareResult_NotEqual;
|
11420
|
+
if (memcmp(buf1, buf2, size1) == 0) return kUpb_UnknownCompareResult_Equal;
|
11421
|
+
|
11422
|
+
upb_UnknownField_Context ctx = {
|
11423
|
+
.arena = upb_Arena_New(),
|
11424
|
+
.depth = max_depth,
|
11425
|
+
.tmp = NULL,
|
11426
|
+
.tmp_size = 0,
|
11427
|
+
.status = kUpb_UnknownCompareResult_Equal,
|
11428
|
+
};
|
11429
|
+
|
11430
|
+
if (!ctx.arena) return kUpb_UnknownCompareResult_OutOfMemory;
|
11431
|
+
|
11432
|
+
return upb_UnknownField_Compare(&ctx, buf1, size1, buf2, size2);
|
11433
|
+
}
|
11434
|
+
|
11435
|
+
|
10606
11436
|
#include <string.h>
|
10607
11437
|
|
10608
11438
|
|
10609
11439
|
// Must be last.
|
10610
11440
|
|
10611
|
-
const
|
11441
|
+
const upb_Extension* UPB_PRIVATE(_upb_Message_Getext)(
|
10612
11442
|
const struct upb_Message* msg, const upb_MiniTableExtension* e) {
|
10613
11443
|
size_t n;
|
10614
|
-
const
|
11444
|
+
const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n);
|
10615
11445
|
|
10616
11446
|
// For now we use linear search exclusively to find extensions.
|
10617
11447
|
// If this becomes an issue due to messages with lots of extensions,
|
@@ -10625,11 +11455,11 @@ const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getext)(
|
|
10625
11455
|
return NULL;
|
10626
11456
|
}
|
10627
11457
|
|
10628
|
-
const
|
11458
|
+
const upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(
|
10629
11459
|
const struct upb_Message* msg, size_t* count) {
|
10630
|
-
upb_Message_Internal* in = msg
|
11460
|
+
upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
|
10631
11461
|
if (in) {
|
10632
|
-
*count = (in->size - in->ext_begin) / sizeof(
|
11462
|
+
*count = (in->size - in->ext_begin) / sizeof(upb_Extension);
|
10633
11463
|
return UPB_PTR_AT(in, in->ext_begin, void);
|
10634
11464
|
} else {
|
10635
11465
|
*count = 0;
|
@@ -10637,17 +11467,16 @@ const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(
|
|
10637
11467
|
}
|
10638
11468
|
}
|
10639
11469
|
|
10640
|
-
|
11470
|
+
upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)(
|
10641
11471
|
struct upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* a) {
|
10642
|
-
|
10643
|
-
(struct upb_Extension*)UPB_PRIVATE(_upb_Message_Getext)(msg, e);
|
11472
|
+
upb_Extension* ext = (upb_Extension*)UPB_PRIVATE(_upb_Message_Getext)(msg, e);
|
10644
11473
|
if (ext) return ext;
|
10645
|
-
if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(
|
11474
|
+
if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(upb_Extension), a))
|
10646
11475
|
return NULL;
|
10647
|
-
upb_Message_Internal* in = msg
|
10648
|
-
in->ext_begin -= sizeof(
|
11476
|
+
upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
|
11477
|
+
in->ext_begin -= sizeof(upb_Extension);
|
10649
11478
|
ext = UPB_PTR_AT(in, in->ext_begin, void);
|
10650
|
-
memset(ext, 0, sizeof(
|
11479
|
+
memset(ext, 0, sizeof(upb_Extension));
|
10651
11480
|
ext->ext = e;
|
10652
11481
|
return ext;
|
10653
11482
|
}
|
@@ -10667,7 +11496,7 @@ bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need,
|
|
10667
11496
|
upb_Arena* a) {
|
10668
11497
|
const size_t overhead = sizeof(upb_Message_Internal);
|
10669
11498
|
|
10670
|
-
upb_Message_Internal* in = msg
|
11499
|
+
upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
|
10671
11500
|
if (!in) {
|
10672
11501
|
// No internal data, allocate from scratch.
|
10673
11502
|
size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + overhead));
|
@@ -10677,7 +11506,7 @@ bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need,
|
|
10677
11506
|
in->size = size;
|
10678
11507
|
in->unknown_end = overhead;
|
10679
11508
|
in->ext_begin = size;
|
10680
|
-
msg
|
11509
|
+
UPB_PRIVATE(_upb_Message_SetInternal)(msg, in);
|
10681
11510
|
} else if (in->ext_begin - in->unknown_end < need) {
|
10682
11511
|
// Internal data is too small, reallocate.
|
10683
11512
|
size_t new_size = upb_Log2CeilingSize(in->size + need);
|
@@ -10693,13 +11522,30 @@ bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need,
|
|
10693
11522
|
}
|
10694
11523
|
in->ext_begin = new_ext_begin;
|
10695
11524
|
in->size = new_size;
|
10696
|
-
msg
|
11525
|
+
UPB_PRIVATE(_upb_Message_SetInternal)(msg, in);
|
10697
11526
|
}
|
10698
11527
|
|
10699
11528
|
UPB_ASSERT(in->ext_begin - in->unknown_end >= need);
|
10700
11529
|
return true;
|
10701
11530
|
}
|
10702
11531
|
|
11532
|
+
#if UPB_TRACING_ENABLED
|
11533
|
+
static void (*_new_message_trace_handler)(const upb_MiniTable*,
|
11534
|
+
const upb_Arena*);
|
11535
|
+
|
11536
|
+
void UPB_PRIVATE(upb_Message_SetNewMessageTraceHandler)(
|
11537
|
+
void (*new_message_trace_handler)(const upb_MiniTable*, const upb_Arena*)) {
|
11538
|
+
_new_message_trace_handler = new_message_trace_handler;
|
11539
|
+
}
|
11540
|
+
|
11541
|
+
void UPB_PRIVATE(upb_Message_LogNewMessage)(const upb_MiniTable* mini_table,
|
11542
|
+
const upb_Arena* arena) {
|
11543
|
+
if (_new_message_trace_handler) {
|
11544
|
+
_new_message_trace_handler(mini_table, arena);
|
11545
|
+
}
|
11546
|
+
}
|
11547
|
+
#endif
|
11548
|
+
|
10703
11549
|
|
10704
11550
|
const char _kUpb_ToBase92[] = {
|
10705
11551
|
' ', '!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/',
|
@@ -11729,7 +12575,11 @@ const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i) {
|
|
11729
12575
|
}
|
11730
12576
|
|
11731
12577
|
bool upb_EnumDef_IsClosed(const upb_EnumDef* e) {
|
11732
|
-
if (
|
12578
|
+
if (UPB_TREAT_CLOSED_ENUMS_LIKE_OPEN) return false;
|
12579
|
+
return upb_EnumDef_IsSpecifiedAsClosed(e);
|
12580
|
+
}
|
12581
|
+
|
12582
|
+
bool upb_EnumDef_IsSpecifiedAsClosed(const upb_EnumDef* e) {
|
11733
12583
|
return UPB_DESC(FeatureSet_enum_type)(e->resolved_features) ==
|
11734
12584
|
UPB_DESC(FeatureSet_CLOSED);
|
11735
12585
|
}
|
@@ -12035,15 +12885,10 @@ static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix,
|
|
12035
12885
|
static void _upb_EnumValueDef_CheckZeroValue(upb_DefBuilder* ctx,
|
12036
12886
|
const upb_EnumDef* e,
|
12037
12887
|
const upb_EnumValueDef* v, int n) {
|
12038
|
-
|
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
|
12888
|
+
// When the special UPB_TREAT_CLOSED_ENUMS_LIKE_OPEN is enabled, we have to
|
12889
|
+
// exempt closed enums from this check, even when we are treating them as
|
12042
12890
|
// open.
|
12043
|
-
if (
|
12044
|
-
upb_FileDef_Syntax(upb_EnumDef_File(e)) == kUpb_Syntax_Proto2) {
|
12045
|
-
return;
|
12046
|
-
}
|
12891
|
+
if (upb_EnumDef_IsSpecifiedAsClosed(e) || n == 0 || v[0].number == 0) return;
|
12047
12892
|
|
12048
12893
|
_upb_DefBuilder_Errf(ctx, "for open enums, the first value must be zero (%s)",
|
12049
12894
|
upb_EnumDef_FullName(e));
|
@@ -12225,27 +13070,16 @@ upb_CType upb_FieldDef_CType(const upb_FieldDef* f) {
|
|
12225
13070
|
return upb_FieldType_CType(f->type_);
|
12226
13071
|
}
|
12227
13072
|
|
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
|
-
}
|
13073
|
+
upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { return f->type_; }
|
12237
13074
|
|
12238
13075
|
uint32_t upb_FieldDef_Index(const upb_FieldDef* f) { return f->index_; }
|
12239
13076
|
|
12240
|
-
|
12241
|
-
|
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_;
|
13077
|
+
uint32_t upb_FieldDef_LayoutIndex(const upb_FieldDef* f) {
|
13078
|
+
return f->layout_index;
|
12247
13079
|
}
|
12248
13080
|
|
13081
|
+
upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { return f->label_; }
|
13082
|
+
|
12249
13083
|
uint32_t upb_FieldDef_Number(const upb_FieldDef* f) { return f->number_; }
|
12250
13084
|
|
12251
13085
|
bool upb_FieldDef_IsExtension(const upb_FieldDef* f) { return f->is_extension; }
|
@@ -12376,6 +13210,40 @@ bool _upb_FieldDef_ValidateUtf8(const upb_FieldDef* f) {
|
|
12376
13210
|
UPB_DESC(FeatureSet_VERIFY);
|
12377
13211
|
}
|
12378
13212
|
|
13213
|
+
bool _upb_FieldDef_IsGroupLike(const upb_FieldDef* f) {
|
13214
|
+
// Groups are always tag-delimited.
|
13215
|
+
if (UPB_DESC(FeatureSet_message_encoding)(upb_FieldDef_ResolvedFeatures(f)) !=
|
13216
|
+
UPB_DESC(FeatureSet_DELIMITED)) {
|
13217
|
+
return false;
|
13218
|
+
}
|
13219
|
+
|
13220
|
+
const upb_MessageDef* msg = upb_FieldDef_MessageSubDef(f);
|
13221
|
+
|
13222
|
+
// Group fields always are always the lowercase type name.
|
13223
|
+
const char* mname = upb_MessageDef_Name(msg);
|
13224
|
+
const char* fname = upb_FieldDef_Name(f);
|
13225
|
+
size_t name_size = strlen(fname);
|
13226
|
+
if (name_size != strlen(mname)) return false;
|
13227
|
+
for (size_t i = 0; i < name_size; ++i) {
|
13228
|
+
if ((mname[i] | 0x20) != fname[i]) {
|
13229
|
+
// Case-insensitive ascii comparison.
|
13230
|
+
return false;
|
13231
|
+
}
|
13232
|
+
}
|
13233
|
+
|
13234
|
+
if (upb_MessageDef_File(msg) != upb_FieldDef_File(f)) {
|
13235
|
+
return false;
|
13236
|
+
}
|
13237
|
+
|
13238
|
+
// Group messages are always defined in the same scope as the field. File
|
13239
|
+
// level extensions will compare NULL == NULL here, which is why the file
|
13240
|
+
// comparison above is necessary to ensure both come from the same file.
|
13241
|
+
return upb_FieldDef_IsExtension(f) ? upb_FieldDef_ExtensionScope(f) ==
|
13242
|
+
upb_MessageDef_ContainingType(msg)
|
13243
|
+
: upb_FieldDef_ContainingType(f) ==
|
13244
|
+
upb_MessageDef_ContainingType(msg);
|
13245
|
+
}
|
13246
|
+
|
12379
13247
|
uint64_t _upb_FieldDef_Modifiers(const upb_FieldDef* f) {
|
12380
13248
|
uint64_t out = upb_FieldDef_IsPacked(f) ? kUpb_FieldModifier_IsPacked : 0;
|
12381
13249
|
|
@@ -12707,7 +13575,6 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix,
|
|
12707
13575
|
|
12708
13576
|
const upb_StringView name = UPB_DESC(FieldDescriptorProto_name)(field_proto);
|
12709
13577
|
f->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name);
|
12710
|
-
f->label_ = (int)UPB_DESC(FieldDescriptorProto_label)(field_proto);
|
12711
13578
|
f->number_ = UPB_DESC(FieldDescriptorProto_number)(field_proto);
|
12712
13579
|
f->is_proto3_optional =
|
12713
13580
|
UPB_DESC(FieldDescriptorProto_proto3_optional)(field_proto);
|
@@ -12753,6 +13620,14 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix,
|
|
12753
13620
|
f->resolved_features = _upb_DefBuilder_DoResolveFeatures(
|
12754
13621
|
ctx, parent_features, unresolved_features, implicit);
|
12755
13622
|
|
13623
|
+
f->label_ = (int)UPB_DESC(FieldDescriptorProto_label)(field_proto);
|
13624
|
+
if (f->label_ == kUpb_Label_Optional &&
|
13625
|
+
// TODO: remove once we can deprecate kUpb_Label_Required.
|
13626
|
+
UPB_DESC(FeatureSet_field_presence)(f->resolved_features) ==
|
13627
|
+
UPB_DESC(FeatureSet_LEGACY_REQUIRED)) {
|
13628
|
+
f->label_ = kUpb_Label_Required;
|
13629
|
+
}
|
13630
|
+
|
12756
13631
|
if (!UPB_DESC(FieldDescriptorProto_has_name)(field_proto)) {
|
12757
13632
|
_upb_DefBuilder_Errf(ctx, "field has no name");
|
12758
13633
|
}
|
@@ -12772,6 +13647,12 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix,
|
|
12772
13647
|
UPB_DESC(FieldDescriptorProto_has_type_name)(field_proto);
|
12773
13648
|
|
12774
13649
|
f->type_ = (int)UPB_DESC(FieldDescriptorProto_type)(field_proto);
|
13650
|
+
if (f->type_ == kUpb_FieldType_Message &&
|
13651
|
+
// TODO: remove once we can deprecate kUpb_FieldType_Group.
|
13652
|
+
UPB_DESC(FeatureSet_message_encoding)(f->resolved_features) ==
|
13653
|
+
UPB_DESC(FeatureSet_DELIMITED)) {
|
13654
|
+
f->type_ = kUpb_FieldType_Group;
|
13655
|
+
}
|
12775
13656
|
|
12776
13657
|
if (has_type) {
|
12777
13658
|
switch (f->type_) {
|
@@ -12821,10 +13702,11 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix,
|
|
12821
13702
|
|
12822
13703
|
f->has_presence =
|
12823
13704
|
(!upb_FieldDef_IsRepeated(f)) &&
|
12824
|
-
(f->
|
12825
|
-
|
12826
|
-
|
12827
|
-
|
13705
|
+
(f->is_extension ||
|
13706
|
+
(f->type_ == kUpb_FieldType_Message ||
|
13707
|
+
f->type_ == kUpb_FieldType_Group || upb_FieldDef_ContainingOneof(f) ||
|
13708
|
+
UPB_DESC(FeatureSet_field_presence)(f->resolved_features) !=
|
13709
|
+
UPB_DESC(FeatureSet_IMPLICIT)));
|
12828
13710
|
}
|
12829
13711
|
|
12830
13712
|
static void _upb_FieldDef_CreateExt(upb_DefBuilder* ctx, const char* prefix,
|
@@ -13260,6 +14142,17 @@ const upb_MiniTableExtension* _upb_FileDef_ExtensionMiniTable(
|
|
13260
14142
|
return f->ext_layouts[i];
|
13261
14143
|
}
|
13262
14144
|
|
14145
|
+
// Note: Import cycles are not allowed so this will terminate.
|
14146
|
+
bool upb_FileDef_Resolves(const upb_FileDef* f, const char* path) {
|
14147
|
+
if (!strcmp(f->name, path)) return true;
|
14148
|
+
|
14149
|
+
for (int i = 0; i < upb_FileDef_PublicDependencyCount(f); i++) {
|
14150
|
+
const upb_FileDef* dep = upb_FileDef_PublicDependency(f, i);
|
14151
|
+
if (upb_FileDef_Resolves(dep, path)) return true;
|
14152
|
+
}
|
14153
|
+
return false;
|
14154
|
+
}
|
14155
|
+
|
13263
14156
|
static char* strviewdup(upb_DefBuilder* ctx, upb_StringView view) {
|
13264
14157
|
char* ret = upb_strdup2(view.data, view.size, _upb_DefBuilder_Arena(ctx));
|
13265
14158
|
if (!ret) _upb_DefBuilder_OomErr(ctx);
|
@@ -13311,20 +14204,35 @@ const UPB_DESC(FeatureSet*)
|
|
13311
14204
|
size_t n;
|
13312
14205
|
const UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault)* const* d =
|
13313
14206
|
UPB_DESC(FeatureSetDefaults_defaults)(defaults, &n);
|
13314
|
-
const UPB_DESC(
|
14207
|
+
const UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault)* result = NULL;
|
13315
14208
|
for (size_t i = 0; i < n; i++) {
|
13316
14209
|
if (UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_edition)(d[i]) >
|
13317
14210
|
edition) {
|
13318
14211
|
break;
|
13319
14212
|
}
|
13320
|
-
|
14213
|
+
result = d[i];
|
13321
14214
|
}
|
13322
|
-
if (
|
14215
|
+
if (result == NULL) {
|
13323
14216
|
_upb_DefBuilder_Errf(ctx, "No valid default found for edition %s",
|
13324
14217
|
upb_FileDef_EditionName(edition));
|
13325
14218
|
return NULL;
|
13326
14219
|
}
|
13327
|
-
|
14220
|
+
|
14221
|
+
// Merge the fixed and overridable features to get the edition's default
|
14222
|
+
// feature set.
|
14223
|
+
const UPB_DESC(FeatureSet)* fixed = UPB_DESC(
|
14224
|
+
FeatureSetDefaults_FeatureSetEditionDefault_fixed_features)(result);
|
14225
|
+
const UPB_DESC(FeatureSet)* overridable = UPB_DESC(
|
14226
|
+
FeatureSetDefaults_FeatureSetEditionDefault_overridable_features)(result);
|
14227
|
+
if (!fixed && !overridable) {
|
14228
|
+
_upb_DefBuilder_Errf(ctx, "No valid default found for edition %s",
|
14229
|
+
upb_FileDef_EditionName(edition));
|
14230
|
+
return NULL;
|
14231
|
+
} else if (!fixed) {
|
14232
|
+
return overridable;
|
14233
|
+
}
|
14234
|
+
return _upb_DefBuilder_DoResolveFeatures(ctx, fixed, overridable,
|
14235
|
+
/*is_implicit=*/true);
|
13328
14236
|
}
|
13329
14237
|
|
13330
14238
|
// Allocate and initialize one file def, and add it to the context object.
|
@@ -14026,7 +14934,15 @@ make:
|
|
14026
14934
|
|
14027
14935
|
bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f,
|
14028
14936
|
upb_MessageValue val, upb_Arena* a) {
|
14029
|
-
|
14937
|
+
const upb_MiniTableField* m_f = upb_FieldDef_MiniTable(f);
|
14938
|
+
|
14939
|
+
if (upb_MiniTableField_IsExtension(m_f)) {
|
14940
|
+
return upb_Message_SetExtension(msg, (const upb_MiniTableExtension*)m_f,
|
14941
|
+
&val, a);
|
14942
|
+
} else {
|
14943
|
+
upb_Message_SetBaseField(msg, m_f, &val);
|
14944
|
+
return true;
|
14945
|
+
}
|
14030
14946
|
}
|
14031
14947
|
|
14032
14948
|
void upb_Message_ClearFieldByDef(upb_Message* msg, const upb_FieldDef* f) {
|
@@ -14046,19 +14962,20 @@ void upb_Message_ClearByDef(upb_Message* msg, const upb_MessageDef* m) {
|
|
14046
14962
|
bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m,
|
14047
14963
|
const upb_DefPool* ext_pool, const upb_FieldDef** out_f,
|
14048
14964
|
upb_MessageValue* out_val, size_t* iter) {
|
14965
|
+
const upb_MiniTable* mt = upb_MessageDef_MiniTable(m);
|
14049
14966
|
size_t i = *iter;
|
14050
|
-
size_t n =
|
14967
|
+
size_t n = upb_MiniTable_FieldCount(mt);
|
14968
|
+
const upb_MessageValue zero = {0};
|
14051
14969
|
UPB_UNUSED(ext_pool);
|
14052
14970
|
|
14053
14971
|
// Iterate over normal fields, returning the first one that is set.
|
14054
14972
|
while (++i < n) {
|
14055
|
-
const
|
14056
|
-
|
14057
|
-
upb_MessageValue val = upb_Message_GetFieldByDef(msg, f);
|
14973
|
+
const upb_MiniTableField* field = upb_MiniTable_GetFieldByIndex(mt, i);
|
14974
|
+
upb_MessageValue val = upb_Message_GetField(msg, field, zero);
|
14058
14975
|
|
14059
14976
|
// Skip field if unset or empty.
|
14060
14977
|
if (upb_MiniTableField_HasPresence(field)) {
|
14061
|
-
if (!
|
14978
|
+
if (!upb_Message_HasBaseField(msg, field)) continue;
|
14062
14979
|
} else {
|
14063
14980
|
switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) {
|
14064
14981
|
case kUpb_FieldMode_Map:
|
@@ -14075,7 +14992,8 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m,
|
|
14075
14992
|
}
|
14076
14993
|
|
14077
14994
|
*out_val = val;
|
14078
|
-
*out_f =
|
14995
|
+
*out_f =
|
14996
|
+
upb_MessageDef_FindFieldByNumber(m, upb_MiniTableField_Number(field));
|
14079
14997
|
*iter = i;
|
14080
14998
|
return true;
|
14081
14999
|
}
|
@@ -14539,7 +15457,10 @@ void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m,
|
|
14539
15457
|
_upb_MessageDef_Insert(m, shortname, shortnamelen, field_v, ctx->arena);
|
14540
15458
|
if (!ok) _upb_DefBuilder_OomErr(ctx);
|
14541
15459
|
|
14542
|
-
|
15460
|
+
bool skip_json_conflicts =
|
15461
|
+
UPB_DESC(MessageOptions_deprecated_legacy_json_field_conflicts)(
|
15462
|
+
upb_MessageDef_Options(m));
|
15463
|
+
if (!skip_json_conflicts && strcmp(shortname, json_name) != 0 &&
|
14543
15464
|
UPB_DESC(FeatureSet_json_format)(m->resolved_features) ==
|
14544
15465
|
UPB_DESC(FeatureSet_ALLOW) &&
|
14545
15466
|
upb_strtable_lookup(&m->ntof, json_name, &v)) {
|
@@ -14549,14 +15470,16 @@ void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m,
|
|
14549
15470
|
}
|
14550
15471
|
|
14551
15472
|
if (upb_strtable_lookup(&m->jtof, json_name, &v)) {
|
14552
|
-
|
15473
|
+
if (!skip_json_conflicts) {
|
15474
|
+
_upb_DefBuilder_Errf(ctx, "duplicate json_name (%s)", json_name);
|
15475
|
+
}
|
15476
|
+
} else {
|
15477
|
+
const size_t json_size = strlen(json_name);
|
15478
|
+
ok = upb_strtable_insert(&m->jtof, json_name, json_size,
|
15479
|
+
upb_value_constptr(f), ctx->arena);
|
15480
|
+
if (!ok) _upb_DefBuilder_OomErr(ctx);
|
14553
15481
|
}
|
14554
15482
|
|
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
15483
|
if (upb_inttable_lookup(&m->itof, field_number, NULL)) {
|
14561
15484
|
_upb_DefBuilder_Errf(ctx, "duplicate field number (%u)", field_number);
|
14562
15485
|
}
|
@@ -14570,7 +15493,7 @@ void _upb_MessageDef_CreateMiniTable(upb_DefBuilder* ctx, upb_MessageDef* m) {
|
|
14570
15493
|
m->layout = _upb_MessageDef_MakeMiniTable(ctx, m);
|
14571
15494
|
} else {
|
14572
15495
|
m->layout = upb_MiniTableFile_Message(ctx->layout, ctx->msg_count++);
|
14573
|
-
UPB_ASSERT(m->field_count == m->layout
|
15496
|
+
UPB_ASSERT(m->field_count == upb_MiniTable_FieldCount(m->layout));
|
14574
15497
|
|
14575
15498
|
// We don't need the result of this call, but it will assign layout_index
|
14576
15499
|
// for all the fields in O(n lg n) time.
|
@@ -14628,7 +15551,7 @@ void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx,
|
|
14628
15551
|
for (int i = 0; i < m->field_count; i++) {
|
14629
15552
|
const upb_FieldDef* f = upb_MessageDef_Field(m, i);
|
14630
15553
|
const int layout_index = _upb_FieldDef_LayoutIndex(f);
|
14631
|
-
UPB_ASSERT(layout_index < m->layout
|
15554
|
+
UPB_ASSERT(layout_index < upb_MiniTable_FieldCount(m->layout));
|
14632
15555
|
const upb_MiniTableField* mt_f =
|
14633
15556
|
&m->layout->UPB_PRIVATE(fields)[layout_index];
|
14634
15557
|
UPB_ASSERT(upb_FieldDef_Type(f) == upb_MiniTableField_Type(mt_f));
|
@@ -15394,7 +16317,7 @@ upb_ServiceDef* _upb_ServiceDefs_New(upb_DefBuilder* ctx, int n,
|
|
15394
16317
|
#undef UPB_ASAN
|
15395
16318
|
#undef UPB_ASAN_GUARD_SIZE
|
15396
16319
|
#undef UPB_CLANG_ASAN
|
15397
|
-
#undef
|
16320
|
+
#undef UPB_TREAT_CLOSED_ENUMS_LIKE_OPEN
|
15398
16321
|
#undef UPB_DEPRECATED
|
15399
16322
|
#undef UPB_GNUC_MIN
|
15400
16323
|
#undef UPB_DESCRIPTOR_UPB_H_FILENAME
|