Sync from Piper @304070343
PROTOBUF_SYNC_PIPER
This commit is contained in:
parent
dec4939439
commit
b99994d994
@ -28,6 +28,8 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// LINT: ALLOW_GROUPS
|
||||
|
||||
// Benchmark messages for proto2.
|
||||
|
||||
syntax = "proto2";
|
||||
|
@ -28,8 +28,12 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// LINT: ALLOW_GROUPS
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package benchmarks.google_message3;
|
||||
|
||||
import "datasets/google_message3/benchmark_message3_1.proto";
|
||||
import "datasets/google_message3/benchmark_message3_2.proto";
|
||||
import "datasets/google_message3/benchmark_message3_3.proto";
|
||||
@ -37,7 +41,6 @@ import "datasets/google_message3/benchmark_message3_4.proto";
|
||||
import "datasets/google_message3/benchmark_message3_5.proto";
|
||||
import "datasets/google_message3/benchmark_message3_7.proto";
|
||||
import "datasets/google_message3/benchmark_message3_8.proto";
|
||||
package benchmarks.google_message3;
|
||||
|
||||
option cc_enable_arenas = true;
|
||||
option java_package = "com.google.protobuf.benchmarks";
|
||||
|
@ -28,14 +28,17 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// LINT: ALLOW_GROUPS
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package benchmarks.google_message3;
|
||||
|
||||
import "datasets/google_message3/benchmark_message3_2.proto";
|
||||
import "datasets/google_message3/benchmark_message3_3.proto";
|
||||
import "datasets/google_message3/benchmark_message3_5.proto";
|
||||
import "datasets/google_message3/benchmark_message3_7.proto";
|
||||
import "datasets/google_message3/benchmark_message3_8.proto";
|
||||
package benchmarks.google_message3;
|
||||
|
||||
option cc_enable_arenas = true;
|
||||
option java_package = "com.google.protobuf.benchmarks";
|
||||
@ -130,15 +133,13 @@ message Message36876 {
|
||||
optional int32 field37047 = 115;
|
||||
optional int32 field37048 = 157;
|
||||
}
|
||||
repeated group Message36878 = 168 {
|
||||
}
|
||||
repeated group Message36878 = 168 {}
|
||||
repeated group Message36879 = 55 {
|
||||
required string field37050 = 56;
|
||||
optional int32 field37051 = 69;
|
||||
}
|
||||
repeated .benchmarks.google_message3.UnusedEmptyMessage field36984 = 78;
|
||||
optional group Message36880 = 137 {
|
||||
}
|
||||
optional group Message36880 = 137 {}
|
||||
optional uint64 field36986 = 59;
|
||||
optional bytes field36987 = 121;
|
||||
optional .benchmarks.google_message3.UnusedEmptyMessage field36988 = 2;
|
||||
@ -154,11 +155,9 @@ message Message36876 {
|
||||
optional int32 field36998 = 47;
|
||||
optional int32 field36999 = 48;
|
||||
optional .benchmarks.google_message3.UnusedEmptyMessage field37000 = 68;
|
||||
repeated group Message36881 = 23 {
|
||||
}
|
||||
repeated group Message36881 = 23 {}
|
||||
optional .benchmarks.google_message3.Message4144 field37002 = 125;
|
||||
repeated group Message36882 = 35 {
|
||||
}
|
||||
repeated group Message36882 = 35 {}
|
||||
optional .benchmarks.google_message3.UnusedEmptyMessage field37004 = 49;
|
||||
optional .benchmarks.google_message3.Message18921 field37005 = 52;
|
||||
optional .benchmarks.google_message3.Message36858 field37006 = 46;
|
||||
@ -171,20 +170,15 @@ message Message36876 {
|
||||
optional .benchmarks.google_message3.Message0 field37013 = 143;
|
||||
optional .benchmarks.google_message3.UnusedEmptyMessage field37014 = 53;
|
||||
optional .benchmarks.google_message3.Message36869 field37015 = 15;
|
||||
optional group Message36883 = 3 {
|
||||
}
|
||||
repeated group Message36884 = 16 {
|
||||
}
|
||||
repeated group Message36885 = 27 {
|
||||
}
|
||||
optional group Message36886 = 32 {
|
||||
}
|
||||
optional group Message36883 = 3 {}
|
||||
repeated group Message36884 = 16 {}
|
||||
repeated group Message36885 = 27 {}
|
||||
optional group Message36886 = 32 {}
|
||||
repeated .benchmarks.google_message3.UnusedEnum field37020 = 71;
|
||||
repeated int32 field37021 = 70;
|
||||
optional .benchmarks.google_message3.UnusedEmptyMessage field37022 = 66;
|
||||
optional .benchmarks.google_message3.Message13090 field37023 = 67;
|
||||
optional group Message36887 = 62 {
|
||||
}
|
||||
optional group Message36887 = 62 {}
|
||||
repeated .benchmarks.google_message3.Message10155 field37025 = 50;
|
||||
repeated .benchmarks.google_message3.Message11874 field37026 = 151;
|
||||
optional string field37027 = 12;
|
||||
@ -232,8 +226,7 @@ message Message36876 {
|
||||
optional int32 field37118 = 160;
|
||||
repeated string field37119 = 161;
|
||||
}
|
||||
repeated group Message36910 = 119 {
|
||||
}
|
||||
repeated group Message36910 = 119 {}
|
||||
optional group Message36911 = 126 {
|
||||
optional .benchmarks.google_message3.UnusedEmptyMessage field37121 = 127;
|
||||
optional .benchmarks.google_message3.Message35538 field37122 = 130;
|
||||
@ -247,11 +240,9 @@ message Message36876 {
|
||||
optional .benchmarks.google_message3.UnusedEmptyMessage field37042 = 155;
|
||||
}
|
||||
|
||||
message Message1328 {
|
||||
}
|
||||
message Message1328 {}
|
||||
|
||||
message Message6850 {
|
||||
}
|
||||
message Message6850 {}
|
||||
|
||||
message Message6863 {
|
||||
optional .benchmarks.google_message3.Enum6858 field6931 = 1;
|
||||
@ -289,8 +280,7 @@ message Message6863 {
|
||||
optional bool field6963 = 34;
|
||||
}
|
||||
|
||||
message Message6871 {
|
||||
}
|
||||
message Message6871 {}
|
||||
|
||||
message Message7547 {
|
||||
required bytes field7549 = 1;
|
||||
@ -312,8 +302,7 @@ message Message7648 {
|
||||
optional bool field7680 = 12;
|
||||
}
|
||||
|
||||
message Message7865 {
|
||||
}
|
||||
message Message7865 {}
|
||||
|
||||
message Message7928 {
|
||||
optional string field7940 = 1;
|
||||
|
@ -28,14 +28,17 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// LINT: ALLOW_GROUPS
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package benchmarks.google_message3;
|
||||
|
||||
import "datasets/google_message3/benchmark_message3_3.proto";
|
||||
import "datasets/google_message3/benchmark_message3_4.proto";
|
||||
import "datasets/google_message3/benchmark_message3_5.proto";
|
||||
import "datasets/google_message3/benchmark_message3_7.proto";
|
||||
import "datasets/google_message3/benchmark_message3_8.proto";
|
||||
package benchmarks.google_message3;
|
||||
|
||||
option cc_enable_arenas = true;
|
||||
option java_package = "com.google.protobuf.benchmarks";
|
||||
@ -55,7 +58,9 @@ message Message24345 {
|
||||
optional string field24536 = 3;
|
||||
optional string field24537 = 4;
|
||||
optional .benchmarks.google_message3.UnusedEnum field24538 = 23;
|
||||
optional string field24539 = 5;
|
||||
|
||||
// LINT: ALLOW_GROUPS
|
||||
|
||||
required string field24540 = 6;
|
||||
optional string field24541 = 7;
|
||||
optional string field24542 = 8;
|
||||
@ -109,8 +114,7 @@ message Message24391 {
|
||||
repeated string field24655 = 6;
|
||||
}
|
||||
|
||||
message Message27454 {
|
||||
}
|
||||
message Message27454 {}
|
||||
|
||||
message Message27357 {
|
||||
optional string field27410 = 1;
|
||||
@ -192,8 +196,7 @@ message Message36869 {
|
||||
}
|
||||
|
||||
message Message33968 {
|
||||
repeated group Message33969 = 1 {
|
||||
}
|
||||
repeated group Message33969 = 1 {}
|
||||
repeated .benchmarks.google_message3.Message33958 field33989 = 3;
|
||||
optional .benchmarks.google_message3.UnusedEmptyMessage field33990 = 106;
|
||||
optional bool field33991 = 108;
|
||||
@ -268,8 +271,7 @@ message Message35573 {
|
||||
optional string field35696 = 1000;
|
||||
optional string field35697 = 1004;
|
||||
optional int32 field35698 = 1003;
|
||||
repeated group Message35574 = 1012 {
|
||||
}
|
||||
repeated group Message35574 = 1012 {}
|
||||
optional int64 field35700 = 1011;
|
||||
optional int64 field35701 = 1005;
|
||||
optional int64 field35702 = 1006;
|
||||
|
@ -28,13 +28,16 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// LINT: ALLOW_GROUPS
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package benchmarks.google_message3;
|
||||
|
||||
import "datasets/google_message3/benchmark_message3_4.proto";
|
||||
import "datasets/google_message3/benchmark_message3_5.proto";
|
||||
import "datasets/google_message3/benchmark_message3_7.proto";
|
||||
import "datasets/google_message3/benchmark_message3_8.proto";
|
||||
package benchmarks.google_message3;
|
||||
|
||||
option cc_enable_arenas = true;
|
||||
option java_package = "com.google.protobuf.benchmarks";
|
||||
@ -96,8 +99,7 @@ message Message2356 {
|
||||
optional bytes field2410 = 124;
|
||||
}
|
||||
optional string field2389 = 120;
|
||||
optional group Message2358 = 107 {
|
||||
}
|
||||
optional group Message2358 = 107 {}
|
||||
repeated group Message2359 = 40 {
|
||||
optional string field2413 = 41;
|
||||
optional string field2414 = 42;
|
||||
@ -438,8 +440,7 @@ message Message16724 {
|
||||
optional bool field16773 = 13;
|
||||
}
|
||||
|
||||
message Message17728 {
|
||||
}
|
||||
message Message17728 {}
|
||||
|
||||
message Message24356 {
|
||||
optional string field24559 = 1;
|
||||
|
@ -28,19 +28,21 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// LINT: ALLOW_GROUPS
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package benchmarks.google_message3;
|
||||
|
||||
import "datasets/google_message3/benchmark_message3_5.proto";
|
||||
import "datasets/google_message3/benchmark_message3_6.proto";
|
||||
import "datasets/google_message3/benchmark_message3_7.proto";
|
||||
import "datasets/google_message3/benchmark_message3_8.proto";
|
||||
package benchmarks.google_message3;
|
||||
|
||||
option cc_enable_arenas = true;
|
||||
option java_package = "com.google.protobuf.benchmarks";
|
||||
|
||||
message Message24346 {
|
||||
}
|
||||
message Message24346 {}
|
||||
|
||||
message Message24401 {
|
||||
optional .benchmarks.google_message3.Message24400 field24679 = 1;
|
||||
@ -219,12 +221,9 @@ message Message13083 {
|
||||
optional float field13099 = 45;
|
||||
optional uint64 field13100 = 46;
|
||||
optional float field13101 = 47;
|
||||
optional group Message13085 = 16 {
|
||||
}
|
||||
repeated group Message13086 = 23 {
|
||||
}
|
||||
repeated group Message13087 = 29 {
|
||||
}
|
||||
optional group Message13085 = 16 {}
|
||||
repeated group Message13086 = 23 {}
|
||||
repeated group Message13087 = 29 {}
|
||||
optional .benchmarks.google_message3.UnusedEmptyMessage field13105 = 43;
|
||||
}
|
||||
|
||||
@ -292,12 +291,10 @@ message Message16816 {
|
||||
optional float field16826 = 1;
|
||||
optional .benchmarks.google_message3.Enum16819 field16827 = 2;
|
||||
optional float field16828 = 3;
|
||||
repeated group Message16817 = 4 {
|
||||
}
|
||||
repeated group Message16817 = 4 {}
|
||||
optional bool field16830 = 7;
|
||||
optional bool field16831 = 8;
|
||||
repeated group Message16818 = 12 {
|
||||
}
|
||||
repeated group Message16818 = 12 {}
|
||||
optional string field16833 = 10;
|
||||
optional bool field16834 = 13;
|
||||
optional bool field16835 = 14;
|
||||
@ -338,11 +335,9 @@ message Message1374 {
|
||||
optional string field1376 = 2;
|
||||
}
|
||||
|
||||
message Message18943 {
|
||||
}
|
||||
message Message18943 {}
|
||||
|
||||
message Message18944 {
|
||||
}
|
||||
message Message18944 {}
|
||||
|
||||
message Message18856 {
|
||||
optional string field18857 = 1;
|
||||
@ -466,8 +461,7 @@ message Message8475 {
|
||||
optional int64 field8482 = 2;
|
||||
}
|
||||
|
||||
message Message12559 {
|
||||
}
|
||||
message Message12559 {}
|
||||
|
||||
message Message12817 {
|
||||
optional int32 field12826 = 1;
|
||||
|
@ -28,21 +28,22 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// LINT: ALLOW_GROUPS
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package benchmarks.google_message3;
|
||||
|
||||
import "datasets/google_message3/benchmark_message3_6.proto";
|
||||
import "datasets/google_message3/benchmark_message3_7.proto";
|
||||
import "datasets/google_message3/benchmark_message3_8.proto";
|
||||
package benchmarks.google_message3;
|
||||
|
||||
option cc_enable_arenas = true;
|
||||
option java_package = "com.google.protobuf.benchmarks";
|
||||
|
||||
message Message24377 {
|
||||
}
|
||||
message Message24377 {}
|
||||
|
||||
message Message24378 {
|
||||
}
|
||||
message Message24378 {}
|
||||
|
||||
message Message24400 {
|
||||
optional int32 field24674 = 1;
|
||||
@ -52,11 +53,9 @@ message Message24400 {
|
||||
optional int32 field24678 = 5;
|
||||
}
|
||||
|
||||
message Message24380 {
|
||||
}
|
||||
message Message24380 {}
|
||||
|
||||
message Message24381 {
|
||||
}
|
||||
message Message24381 {}
|
||||
|
||||
message Message719 {
|
||||
repeated string field881 = 1;
|
||||
@ -133,6 +132,7 @@ message Message697 {
|
||||
|
||||
message Message0 {
|
||||
option message_set_wire_format = true;
|
||||
|
||||
extensions 4 to 2147483646;
|
||||
}
|
||||
|
||||
@ -223,7 +223,8 @@ message Message10155 {
|
||||
optional fixed64 field10232 = 13;
|
||||
optional fixed64 field10233 = 20;
|
||||
optional bool field10234 = 79;
|
||||
repeated .benchmarks.google_message3.Enum10167 field10235 = 80 [packed = true];
|
||||
repeated .benchmarks.google_message3.Enum10167 field10235 = 80
|
||||
[packed = true];
|
||||
optional int32 field10236 = 14;
|
||||
optional int32 field10237 = 15;
|
||||
optional int32 field10238 = 28;
|
||||
@ -315,25 +316,20 @@ message Message13145 {
|
||||
extensions 1000 to 536870911;
|
||||
}
|
||||
|
||||
message Message16686 {
|
||||
}
|
||||
message Message16686 {}
|
||||
|
||||
message Message12796 {
|
||||
repeated fixed64 field12800 = 1;
|
||||
optional uint64 field12801 = 2;
|
||||
}
|
||||
|
||||
message Message6722 {
|
||||
}
|
||||
message Message6722 {}
|
||||
|
||||
message Message6727 {
|
||||
}
|
||||
message Message6727 {}
|
||||
|
||||
message Message6724 {
|
||||
}
|
||||
message Message6724 {}
|
||||
|
||||
message Message6735 {
|
||||
}
|
||||
message Message6735 {}
|
||||
|
||||
message Message8183 {
|
||||
optional string field8226 = 1;
|
||||
@ -355,8 +351,7 @@ message Message8301 {
|
||||
extensions 64 to 536870911;
|
||||
}
|
||||
|
||||
message Message8456 {
|
||||
}
|
||||
message Message8456 {}
|
||||
|
||||
message Message8302 {
|
||||
optional string field8339 = 1;
|
||||
@ -383,8 +378,7 @@ message Message8302 {
|
||||
extensions 64 to 536870911;
|
||||
}
|
||||
|
||||
message Message8457 {
|
||||
}
|
||||
message Message8457 {}
|
||||
|
||||
message Message8449 {
|
||||
optional string field8458 = 1;
|
||||
|
@ -28,17 +28,19 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// LINT: ALLOW_GROUPS
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package benchmarks.google_message3;
|
||||
|
||||
import "datasets/google_message3/benchmark_message3_7.proto";
|
||||
import "datasets/google_message3/benchmark_message3_8.proto";
|
||||
package benchmarks.google_message3;
|
||||
|
||||
option cc_enable_arenas = true;
|
||||
option java_package = "com.google.protobuf.benchmarks";
|
||||
|
||||
message Message10576 {
|
||||
}
|
||||
message Message10576 {}
|
||||
|
||||
message Message10154 {
|
||||
optional bytes field10192 = 1;
|
||||
@ -373,8 +375,7 @@ message Message8939 {
|
||||
optional string field9012 = 3;
|
||||
repeated string field9013 = 4;
|
||||
optional string field9014 = 5;
|
||||
repeated group Message8940 = 11 {
|
||||
}
|
||||
repeated group Message8940 = 11 {}
|
||||
optional int64 field9016 = 21;
|
||||
optional int64 field9017 = 22;
|
||||
optional int64 field9018 = 23;
|
||||
@ -453,8 +454,7 @@ message Message9627 {
|
||||
optional float field9672 = 5;
|
||||
}
|
||||
|
||||
message Message11020 {
|
||||
}
|
||||
message Message11020 {}
|
||||
|
||||
message Message11013 {
|
||||
optional bytes field11757 = 19;
|
||||
|
@ -35,8 +35,7 @@ package benchmarks.google_message3;
|
||||
option cc_enable_arenas = true;
|
||||
option java_package = "com.google.protobuf.benchmarks";
|
||||
|
||||
message Message11018 {
|
||||
}
|
||||
message Message11018 {}
|
||||
|
||||
message Message10800 {
|
||||
optional string field10808 = 1;
|
||||
@ -45,8 +44,7 @@ message Message10800 {
|
||||
optional float field10811 = 4;
|
||||
}
|
||||
|
||||
message Message10802 {
|
||||
}
|
||||
message Message10802 {}
|
||||
|
||||
message Message10748 {
|
||||
optional string field10750 = 1;
|
||||
@ -69,16 +67,14 @@ message Message708 {
|
||||
repeated string field828 = 5;
|
||||
}
|
||||
|
||||
message Message8942 {
|
||||
}
|
||||
message Message8942 {}
|
||||
|
||||
message Message11011 {
|
||||
required bytes field11752 = 1;
|
||||
required bytes field11753 = 2;
|
||||
}
|
||||
|
||||
message UnusedEmptyMessage {
|
||||
}
|
||||
message UnusedEmptyMessage {}
|
||||
|
||||
message Message741 {
|
||||
repeated string field936 = 1;
|
||||
|
@ -639,9 +639,7 @@ enum Enum10325 {
|
||||
ENUM_VALUE10334 = 8;
|
||||
}
|
||||
|
||||
enum Enum10335 {
|
||||
ENUM_VALUE10336 = 0;
|
||||
}
|
||||
enum Enum10335 { ENUM_VALUE10336 = 0; }
|
||||
|
||||
enum Enum10337 {
|
||||
ENUM_VALUE10338 = 0;
|
||||
@ -1887,9 +1885,7 @@ enum Enum33960 {
|
||||
ENUM_VALUE33967 = 6;
|
||||
}
|
||||
|
||||
enum Enum34388 {
|
||||
ENUM_VALUE34389 = 1;
|
||||
}
|
||||
enum Enum34388 { ENUM_VALUE34389 = 1; }
|
||||
|
||||
enum Enum35477 {
|
||||
ENUM_VALUE35478 = 4;
|
||||
|
@ -28,12 +28,15 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// LINT: ALLOW_GROUPS
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package benchmarks.google_message4;
|
||||
|
||||
import "datasets/google_message4/benchmark_message4_1.proto";
|
||||
import "datasets/google_message4/benchmark_message4_2.proto";
|
||||
import "datasets/google_message4/benchmark_message4_3.proto";
|
||||
package benchmarks.google_message4;
|
||||
|
||||
option cc_enable_arenas = true;
|
||||
option java_package = "com.google.protobuf.benchmarks";
|
||||
@ -176,8 +179,7 @@ message Message176 {
|
||||
optional .benchmarks.google_message4.UnusedEnum field455 = 37;
|
||||
optional .benchmarks.google_message4.UnusedEnum field456 = 34;
|
||||
optional int32 field457 = 35;
|
||||
repeated group Message178 = 101 {
|
||||
}
|
||||
repeated group Message178 = 101 {}
|
||||
optional bool field459 = 52;
|
||||
optional uint64 field460 = 58;
|
||||
optional uint64 field461 = 59;
|
||||
@ -458,10 +460,8 @@ message Message2356 {
|
||||
optional bytes field2410 = 124;
|
||||
}
|
||||
optional string field2389 = 120;
|
||||
optional group Message2358 = 107 {
|
||||
}
|
||||
repeated group Message2359 = 40 {
|
||||
}
|
||||
optional group Message2358 = 107 {}
|
||||
repeated group Message2359 = 40 {}
|
||||
optional int32 field2392 = 50;
|
||||
optional .benchmarks.google_message4.UnusedEmptyMessage field2393 = 60;
|
||||
optional .benchmarks.google_message4.UnusedEmptyMessage field2394 = 70;
|
||||
@ -473,6 +473,7 @@ message Message2356 {
|
||||
|
||||
message Message0 {
|
||||
option message_set_wire_format = true;
|
||||
|
||||
extensions 4 to 2147483646;
|
||||
}
|
||||
|
||||
|
@ -28,11 +28,14 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// LINT: ALLOW_GROUPS
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package benchmarks.google_message4;
|
||||
|
||||
import "datasets/google_message4/benchmark_message4_2.proto";
|
||||
import "datasets/google_message4/benchmark_message4_3.proto";
|
||||
package benchmarks.google_message4;
|
||||
|
||||
option cc_enable_arenas = true;
|
||||
option java_package = "com.google.protobuf.benchmarks";
|
||||
@ -46,8 +49,7 @@ message Message12686 {
|
||||
optional .benchmarks.google_message4.Message12685 field12700 = 2;
|
||||
}
|
||||
|
||||
message Message11949 {
|
||||
}
|
||||
message Message11949 {}
|
||||
|
||||
message Message11975 {
|
||||
optional string field11992 = 1;
|
||||
@ -134,8 +136,7 @@ message Message3061 {
|
||||
}
|
||||
optional .benchmarks.google_message4.UnusedEmptyMessage field3315 = 39;
|
||||
optional int32 field3316 = 76;
|
||||
optional group Message3065 = 63 {
|
||||
}
|
||||
optional group Message3065 = 63 {}
|
||||
optional .benchmarks.google_message4.Enum2806 field3318 = 54;
|
||||
optional int32 field3319 = 46;
|
||||
repeated string field3320 = 24;
|
||||
@ -163,8 +164,7 @@ message Message3061 {
|
||||
optional int32 field3333 = 17;
|
||||
}
|
||||
|
||||
message Message12949 {
|
||||
}
|
||||
message Message12949 {}
|
||||
|
||||
message Message8572 {
|
||||
optional bytes field8647 = 1;
|
||||
@ -269,11 +269,9 @@ message Message12825 {
|
||||
repeated .benchmarks.google_message4.UnusedEmptyMessage field12868 = 7;
|
||||
}
|
||||
|
||||
message Message8590 {
|
||||
}
|
||||
message Message8590 {}
|
||||
|
||||
message Message8587 {
|
||||
}
|
||||
message Message8587 {}
|
||||
|
||||
message Message1374 {
|
||||
required string field1375 = 1;
|
||||
@ -453,8 +451,7 @@ message Message3052 {
|
||||
optional string field3262 = 9;
|
||||
}
|
||||
|
||||
message Message8575 {
|
||||
}
|
||||
message Message8575 {}
|
||||
|
||||
message Message7843 {
|
||||
optional bool field7844 = 5;
|
||||
|
@ -30,9 +30,10 @@
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
import "datasets/google_message4/benchmark_message4_3.proto";
|
||||
package benchmarks.google_message4;
|
||||
|
||||
import "datasets/google_message4/benchmark_message4_3.proto";
|
||||
|
||||
option cc_enable_arenas = true;
|
||||
option java_package = "com.google.protobuf.benchmarks";
|
||||
|
||||
@ -132,8 +133,7 @@ message Message5881 {
|
||||
optional .benchmarks.google_message4.Message5880 field5902 = 6;
|
||||
}
|
||||
|
||||
message Message6110 {
|
||||
}
|
||||
message Message6110 {}
|
||||
|
||||
message Message6107 {
|
||||
optional .benchmarks.google_message4.Message4016 field6134 = 1;
|
||||
@ -211,8 +211,7 @@ message Message3850 {
|
||||
optional bool field3929 = 14;
|
||||
}
|
||||
|
||||
message Message7865 {
|
||||
}
|
||||
message Message7865 {}
|
||||
|
||||
message Message7511 {
|
||||
optional bool field7523 = 1;
|
||||
@ -224,8 +223,7 @@ message Message7511 {
|
||||
optional int32 field7529 = 7;
|
||||
}
|
||||
|
||||
message Message3920 {
|
||||
}
|
||||
message Message3920 {}
|
||||
|
||||
message Message7928 {
|
||||
optional string field7940 = 1;
|
||||
@ -261,8 +259,7 @@ message Message6054 {
|
||||
optional string field6090 = 2;
|
||||
}
|
||||
|
||||
message Message6127 {
|
||||
}
|
||||
message Message6127 {}
|
||||
|
||||
message Message6052 {
|
||||
required string field6084 = 1;
|
||||
@ -302,8 +299,7 @@ message Message4016 {
|
||||
required int32 field4020 = 4;
|
||||
}
|
||||
|
||||
message Message6108 {
|
||||
}
|
||||
message Message6108 {}
|
||||
|
||||
message Message5907 {
|
||||
optional .benchmarks.google_message4.Message5903 field5967 = 1;
|
||||
@ -312,8 +308,7 @@ message Message5907 {
|
||||
optional .benchmarks.google_message4.Message5903 field5970 = 4;
|
||||
}
|
||||
|
||||
message UnusedEmptyMessage {
|
||||
}
|
||||
message UnusedEmptyMessage {}
|
||||
|
||||
message Message5903 {
|
||||
required int32 field5965 = 1;
|
||||
|
@ -77,6 +77,7 @@ enum Enum2806 {
|
||||
|
||||
enum Enum2851 {
|
||||
option allow_alias = true;
|
||||
|
||||
ENUM_VALUE2852 = 0;
|
||||
ENUM_VALUE2853 = 0;
|
||||
ENUM_VALUE2854 = 1;
|
||||
@ -747,9 +748,7 @@ enum Enum10325 {
|
||||
ENUM_VALUE10334 = 8;
|
||||
}
|
||||
|
||||
enum Enum10335 {
|
||||
ENUM_VALUE10336 = 0;
|
||||
}
|
||||
enum Enum10335 { ENUM_VALUE10336 = 0; }
|
||||
|
||||
enum Enum10337 {
|
||||
ENUM_VALUE10338 = 0;
|
||||
|
@ -67,6 +67,7 @@ set(tests_protos
|
||||
google/protobuf/unittest_proto3_arena.proto
|
||||
google/protobuf/unittest_proto3_arena_lite.proto
|
||||
google/protobuf/unittest_proto3_lite.proto
|
||||
google/protobuf/unittest_proto3_optional.proto
|
||||
google/protobuf/unittest_well_known_types.proto
|
||||
google/protobuf/util/internal/testdata/anys.proto
|
||||
google/protobuf/util/internal/testdata/books.proto
|
||||
@ -93,6 +94,7 @@ macro(compile_proto_file filename)
|
||||
COMMAND protoc ${protobuf_source_dir}/src/${dirname}/${basename}.proto
|
||||
--proto_path=${protobuf_source_dir}/src
|
||||
--cpp_out=${protobuf_source_dir}/src
|
||||
--experimental_allow_proto3_optional
|
||||
)
|
||||
endmacro(compile_proto_file)
|
||||
|
||||
|
@ -2156,12 +2156,12 @@ void BinaryAndJsonConformanceSuite::RunJsonTestsForNonRepeatedTypes() {
|
||||
{
|
||||
TestAllTypesProto3 message;
|
||||
message.set_optional_double(
|
||||
WireFormatLite::DecodeDouble(0x7FFA123456789ABCLL));
|
||||
WireFormatLite::DecodeDouble(int64{0x7FFA123456789ABC}));
|
||||
RunValidJsonTestWithProtobufInput(
|
||||
"DoubleFieldNormalizeQuietNan", REQUIRED, message,
|
||||
"optional_double: nan");
|
||||
message.set_optional_double(
|
||||
WireFormatLite::DecodeDouble(0xFFFBCBA987654321LL));
|
||||
WireFormatLite::DecodeDouble(uint64{0xFFFBCBA987654321}));
|
||||
RunValidJsonTestWithProtobufInput(
|
||||
"DoubleFieldNormalizeSignalingNan", REQUIRED, message,
|
||||
"optional_double: nan");
|
||||
|
@ -157,7 +157,8 @@ def do_test(request):
|
||||
|
||||
elif request.requested_output_format == conformance_pb2.JSON:
|
||||
try:
|
||||
response.json_payload = json_format.MessageToJson(test_message)
|
||||
response.json_payload = json_format.MessageToJson(
|
||||
test_message, float_precision=None)
|
||||
except Exception as e:
|
||||
response.serialize_error = str(e)
|
||||
return response
|
||||
|
@ -313,6 +313,66 @@ void TextFormatConformanceTestSuite::RunSuiteImpl() {
|
||||
}
|
||||
}
|
||||
)");
|
||||
|
||||
// Map fields
|
||||
TestAllTypesProto3 prototype;
|
||||
(*prototype.mutable_map_string_string())["c"] = "value";
|
||||
(*prototype.mutable_map_string_string())["b"] = "value";
|
||||
(*prototype.mutable_map_string_string())["a"] = "value";
|
||||
RunValidTextFormatTestWithMessage("AlphabeticallySortedMapStringKeys",
|
||||
REQUIRED,
|
||||
R"(
|
||||
map_string_string {
|
||||
key: "a"
|
||||
value: "value"
|
||||
}
|
||||
map_string_string {
|
||||
key: "b"
|
||||
value: "value"
|
||||
}
|
||||
map_string_string {
|
||||
key: "c"
|
||||
value: "value"
|
||||
}
|
||||
)",
|
||||
prototype);
|
||||
|
||||
prototype.Clear();
|
||||
(*prototype.mutable_map_int32_int32())[3] = 0;
|
||||
(*prototype.mutable_map_int32_int32())[2] = 0;
|
||||
(*prototype.mutable_map_int32_int32())[1] = 0;
|
||||
RunValidTextFormatTestWithMessage("AlphabeticallySortedMapIntKeys", REQUIRED,
|
||||
R"(
|
||||
map_int32_int32 {
|
||||
key: 1
|
||||
value: 0
|
||||
}
|
||||
map_int32_int32 {
|
||||
key: 2
|
||||
value: 0
|
||||
}
|
||||
map_int32_int32 {
|
||||
key: 3
|
||||
value: 0
|
||||
}
|
||||
)",
|
||||
prototype);
|
||||
|
||||
prototype.Clear();
|
||||
(*prototype.mutable_map_bool_bool())[true] = false;
|
||||
(*prototype.mutable_map_bool_bool())[false] = false;
|
||||
RunValidTextFormatTestWithMessage("AlphabeticallySortedMapBoolKeys", REQUIRED,
|
||||
R"(
|
||||
map_bool_bool {
|
||||
key: false
|
||||
value: false
|
||||
}
|
||||
map_bool_bool {
|
||||
key: true
|
||||
value: false
|
||||
}
|
||||
)",
|
||||
prototype);
|
||||
}
|
||||
|
||||
} // namespace protobuf
|
||||
|
@ -140,6 +140,26 @@ final class BooleanArrayList extends AbstractProtobufList<Boolean>
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Object element) {
|
||||
if (!(element instanceof Boolean)) {
|
||||
return -1;
|
||||
}
|
||||
boolean unboxedElement = (Boolean) element;
|
||||
int numElems = size();
|
||||
for (int i = 0; i < numElems; i++) {
|
||||
if (array[i] == unboxedElement) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object element) {
|
||||
return indexOf(element) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
|
@ -484,7 +484,7 @@ public abstract class CodedInputStream {
|
||||
* Returns true if the stream has reached the end of the input. This is the case if either the end
|
||||
* of the underlying input source has been reached or if the stream has reached a limit created
|
||||
* using {@link #pushLimit(int)}. This function may get blocked when using StreamDecoder as it
|
||||
* invokes {@link #StreamDecoder.tryRefillBuffer(int)} in this function which will try to read
|
||||
* invokes {@link StreamDecoder#tryRefillBuffer(int)} in this function which will try to read
|
||||
* bytes from input.
|
||||
*/
|
||||
public abstract boolean isAtEnd() throws IOException;
|
||||
|
@ -1125,6 +1125,34 @@ public final class Descriptors {
|
||||
return containingOneof;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this field was syntactically written with "optional" in the .proto file.
|
||||
* Excludes singular proto3 fields that do not have a label.
|
||||
*/
|
||||
public boolean hasOptionalKeyword() {
|
||||
return isProto3Optional
|
||||
|| (file.getSyntax() == Syntax.PROTO2 && isOptional() && getContainingOneof() == null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this is a non-oneof field that tracks presence.
|
||||
*
|
||||
* <p>This includes all "required" and "optional" fields in the .proto file, but excludes oneof
|
||||
* fields and singular proto3 fields without "optional".
|
||||
*
|
||||
* <p>In implementations that use hasbits, this method will probably indicate whether this field
|
||||
* uses a hasbit.
|
||||
*/
|
||||
boolean isSingularWithPresence() {
|
||||
if (isRepeated()) {
|
||||
return false;
|
||||
}
|
||||
if (getContainingOneof() != null && !getContainingOneof().isSynthetic()) {
|
||||
return false;
|
||||
}
|
||||
return getType() == Type.MESSAGE || isProto3Optional || file.getSyntax() == Syntax.PROTO2;
|
||||
}
|
||||
|
||||
/**
|
||||
* For extensions defined nested within message types, gets the outer type. Not valid for
|
||||
* non-extension fields. For example, consider this {@code .proto} file:
|
||||
@ -1203,6 +1231,7 @@ public final class Descriptors {
|
||||
private final String jsonName;
|
||||
private final FileDescriptor file;
|
||||
private final Descriptor extensionScope;
|
||||
private final boolean isProto3Optional;
|
||||
|
||||
// Possibly initialized during cross-linking.
|
||||
private Type type;
|
||||
@ -1327,6 +1356,8 @@ public final class Descriptors {
|
||||
type = Type.valueOf(proto.getType());
|
||||
}
|
||||
|
||||
isProto3Optional = proto.getProto3Optional();
|
||||
|
||||
if (getNumber() <= 0) {
|
||||
throw new DescriptorValidationException(this, "Field numbers must be positive integers.");
|
||||
}
|
||||
@ -2627,6 +2658,10 @@ public final class Descriptors {
|
||||
return proto.getOptions();
|
||||
}
|
||||
|
||||
public boolean isSynthetic() {
|
||||
return fields.length == 1 && fields[0].isProto3Optional;
|
||||
}
|
||||
|
||||
/** Get a list of this message type's fields. */
|
||||
public List<FieldDescriptor> getFields() {
|
||||
return Collections.unmodifiableList(Arrays.asList(fields));
|
||||
|
@ -140,6 +140,26 @@ final class DoubleArrayList extends AbstractProtobufList<Double>
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Object element) {
|
||||
if (!(element instanceof Double)) {
|
||||
return -1;
|
||||
}
|
||||
double unboxedElement = (Double) element;
|
||||
int numElems = size();
|
||||
for (int i = 0; i < numElems; i++) {
|
||||
if (array[i] == unboxedElement) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object element) {
|
||||
return indexOf(element) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
|
@ -139,6 +139,26 @@ final class FloatArrayList extends AbstractProtobufList<Float>
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Object element) {
|
||||
if (!(element instanceof Float)) {
|
||||
return -1;
|
||||
}
|
||||
float unboxedElement = (Float) element;
|
||||
int numElems = size();
|
||||
for (int i = 0; i < numElems; i++) {
|
||||
if (array[i] == unboxedElement) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object element) {
|
||||
return indexOf(element) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
|
@ -121,7 +121,11 @@ public abstract class GeneratedMessageLite<
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!getDefaultInstanceForType().getClass().isInstance(other)) {
|
||||
if (other == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.getClass() != other.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1987,9 +1987,9 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
|
||||
|
||||
int oneofsSize = oneofs.length;
|
||||
for (int i = 0; i < oneofsSize; i++) {
|
||||
oneofs[i] = new OneofAccessor(
|
||||
descriptor, camelCaseNames[i + fieldsSize],
|
||||
messageClass, builderClass);
|
||||
oneofs[i] =
|
||||
new OneofAccessor(
|
||||
descriptor, i, camelCaseNames[i + fieldsSize], messageClass, builderClass);
|
||||
}
|
||||
initialized = true;
|
||||
camelCaseNames = null;
|
||||
@ -2057,14 +2057,22 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
|
||||
/** OneofAccessor provides access to a single oneof. */
|
||||
private static class OneofAccessor {
|
||||
OneofAccessor(
|
||||
final Descriptor descriptor, final String camelCaseName,
|
||||
final Descriptor descriptor,
|
||||
final int oneofIndex,
|
||||
final String camelCaseName,
|
||||
final Class<? extends GeneratedMessageV3> messageClass,
|
||||
final Class<? extends Builder> builderClass) {
|
||||
this.descriptor = descriptor;
|
||||
caseMethod =
|
||||
getMethodOrDie(messageClass, "get" + camelCaseName + "Case");
|
||||
caseMethodBuilder =
|
||||
getMethodOrDie(builderClass, "get" + camelCaseName + "Case");
|
||||
OneofDescriptor oneofDescriptor = descriptor.getOneofs().get(oneofIndex);
|
||||
if (oneofDescriptor.isSynthetic()) {
|
||||
caseMethod = null;
|
||||
caseMethodBuilder = null;
|
||||
fieldDescriptor = oneofDescriptor.getFields().get(0);
|
||||
} else {
|
||||
caseMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Case");
|
||||
caseMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Case");
|
||||
fieldDescriptor = null;
|
||||
}
|
||||
clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName);
|
||||
}
|
||||
|
||||
@ -2072,33 +2080,51 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
|
||||
private final Method caseMethod;
|
||||
private final Method caseMethodBuilder;
|
||||
private final Method clearMethod;
|
||||
private final FieldDescriptor fieldDescriptor;
|
||||
|
||||
public boolean has(final GeneratedMessageV3 message) {
|
||||
if (((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber() == 0) {
|
||||
return false;
|
||||
if (fieldDescriptor != null) {
|
||||
return message.hasField(fieldDescriptor);
|
||||
} else {
|
||||
if (((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber() == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean has(GeneratedMessageV3.Builder builder) {
|
||||
if (((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber() == 0) {
|
||||
return false;
|
||||
if (fieldDescriptor != null) {
|
||||
return builder.hasField(fieldDescriptor);
|
||||
} else {
|
||||
if (((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber() == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public FieldDescriptor get(final GeneratedMessageV3 message) {
|
||||
int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber();
|
||||
if (fieldNumber > 0) {
|
||||
return descriptor.findFieldByNumber(fieldNumber);
|
||||
if (fieldDescriptor != null) {
|
||||
return message.hasField(fieldDescriptor) ? fieldDescriptor : null;
|
||||
} else {
|
||||
int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber();
|
||||
if (fieldNumber > 0) {
|
||||
return descriptor.findFieldByNumber(fieldNumber);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public FieldDescriptor get(GeneratedMessageV3.Builder builder) {
|
||||
int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber();
|
||||
if (fieldNumber > 0) {
|
||||
return descriptor.findFieldByNumber(fieldNumber);
|
||||
if (fieldDescriptor != null) {
|
||||
return builder.hasField(fieldDescriptor) ? fieldDescriptor : null;
|
||||
} else {
|
||||
int fieldNumber =
|
||||
((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber();
|
||||
if (fieldNumber > 0) {
|
||||
return descriptor.findFieldByNumber(fieldNumber);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -2108,10 +2134,6 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean supportFieldPresence(FileDescriptor file) {
|
||||
return file.getSyntax() == FileDescriptor.Syntax.PROTO2;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
private static class SingularFieldAccessor implements FieldAccessor {
|
||||
@ -2216,9 +2238,13 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
|
||||
final Class<? extends GeneratedMessageV3> messageClass,
|
||||
final Class<? extends Builder> builderClass,
|
||||
final String containingOneofCamelCaseName) {
|
||||
isOneofField = descriptor.getContainingOneof() != null;
|
||||
hasHasMethod = supportFieldPresence(descriptor.getFile())
|
||||
|| (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE);
|
||||
isOneofField =
|
||||
descriptor.getContainingOneof() != null
|
||||
&& !descriptor.getContainingOneof().isSynthetic();
|
||||
hasHasMethod =
|
||||
descriptor.getFile().getSyntax() == FileDescriptor.Syntax.PROTO2
|
||||
|| descriptor.hasOptionalKeyword()
|
||||
|| (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE);
|
||||
ReflectionInvoker reflectionInvoker =
|
||||
new ReflectionInvoker(
|
||||
descriptor,
|
||||
|
@ -139,6 +139,26 @@ final class IntArrayList extends AbstractProtobufList<Integer>
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Object element) {
|
||||
if (!(element instanceof Integer)) {
|
||||
return -1;
|
||||
}
|
||||
int unboxedElement = (Integer) element;
|
||||
int numElems = size();
|
||||
for (int i = 0; i < numElems; i++) {
|
||||
if (array[i] == unboxedElement) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object element) {
|
||||
return indexOf(element) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
|
@ -139,6 +139,26 @@ final class LongArrayList extends AbstractProtobufList<Long>
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Object element) {
|
||||
if (!(element instanceof Long)) {
|
||||
return -1;
|
||||
}
|
||||
long unboxedElement = (Long) element;
|
||||
int numElems = size();
|
||||
for (int i = 0; i < numElems; i++) {
|
||||
if (array[i] == unboxedElement) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object element) {
|
||||
return indexOf(element) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
|
@ -89,6 +89,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
private static final int FIELD_TYPE_MASK = 0x0FF00000;
|
||||
private static final int REQUIRED_MASK = 0x10000000;
|
||||
private static final int ENFORCE_UTF8_MASK = 0x20000000;
|
||||
private static final int NO_PRESENCE_SENTINEL = -1 & OFFSET_MASK;
|
||||
private static final int[] EMPTY_INT_ARRAY = new int[0];
|
||||
|
||||
/** An offset applied to the field type ID for scalar fields that are a member of a oneof. */
|
||||
@ -118,6 +119,11 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
* [70 - 75] field presence mask shift (unused for oneof/repeated fields)
|
||||
* [76 - 95] presence field offset / oneof case field offset / cached size field offset
|
||||
* </pre>
|
||||
*
|
||||
* Note that presence field offset can only use 20 bits - 1. All bits set to 1 is the sentinel
|
||||
* value for non-presence. This is not validated at runtime, we simply assume message layouts
|
||||
* will not exceed 1MB (assuming ~10 bytes per field, that implies 100k fields which should hit
|
||||
* other javac limits first).
|
||||
*/
|
||||
private final int[] buffer;
|
||||
|
||||
@ -260,7 +266,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
}
|
||||
next = result | (next << shift);
|
||||
}
|
||||
final int flags = next;
|
||||
final int unusedFlags = next;
|
||||
|
||||
next = info.charAt(i++);
|
||||
if (next >= 0xD800) {
|
||||
@ -464,8 +470,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
|| oneofFieldType == 17 /* FieldType.GROUP */) {
|
||||
objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageInfoObjects[objectsPosition++];
|
||||
} else if (oneofFieldType == 12 /* FieldType.ENUM */) {
|
||||
// proto2
|
||||
if ((flags & 0x1) == 0x1) {
|
||||
if (!isProto3) {
|
||||
objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageInfoObjects[objectsPosition++];
|
||||
}
|
||||
}
|
||||
@ -508,7 +513,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
} else if (fieldType == 12 /* FieldType.ENUM */
|
||||
|| fieldType == 30 /* FieldType.ENUM_LIST */
|
||||
|| fieldType == 44 /* FieldType.ENUM_LIST_PACKED */) {
|
||||
if ((flags & 0x1) == 0x1) {
|
||||
if (!isProto3) {
|
||||
objects[bufferIndex / INTS_PER_FIELD * 2 + 1] = messageInfoObjects[objectsPosition++];
|
||||
}
|
||||
} else if (fieldType == 50 /* FieldType.MAP */) {
|
||||
@ -520,7 +525,8 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
}
|
||||
|
||||
fieldOffset = (int) unsafe.objectFieldOffset(field);
|
||||
if ((flags & 0x1) == 0x1 && fieldType <= 17 /* FieldType.GROUP */) {
|
||||
boolean hasHasBit = (fieldTypeWithExtraBits & 0x1000) == 0x1000;
|
||||
if (hasHasBit && fieldType <= 17 /* FieldType.GROUP */) {
|
||||
next = info.charAt(i++);
|
||||
if (next >= 0xD800) {
|
||||
int result = next & 0x1FFF;
|
||||
@ -546,7 +552,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
presenceFieldOffset = (int) unsafe.objectFieldOffset(hasBitsField);
|
||||
presenceMaskShift = hasBitsIndex % 32;
|
||||
} else {
|
||||
presenceFieldOffset = 0;
|
||||
presenceFieldOffset = NO_PRESENCE_SENTINEL;
|
||||
presenceMaskShift = 0;
|
||||
}
|
||||
|
||||
@ -662,7 +668,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
|
||||
// We found the entry for the next field. Store the entry in the manifest for
|
||||
// this field and increment the field index.
|
||||
storeFieldData(fi, buffer, bufferIndex, isProto3, objects);
|
||||
storeFieldData(fi, buffer, bufferIndex, objects);
|
||||
|
||||
// Convert field number to index
|
||||
if (checkInitializedIndex < checkInitialized.length
|
||||
@ -719,7 +725,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
}
|
||||
|
||||
private static void storeFieldData(
|
||||
FieldInfo fi, int[] buffer, int bufferIndex, boolean proto3, Object[] objects) {
|
||||
FieldInfo fi, int[] buffer, int bufferIndex, Object[] objects) {
|
||||
final int fieldOffset;
|
||||
final int typeId;
|
||||
final int presenceMaskShift;
|
||||
@ -735,8 +741,13 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
FieldType type = fi.getType();
|
||||
fieldOffset = (int) UnsafeUtil.objectFieldOffset(fi.getField());
|
||||
typeId = type.id();
|
||||
if (!proto3 && !type.isList() && !type.isMap()) {
|
||||
presenceFieldOffset = (int) UnsafeUtil.objectFieldOffset(fi.getPresenceField());
|
||||
if (!type.isList() && !type.isMap()) {
|
||||
Field presenceField = fi.getPresenceField();
|
||||
if (presenceField == null) {
|
||||
presenceFieldOffset = NO_PRESENCE_SENTINEL;
|
||||
} else {
|
||||
presenceFieldOffset = (int) UnsafeUtil.objectFieldOffset(presenceField);
|
||||
}
|
||||
presenceMaskShift = Integer.numberOfTrailingZeros(fi.getPresenceMask());
|
||||
} else {
|
||||
if (fi.getCachedSizeField() == null) {
|
||||
@ -1408,13 +1419,13 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
public int getSerializedSize(T message) {
|
||||
return proto3 ? getSerializedSizeProto3(message) : getSerializedSizeProto2(message);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private int getSerializedSizeProto2(T message) {
|
||||
int size = 0;
|
||||
|
||||
final sun.misc.Unsafe unsafe = UNSAFE;
|
||||
int currentPresenceFieldOffset = -1;
|
||||
int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL;
|
||||
int currentPresenceField = 0;
|
||||
for (int i = 0; i < buffer.length; i += INTS_PER_FIELD) {
|
||||
final int typeAndOffset = typeAndOffsetAt(i);
|
||||
@ -2548,7 +2559,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
nextExtension = extensionIterator.next();
|
||||
}
|
||||
}
|
||||
int currentPresenceFieldOffset = -1;
|
||||
int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL;
|
||||
int currentPresenceField = 0;
|
||||
final int bufferLength = buffer.length;
|
||||
final sun.misc.Unsafe unsafe = UNSAFE;
|
||||
@ -2924,7 +2935,6 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
nextExtension = extensionIterator.next();
|
||||
}
|
||||
}
|
||||
|
||||
final int bufferLength = buffer.length;
|
||||
for (int pos = 0; pos < bufferLength; pos += INTS_PER_FIELD) {
|
||||
final int typeAndOffset = typeAndOffsetAt(pos);
|
||||
@ -4867,7 +4877,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
T message, byte[] data, int position, int limit, int endGroup, Registers registers)
|
||||
throws IOException {
|
||||
final sun.misc.Unsafe unsafe = UNSAFE;
|
||||
int currentPresenceFieldOffset = -1;
|
||||
int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL;
|
||||
int currentPresenceField = 0;
|
||||
int tag = 0;
|
||||
int oldNumber = -1;
|
||||
@ -4901,7 +4911,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
// We cache the 32-bit has-bits integer value and only write it back when parsing a field
|
||||
// using a different has-bits integer.
|
||||
if (presenceFieldOffset != currentPresenceFieldOffset) {
|
||||
if (currentPresenceFieldOffset != -1) {
|
||||
if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) {
|
||||
unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField);
|
||||
}
|
||||
currentPresenceFieldOffset = presenceFieldOffset;
|
||||
@ -5143,7 +5153,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
tag, data, position, limit, getMutableUnknownFields(message), registers);
|
||||
}
|
||||
}
|
||||
if (currentPresenceFieldOffset != -1) {
|
||||
if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) {
|
||||
unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField);
|
||||
}
|
||||
UnknownFieldSetLite unknownFields = null;
|
||||
@ -5175,6 +5185,8 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
private int parseProto3Message(
|
||||
T message, byte[] data, int position, int limit, Registers registers) throws IOException {
|
||||
final sun.misc.Unsafe unsafe = UNSAFE;
|
||||
int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL;
|
||||
int currentPresenceField = 0;
|
||||
int tag = 0;
|
||||
int oldNumber = -1;
|
||||
int pos = 0;
|
||||
@ -5200,11 +5212,30 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
final int fieldType = type(typeAndOffset);
|
||||
final long fieldOffset = offset(typeAndOffset);
|
||||
if (fieldType <= 17) {
|
||||
// Proto3 optional fields have has-bits.
|
||||
final int presenceMaskAndOffset = buffer[pos + 2];
|
||||
final int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS);
|
||||
final int presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK;
|
||||
// We cache the 32-bit has-bits integer value and only write it back when parsing a field
|
||||
// using a different has-bits integer.
|
||||
//
|
||||
// Note that for fields that do not have hasbits, we unconditionally write and discard
|
||||
// the data.
|
||||
if (presenceFieldOffset != currentPresenceFieldOffset) {
|
||||
if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) {
|
||||
unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField);
|
||||
}
|
||||
if (presenceFieldOffset != NO_PRESENCE_SENTINEL) {
|
||||
currentPresenceField = unsafe.getInt(message, (long) presenceFieldOffset);
|
||||
}
|
||||
currentPresenceFieldOffset = presenceFieldOffset;
|
||||
}
|
||||
switch (fieldType) {
|
||||
case 0: // DOUBLE:
|
||||
if (wireType == WireFormat.WIRETYPE_FIXED64) {
|
||||
UnsafeUtil.putDouble(message, fieldOffset, decodeDouble(data, position));
|
||||
position += 8;
|
||||
currentPresenceField |= presenceMask;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@ -5212,6 +5243,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
if (wireType == WireFormat.WIRETYPE_FIXED32) {
|
||||
UnsafeUtil.putFloat(message, fieldOffset, decodeFloat(data, position));
|
||||
position += 4;
|
||||
currentPresenceField |= presenceMask;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@ -5220,6 +5252,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
if (wireType == WireFormat.WIRETYPE_VARINT) {
|
||||
position = decodeVarint64(data, position, registers);
|
||||
unsafe.putLong(message, fieldOffset, registers.long1);
|
||||
currentPresenceField |= presenceMask;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@ -5228,6 +5261,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
if (wireType == WireFormat.WIRETYPE_VARINT) {
|
||||
position = decodeVarint32(data, position, registers);
|
||||
unsafe.putInt(message, fieldOffset, registers.int1);
|
||||
currentPresenceField |= presenceMask;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@ -5236,6 +5270,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
if (wireType == WireFormat.WIRETYPE_FIXED64) {
|
||||
unsafe.putLong(message, fieldOffset, decodeFixed64(data, position));
|
||||
position += 8;
|
||||
currentPresenceField |= presenceMask;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@ -5244,6 +5279,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
if (wireType == WireFormat.WIRETYPE_FIXED32) {
|
||||
unsafe.putInt(message, fieldOffset, decodeFixed32(data, position));
|
||||
position += 4;
|
||||
currentPresenceField |= presenceMask;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@ -5251,6 +5287,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
if (wireType == WireFormat.WIRETYPE_VARINT) {
|
||||
position = decodeVarint64(data, position, registers);
|
||||
UnsafeUtil.putBoolean(message, fieldOffset, registers.long1 != 0);
|
||||
currentPresenceField |= presenceMask;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@ -5262,6 +5299,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
position = decodeStringRequireUtf8(data, position, registers);
|
||||
}
|
||||
unsafe.putObject(message, fieldOffset, registers.object1);
|
||||
currentPresenceField |= presenceMask;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@ -5277,6 +5315,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
unsafe.putObject(
|
||||
message, fieldOffset, Internal.mergeMessage(oldValue, registers.object1));
|
||||
}
|
||||
currentPresenceField |= presenceMask;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@ -5284,6 +5323,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) {
|
||||
position = decodeBytes(data, position, registers);
|
||||
unsafe.putObject(message, fieldOffset, registers.object1);
|
||||
currentPresenceField |= presenceMask;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@ -5291,6 +5331,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
if (wireType == WireFormat.WIRETYPE_VARINT) {
|
||||
position = decodeVarint32(data, position, registers);
|
||||
unsafe.putInt(message, fieldOffset, registers.int1);
|
||||
currentPresenceField |= presenceMask;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@ -5299,6 +5340,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
position = decodeVarint32(data, position, registers);
|
||||
unsafe.putInt(
|
||||
message, fieldOffset, CodedInputStream.decodeZigZag32(registers.int1));
|
||||
currentPresenceField |= presenceMask;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@ -5307,6 +5349,7 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
position = decodeVarint64(data, position, registers);
|
||||
unsafe.putLong(
|
||||
message, fieldOffset, CodedInputStream.decodeZigZag64(registers.long1));
|
||||
currentPresenceField |= presenceMask;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@ -5381,6 +5424,9 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
position = decodeUnknownField(
|
||||
tag, data, position, limit, getMutableUnknownFields(message), registers);
|
||||
}
|
||||
if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) {
|
||||
unsafe.putInt(message, (long) currentPresenceFieldOffset, currentPresenceField);
|
||||
}
|
||||
if (position != limit) {
|
||||
throw InvalidProtocolBufferException.parseFailure();
|
||||
}
|
||||
@ -5502,28 +5548,26 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
|
||||
@Override
|
||||
public final boolean isInitialized(T message) {
|
||||
int currentPresenceFieldOffset = -1;
|
||||
int currentPresenceFieldOffset = NO_PRESENCE_SENTINEL;
|
||||
int currentPresenceField = 0;
|
||||
for (int i = 0; i < checkInitializedCount; i++) {
|
||||
final int pos = intArray[i];
|
||||
final int number = numberAt(pos);
|
||||
|
||||
final int typeAndOffset = typeAndOffsetAt(pos);
|
||||
|
||||
int presenceMaskAndOffset = 0;
|
||||
int presenceMask = 0;
|
||||
if (!proto3) {
|
||||
presenceMaskAndOffset = buffer[pos + 2];
|
||||
final int presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK;
|
||||
presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS);
|
||||
if (presenceFieldOffset != currentPresenceFieldOffset) {
|
||||
currentPresenceFieldOffset = presenceFieldOffset;
|
||||
int presenceMaskAndOffset = buffer[pos + 2];
|
||||
final int presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK;
|
||||
int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS);
|
||||
if (presenceFieldOffset != currentPresenceFieldOffset) {
|
||||
currentPresenceFieldOffset = presenceFieldOffset;
|
||||
if (currentPresenceFieldOffset != NO_PRESENCE_SENTINEL) {
|
||||
currentPresenceField = UNSAFE.getInt(message, (long) presenceFieldOffset);
|
||||
}
|
||||
}
|
||||
|
||||
if (isRequired(typeAndOffset)) {
|
||||
if (!isFieldPresent(message, pos, currentPresenceField, presenceMask)) {
|
||||
if (!isFieldPresent(
|
||||
message, pos, currentPresenceFieldOffset, currentPresenceField, presenceMask)) {
|
||||
return false;
|
||||
}
|
||||
// If a required message field is set but has no required fields of it's own, we still
|
||||
@ -5534,7 +5578,8 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
switch (type(typeAndOffset)) {
|
||||
case 9: // MESSAGE
|
||||
case 17: // GROUP
|
||||
if (isFieldPresent(message, pos, currentPresenceField, presenceMask)
|
||||
if (isFieldPresent(
|
||||
message, pos, currentPresenceFieldOffset, currentPresenceField, presenceMask)
|
||||
&& !isInitialized(message, typeAndOffset, getMessageFieldSchema(pos))) {
|
||||
return false;
|
||||
}
|
||||
@ -5744,8 +5789,9 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
return isFieldPresent(message, pos) == isFieldPresent(other, pos);
|
||||
}
|
||||
|
||||
private boolean isFieldPresent(T message, int pos, int presenceField, int presenceMask) {
|
||||
if (proto3) {
|
||||
private boolean isFieldPresent(
|
||||
T message, int pos, int presenceFieldOffset, int presenceField, int presenceMask) {
|
||||
if (presenceFieldOffset == NO_PRESENCE_SENTINEL) {
|
||||
return isFieldPresent(message, pos);
|
||||
} else {
|
||||
return (presenceField & presenceMask) != 0;
|
||||
@ -5753,7 +5799,9 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
}
|
||||
|
||||
private boolean isFieldPresent(T message, int pos) {
|
||||
if (proto3) {
|
||||
final int presenceMaskAndOffset = presenceMaskAndOffsetAt(pos);
|
||||
final long presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK;
|
||||
if (presenceFieldOffset == NO_PRESENCE_SENTINEL) {
|
||||
final int typeAndOffset = typeAndOffsetAt(pos);
|
||||
final long offset = offset(typeAndOffset);
|
||||
switch (type(typeAndOffset)) {
|
||||
@ -5804,20 +5852,18 @@ final class MessageSchema<T> implements Schema<T> {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
} else {
|
||||
int presenceMaskAndOffset = presenceMaskAndOffsetAt(pos);
|
||||
final int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS);
|
||||
return (UnsafeUtil.getInt(message, presenceMaskAndOffset & OFFSET_MASK) & presenceMask) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void setFieldPresent(T message, int pos) {
|
||||
if (proto3) {
|
||||
// Proto3 doesn't have presence fields
|
||||
int presenceMaskAndOffset = presenceMaskAndOffsetAt(pos);
|
||||
final long presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK;
|
||||
if (presenceFieldOffset == NO_PRESENCE_SENTINEL) {
|
||||
return;
|
||||
}
|
||||
int presenceMaskAndOffset = presenceMaskAndOffsetAt(pos);
|
||||
final int presenceMask = 1 << (presenceMaskAndOffset >>> OFFSET_BITS);
|
||||
final long presenceFieldOffset = presenceMaskAndOffset & OFFSET_MASK;
|
||||
UnsafeUtil.putInt(
|
||||
message,
|
||||
presenceFieldOffset,
|
||||
|
@ -96,7 +96,7 @@ final class RawMessageInfo implements MessageInfo {
|
||||
* If the field is in an oneof:
|
||||
*
|
||||
* <ul>
|
||||
* <li>[2]: oenof index
|
||||
* <li>[2]: oneof index
|
||||
* </ul>
|
||||
*
|
||||
* For other types, the field entry only has field number and field type.
|
||||
|
@ -346,9 +346,8 @@ public class RepeatedFieldBuilder<
|
||||
// If we can inspect the size, we can more efficiently add messages.
|
||||
int size = -1;
|
||||
if (values instanceof Collection) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final Collection<MType> collection = (Collection<MType>) values;
|
||||
if (collection.size() == 0) {
|
||||
final Collection<?> collection = (Collection<?>) values;
|
||||
if (collection.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
size = collection.size();
|
||||
@ -408,8 +407,7 @@ public class RepeatedFieldBuilder<
|
||||
|
||||
/**
|
||||
* Removes the element at the specified position in this list. Shifts any subsequent elements to
|
||||
* the left (subtracts one from their indices). Returns the element that was removed from the
|
||||
* list.
|
||||
* the left (subtracts one from their indices).
|
||||
*
|
||||
* @param index the index at which to remove the message
|
||||
*/
|
||||
|
@ -346,9 +346,8 @@ public class RepeatedFieldBuilderV3<
|
||||
// If we can inspect the size, we can more efficiently add messages.
|
||||
int size = -1;
|
||||
if (values instanceof Collection) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final Collection<MType> collection = (Collection<MType>) values;
|
||||
if (collection.size() == 0) {
|
||||
final Collection<?> collection = (Collection<?>) values;
|
||||
if (collection.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
size = collection.size();
|
||||
@ -408,8 +407,7 @@ public class RepeatedFieldBuilderV3<
|
||||
|
||||
/**
|
||||
* Removes the element at the specified position in this list. Shifts any subsequent elements to
|
||||
* the left (subtracts one from their indices). Returns the element that was removed from the
|
||||
* list.
|
||||
* the left (subtracts one from their indices).
|
||||
*
|
||||
* @param index the index at which to remove the message
|
||||
*/
|
||||
|
@ -34,10 +34,12 @@ import com.google.protobuf.Descriptors.Descriptor;
|
||||
import com.google.protobuf.Descriptors.EnumDescriptor;
|
||||
import com.google.protobuf.Descriptors.EnumValueDescriptor;
|
||||
import com.google.protobuf.Descriptors.FieldDescriptor;
|
||||
import com.google.protobuf.MessageReflection.MergeTarget;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.CharBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@ -137,7 +139,7 @@ public final class TextFormat {
|
||||
/**
|
||||
* Like {@code print()}, but writes directly to a {@code String} and returns it.
|
||||
*
|
||||
* @deprecated Use {@link MessageOrBuilder#toString()}
|
||||
* @deprecated Use {@code message.toString()}
|
||||
*/
|
||||
@Deprecated
|
||||
public static String printToString(final MessageOrBuilder message) {
|
||||
@ -419,7 +421,17 @@ public final class TextFormat {
|
||||
private void printField(
|
||||
final FieldDescriptor field, final Object value, final TextGenerator generator)
|
||||
throws IOException {
|
||||
if (field.isRepeated()) {
|
||||
// Sort map field entries by key
|
||||
if (field.isMapField()) {
|
||||
List<MapEntryAdapter> adapters = new ArrayList<>();
|
||||
for (Object entry : (List<?>) value) {
|
||||
adapters.add(new MapEntryAdapter(entry, field));
|
||||
}
|
||||
Collections.sort(adapters);
|
||||
for (MapEntryAdapter adapter : adapters) {
|
||||
printSingleField(field, adapter.getEntry(), generator);
|
||||
}
|
||||
} else if (field.isRepeated()) {
|
||||
// Repeated field. Print each element.
|
||||
for (Object element : (List<?>) value) {
|
||||
printSingleField(field, element, generator);
|
||||
@ -429,6 +441,94 @@ public final class TextFormat {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An adapter class that can take a MapEntry or a MutableMapEntry and returns its key and entry.
|
||||
* This class is created solely for the purpose of sorting map entries by its key and prevent
|
||||
* duplicated logic by having a separate comparator for MapEntry and MutableMapEntry.
|
||||
*/
|
||||
private static class MapEntryAdapter implements Comparable<MapEntryAdapter> {
|
||||
private Object entry;
|
||||
|
||||
@SuppressWarnings({"rawtypes"})
|
||||
private MapEntry mapEntry;
|
||||
|
||||
|
||||
private final FieldDescriptor.JavaType fieldType;
|
||||
|
||||
public MapEntryAdapter(Object entry, FieldDescriptor fieldDescriptor) {
|
||||
if (entry instanceof MapEntry) {
|
||||
this.mapEntry = (MapEntry) entry;
|
||||
} else {
|
||||
this.entry = entry;
|
||||
}
|
||||
this.fieldType = extractFieldType(fieldDescriptor);
|
||||
}
|
||||
|
||||
private static FieldDescriptor.JavaType extractFieldType(FieldDescriptor fieldDescriptor) {
|
||||
return fieldDescriptor.getMessageType().getFields().get(0).getJavaType();
|
||||
}
|
||||
|
||||
public Object getKey() {
|
||||
if (mapEntry != null) {
|
||||
return mapEntry.getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getEntry() {
|
||||
if (mapEntry != null) {
|
||||
return mapEntry;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(MapEntryAdapter b) {
|
||||
if (getKey() == null || b.getKey() == null) {
|
||||
logger.info("Invalid key for map field.");
|
||||
return -1;
|
||||
}
|
||||
switch (fieldType) {
|
||||
case BOOLEAN:
|
||||
boolean aBoolean = (boolean) getKey();
|
||||
boolean bBoolean = (boolean) b.getKey();
|
||||
if (aBoolean == bBoolean) {
|
||||
return 0;
|
||||
} else if (aBoolean) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
case LONG:
|
||||
long aLong = (long) getKey();
|
||||
long bLong = (long) b.getKey();
|
||||
if (aLong < bLong) {
|
||||
return -1;
|
||||
} else if (aLong > bLong) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
case INT:
|
||||
return (int) getKey() - (int) b.getKey();
|
||||
case STRING:
|
||||
String aString = (String) getKey();
|
||||
String bString = (String) b.getKey();
|
||||
if (aString == null && bString == null) {
|
||||
return 0;
|
||||
} else if (aString == null && bString != null) {
|
||||
return -1;
|
||||
} else if (aString != null && bString == null) {
|
||||
return 1;
|
||||
} else {
|
||||
return aString.compareTo(bString);
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a textual representation of the value of given field value.
|
||||
*
|
||||
@ -1708,6 +1808,12 @@ public final class TextFormat {
|
||||
final Descriptor type = target.getDescriptorForType();
|
||||
ExtensionRegistry.ExtensionInfo extension = null;
|
||||
|
||||
if ("google.protobuf.Any".equals(type.getFullName()) && tokenizer.tryConsume("[")) {
|
||||
mergeAnyFieldValue(tokenizer, extensionRegistry, target, parseTreeBuilder, unknownFields,
|
||||
type);
|
||||
return;
|
||||
}
|
||||
|
||||
if (tokenizer.tryConsume("[")) {
|
||||
// An extension.
|
||||
final StringBuilder name = new StringBuilder(tokenizer.consumeIdentifier());
|
||||
@ -1928,9 +2034,13 @@ public final class TextFormat {
|
||||
// Try to parse human readable format of Any in the form: [type_url]: { ... }
|
||||
if (field.getMessageType().getFullName().equals("google.protobuf.Any")
|
||||
&& tokenizer.tryConsume("[")) {
|
||||
value =
|
||||
consumeAnyFieldValue(
|
||||
tokenizer, extensionRegistry, field, parseTreeBuilder, unknownFields);
|
||||
// Use Proto reflection here since depending on Any would intoduce a cyclic dependency
|
||||
// (java_proto_library for any_java_proto depends on the protobuf_impl).
|
||||
Message anyBuilder = DynamicMessage.getDefaultInstance(field.getMessageType());
|
||||
MessageReflection.MergeTarget anyField = target.newMergeTargetForField(field, anyBuilder);
|
||||
mergeAnyFieldValue(tokenizer, extensionRegistry, anyField, parseTreeBuilder,
|
||||
unknownFields, field.getMessageType());
|
||||
value = anyField.finish();
|
||||
tokenizer.consume(endToken);
|
||||
} else {
|
||||
Message defaultInstance = (extension == null) ? null : extension.defaultInstance;
|
||||
@ -2052,12 +2162,13 @@ public final class TextFormat {
|
||||
}
|
||||
}
|
||||
|
||||
private Object consumeAnyFieldValue(
|
||||
private void mergeAnyFieldValue(
|
||||
final Tokenizer tokenizer,
|
||||
final ExtensionRegistry extensionRegistry,
|
||||
final FieldDescriptor field,
|
||||
MergeTarget target,
|
||||
final TextFormatParseInfoTree.Builder parseTreeBuilder,
|
||||
List<UnknownField> unknownFields)
|
||||
List<UnknownField> unknownFields,
|
||||
Descriptor anyDescriptor)
|
||||
throws ParseException {
|
||||
// Try to parse human readable format of Any in the form: [type_url]: { ... }
|
||||
StringBuilder typeUrlBuilder = new StringBuilder();
|
||||
@ -2105,21 +2216,13 @@ public final class TextFormat {
|
||||
mergeField(tokenizer, extensionRegistry, contentTarget, parseTreeBuilder, unknownFields);
|
||||
}
|
||||
|
||||
// Serialize the content and put it back into an Any. Note that we can't depend on Any here
|
||||
// because of a cyclic dependency (java_proto_library for any_java_proto depends on the
|
||||
// protobuf_impl), so we need to construct the Any using proto reflection.
|
||||
Descriptor anyDescriptor = field.getMessageType();
|
||||
Message.Builder anyBuilder =
|
||||
DynamicMessage.getDefaultInstance(anyDescriptor).newBuilderForType();
|
||||
anyBuilder.setField(anyDescriptor.findFieldByName("type_url"), typeUrlBuilder.toString());
|
||||
anyBuilder.setField(
|
||||
target.setField(anyDescriptor.findFieldByName("type_url"), typeUrlBuilder.toString());
|
||||
target.setField(
|
||||
anyDescriptor.findFieldByName("value"), contentBuilder.build().toByteString());
|
||||
|
||||
return anyBuilder.build();
|
||||
}
|
||||
|
||||
/** Skips the next field including the field's name and value. */
|
||||
private void skipField(Tokenizer tokenizer) throws ParseException {
|
||||
private static void skipField(Tokenizer tokenizer) throws ParseException {
|
||||
if (tokenizer.tryConsume("[")) {
|
||||
// Extension name.
|
||||
do {
|
||||
@ -2151,7 +2254,7 @@ public final class TextFormat {
|
||||
/**
|
||||
* Skips the whole body of a message including the beginning delimiter and the ending delimiter.
|
||||
*/
|
||||
private void skipFieldMessage(Tokenizer tokenizer) throws ParseException {
|
||||
private static void skipFieldMessage(Tokenizer tokenizer) throws ParseException {
|
||||
final String delimiter;
|
||||
if (tokenizer.tryConsume("<")) {
|
||||
delimiter = ">";
|
||||
@ -2166,7 +2269,7 @@ public final class TextFormat {
|
||||
}
|
||||
|
||||
/** Skips a field value. */
|
||||
private void skipFieldValue(Tokenizer tokenizer) throws ParseException {
|
||||
private static void skipFieldValue(Tokenizer tokenizer) throws ParseException {
|
||||
if (tokenizer.tryConsumeString()) {
|
||||
while (tokenizer.tryConsumeString()) {}
|
||||
return;
|
||||
|
@ -301,7 +301,7 @@ public final class UnknownFieldSetLite {
|
||||
return size;
|
||||
}
|
||||
|
||||
private static boolean equals(int[] tags1, int[] tags2, int count) {
|
||||
private static boolean tagsEquals(int[] tags1, int[] tags2, int count) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
if (tags1[i] != tags2[i]) {
|
||||
return false;
|
||||
@ -310,7 +310,7 @@ public final class UnknownFieldSetLite {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean equals(Object[] objects1, Object[] objects2, int count) {
|
||||
private static boolean objectsEquals(Object[] objects1, Object[] objects2, int count) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
if (!objects1[i].equals(objects2[i])) {
|
||||
return false;
|
||||
@ -335,8 +335,8 @@ public final class UnknownFieldSetLite {
|
||||
|
||||
UnknownFieldSetLite other = (UnknownFieldSetLite) obj;
|
||||
if (count != other.count
|
||||
|| !equals(tags, other.tags, count)
|
||||
|| !equals(objects, other.objects, count)) {
|
||||
|| !tagsEquals(tags, other.tags, count)
|
||||
|| !objectsEquals(objects, other.objects, count)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -140,6 +140,68 @@ public class BooleanArrayListTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testIndexOf_nullElement() {
|
||||
assertEquals(-1, TERTIARY_LIST.indexOf(null));
|
||||
}
|
||||
|
||||
public void testIndexOf_incompatibleElementType() {
|
||||
assertEquals(-1, TERTIARY_LIST.indexOf(new Object()));
|
||||
}
|
||||
|
||||
public void testIndexOf_notInList() {
|
||||
assertEquals(-1, UNARY_LIST.indexOf(false));
|
||||
}
|
||||
|
||||
public void testIndexOf_notInListWithDuplicates() {
|
||||
BooleanArrayList listWithDupes = newImmutableBooleanArrayList(true, true);
|
||||
assertEquals(-1, listWithDupes.indexOf(false));
|
||||
}
|
||||
|
||||
public void testIndexOf_inList() {
|
||||
assertEquals(1, TERTIARY_LIST.indexOf(false));
|
||||
}
|
||||
|
||||
public void testIndexOf_inListWithDuplicates_matchAtHead() {
|
||||
BooleanArrayList listWithDupes = newImmutableBooleanArrayList(true, true, false);
|
||||
assertEquals(0, listWithDupes.indexOf(true));
|
||||
}
|
||||
|
||||
public void testIndexOf_inListWithDuplicates_matchMidList() {
|
||||
BooleanArrayList listWithDupes = newImmutableBooleanArrayList(false, true, true, false);
|
||||
assertEquals(1, listWithDupes.indexOf(true));
|
||||
}
|
||||
|
||||
public void testContains_nullElement() {
|
||||
assertEquals(false, TERTIARY_LIST.contains(null));
|
||||
}
|
||||
|
||||
public void testContains_incompatibleElementType() {
|
||||
assertEquals(false, TERTIARY_LIST.contains(new Object()));
|
||||
}
|
||||
|
||||
public void testContains_notInList() {
|
||||
assertEquals(false, UNARY_LIST.contains(false));
|
||||
}
|
||||
|
||||
public void testContains_notInListWithDuplicates() {
|
||||
BooleanArrayList listWithDupes = newImmutableBooleanArrayList(true, true);
|
||||
assertEquals(false, listWithDupes.contains(false));
|
||||
}
|
||||
|
||||
public void testContains_inList() {
|
||||
assertEquals(true, TERTIARY_LIST.contains(false));
|
||||
}
|
||||
|
||||
public void testContains_inListWithDuplicates_matchAtHead() {
|
||||
BooleanArrayList listWithDupes = newImmutableBooleanArrayList(true, true, false);
|
||||
assertEquals(true, listWithDupes.contains(true));
|
||||
}
|
||||
|
||||
public void testContains_inListWithDuplicates_matchMidList() {
|
||||
BooleanArrayList listWithDupes = newImmutableBooleanArrayList(false, true, true, false);
|
||||
assertEquals(true, listWithDupes.contains(true));
|
||||
}
|
||||
|
||||
public void testSize() {
|
||||
assertEquals(0, BooleanArrayList.emptyList().size());
|
||||
assertEquals(1, UNARY_LIST.size());
|
||||
|
@ -139,6 +139,68 @@ public class DoubleArrayListTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testIndexOf_nullElement() {
|
||||
assertEquals(-1, TERTIARY_LIST.indexOf(null));
|
||||
}
|
||||
|
||||
public void testIndexOf_incompatibleElementType() {
|
||||
assertEquals(-1, TERTIARY_LIST.indexOf(new Object()));
|
||||
}
|
||||
|
||||
public void testIndexOf_notInList() {
|
||||
assertEquals(-1, UNARY_LIST.indexOf(2D));
|
||||
}
|
||||
|
||||
public void testIndexOf_notInListWithDuplicates() {
|
||||
DoubleArrayList listWithDupes = newImmutableDoubleArrayList(1D, 1D);
|
||||
assertEquals(-1, listWithDupes.indexOf(2D));
|
||||
}
|
||||
|
||||
public void testIndexOf_inList() {
|
||||
assertEquals(1, TERTIARY_LIST.indexOf(2D));
|
||||
}
|
||||
|
||||
public void testIndexOf_inListWithDuplicates_matchAtHead() {
|
||||
DoubleArrayList listWithDupes = newImmutableDoubleArrayList(1D, 1D, 2D);
|
||||
assertEquals(0, listWithDupes.indexOf(1D));
|
||||
}
|
||||
|
||||
public void testIndexOf_inListWithDuplicates_matchMidList() {
|
||||
DoubleArrayList listWithDupes = newImmutableDoubleArrayList(2D, 1D, 1D, 2D);
|
||||
assertEquals(1, listWithDupes.indexOf(1D));
|
||||
}
|
||||
|
||||
public void testContains_nullElement() {
|
||||
assertEquals(false, TERTIARY_LIST.contains(null));
|
||||
}
|
||||
|
||||
public void testContains_incompatibleElementType() {
|
||||
assertEquals(false, TERTIARY_LIST.contains(new Object()));
|
||||
}
|
||||
|
||||
public void testContains_notInList() {
|
||||
assertEquals(false, UNARY_LIST.contains(2D));
|
||||
}
|
||||
|
||||
public void testContains_notInListWithDuplicates() {
|
||||
DoubleArrayList listWithDupes = newImmutableDoubleArrayList(1D, 1D);
|
||||
assertEquals(false, listWithDupes.contains(2D));
|
||||
}
|
||||
|
||||
public void testContains_inList() {
|
||||
assertEquals(true, TERTIARY_LIST.contains(2D));
|
||||
}
|
||||
|
||||
public void testContains_inListWithDuplicates_matchAtHead() {
|
||||
DoubleArrayList listWithDupes = newImmutableDoubleArrayList(1D, 1D, 2D);
|
||||
assertEquals(true, listWithDupes.contains(1D));
|
||||
}
|
||||
|
||||
public void testContains_inListWithDuplicates_matchMidList() {
|
||||
DoubleArrayList listWithDupes = newImmutableDoubleArrayList(2D, 1D, 1D, 2D);
|
||||
assertEquals(true, listWithDupes.contains(1D));
|
||||
}
|
||||
|
||||
public void testSize() {
|
||||
assertEquals(0, DoubleArrayList.emptyList().size());
|
||||
assertEquals(1, UNARY_LIST.size());
|
||||
|
@ -34,6 +34,7 @@ import com.google.protobuf.Descriptors.Descriptor;
|
||||
import com.google.protobuf.Descriptors.EnumDescriptor;
|
||||
import com.google.protobuf.Descriptors.EnumValueDescriptor;
|
||||
import com.google.protobuf.Descriptors.FieldDescriptor;
|
||||
import com.google.protobuf.Descriptors.OneofDescriptor;
|
||||
import com.google.protobuf.FieldPresenceTestProto.TestAllTypes;
|
||||
import com.google.protobuf.FieldPresenceTestProto.TestOptionalFieldsOnly;
|
||||
import com.google.protobuf.FieldPresenceTestProto.TestRepeatedFieldsOnly;
|
||||
@ -100,6 +101,7 @@ public class FieldPresenceTest extends TestCase {
|
||||
UnittestProto.TestAllTypes.Builder.class, TestAllTypes.Builder.class, "OneofBytes");
|
||||
}
|
||||
|
||||
|
||||
public void testOneofEquals() throws Exception {
|
||||
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
|
||||
TestAllTypes message1 = builder.build();
|
||||
|
@ -139,6 +139,68 @@ public class FloatArrayListTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testIndexOf_nullElement() {
|
||||
assertEquals(-1, TERTIARY_LIST.indexOf(null));
|
||||
}
|
||||
|
||||
public void testIndexOf_incompatibleElementType() {
|
||||
assertEquals(-1, TERTIARY_LIST.indexOf(new Object()));
|
||||
}
|
||||
|
||||
public void testIndexOf_notInList() {
|
||||
assertEquals(-1, UNARY_LIST.indexOf(2F));
|
||||
}
|
||||
|
||||
public void testIndexOf_notInListWithDuplicates() {
|
||||
FloatArrayList listWithDupes = newImmutableFloatArrayList(1F, 1F);
|
||||
assertEquals(-1, listWithDupes.indexOf(2F));
|
||||
}
|
||||
|
||||
public void testIndexOf_inList() {
|
||||
assertEquals(1, TERTIARY_LIST.indexOf(2F));
|
||||
}
|
||||
|
||||
public void testIndexOf_inListWithDuplicates_matchAtHead() {
|
||||
FloatArrayList listWithDupes = newImmutableFloatArrayList(1F, 1F, 2F);
|
||||
assertEquals(0, listWithDupes.indexOf(1F));
|
||||
}
|
||||
|
||||
public void testIndexOf_inListWithDuplicates_matchMidList() {
|
||||
FloatArrayList listWithDupes = newImmutableFloatArrayList(2F, 1F, 1F, 2F);
|
||||
assertEquals(1, listWithDupes.indexOf(1F));
|
||||
}
|
||||
|
||||
public void testContains_nullElement() {
|
||||
assertEquals(false, TERTIARY_LIST.contains(null));
|
||||
}
|
||||
|
||||
public void testContains_incompatibleElementType() {
|
||||
assertEquals(false, TERTIARY_LIST.contains(new Object()));
|
||||
}
|
||||
|
||||
public void testContains_notInList() {
|
||||
assertEquals(false, UNARY_LIST.contains(2F));
|
||||
}
|
||||
|
||||
public void testContains_notInListWithDuplicates() {
|
||||
FloatArrayList listWithDupes = newImmutableFloatArrayList(1F, 1F);
|
||||
assertEquals(false, listWithDupes.contains(2F));
|
||||
}
|
||||
|
||||
public void testContains_inList() {
|
||||
assertEquals(true, TERTIARY_LIST.contains(2F));
|
||||
}
|
||||
|
||||
public void testContains_inListWithDuplicates_matchAtHead() {
|
||||
FloatArrayList listWithDupes = newImmutableFloatArrayList(1F, 1F, 2F);
|
||||
assertEquals(true, listWithDupes.contains(1F));
|
||||
}
|
||||
|
||||
public void testContains_inListWithDuplicates_matchMidList() {
|
||||
FloatArrayList listWithDupes = newImmutableFloatArrayList(2F, 1F, 1F, 2F);
|
||||
assertEquals(true, listWithDupes.contains(1F));
|
||||
}
|
||||
|
||||
public void testSize() {
|
||||
assertEquals(0, FloatArrayList.emptyList().size());
|
||||
assertEquals(1, UNARY_LIST.size());
|
||||
|
@ -139,6 +139,68 @@ public class IntArrayListTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testIndexOf_nullElement() {
|
||||
assertEquals(-1, TERTIARY_LIST.indexOf(null));
|
||||
}
|
||||
|
||||
public void testIndexOf_incompatibleElementType() {
|
||||
assertEquals(-1, TERTIARY_LIST.indexOf(new Object()));
|
||||
}
|
||||
|
||||
public void testIndexOf_notInList() {
|
||||
assertEquals(-1, UNARY_LIST.indexOf(2));
|
||||
}
|
||||
|
||||
public void testIndexOf_notInListWithDuplicates() {
|
||||
IntArrayList listWithDupes = newImmutableIntArrayList(1, 1);
|
||||
assertEquals(-1, listWithDupes.indexOf(2));
|
||||
}
|
||||
|
||||
public void testIndexOf_inList() {
|
||||
assertEquals(1, TERTIARY_LIST.indexOf(2));
|
||||
}
|
||||
|
||||
public void testIndexOf_inListWithDuplicates_matchAtHead() {
|
||||
IntArrayList listWithDupes = newImmutableIntArrayList(1, 1, 2);
|
||||
assertEquals(0, listWithDupes.indexOf(1));
|
||||
}
|
||||
|
||||
public void testIndexOf_inListWithDuplicates_matchMidList() {
|
||||
IntArrayList listWithDupes = newImmutableIntArrayList(2, 1, 1, 2);
|
||||
assertEquals(1, listWithDupes.indexOf(1));
|
||||
}
|
||||
|
||||
public void testContains_nullElement() {
|
||||
assertEquals(false, TERTIARY_LIST.contains(null));
|
||||
}
|
||||
|
||||
public void testContains_incompatibleElementType() {
|
||||
assertEquals(false, TERTIARY_LIST.contains(new Object()));
|
||||
}
|
||||
|
||||
public void testContains_notInList() {
|
||||
assertEquals(false, UNARY_LIST.contains(2));
|
||||
}
|
||||
|
||||
public void testContains_notInListWithDuplicates() {
|
||||
IntArrayList listWithDupes = newImmutableIntArrayList(1, 1);
|
||||
assertEquals(false, listWithDupes.contains(2));
|
||||
}
|
||||
|
||||
public void testContains_inList() {
|
||||
assertEquals(true, TERTIARY_LIST.contains(2));
|
||||
}
|
||||
|
||||
public void testContains_inListWithDuplicates_matchAtHead() {
|
||||
IntArrayList listWithDupes = newImmutableIntArrayList(1, 1, 2);
|
||||
assertEquals(true, listWithDupes.contains(1));
|
||||
}
|
||||
|
||||
public void testContains_inListWithDuplicates_matchMidList() {
|
||||
IntArrayList listWithDupes = newImmutableIntArrayList(2, 1, 1, 2);
|
||||
assertEquals(true, listWithDupes.contains(1));
|
||||
}
|
||||
|
||||
public void testSize() {
|
||||
assertEquals(0, IntArrayList.emptyList().size());
|
||||
assertEquals(1, UNARY_LIST.size());
|
||||
|
@ -139,6 +139,68 @@ public class LongArrayListTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testIndexOf_nullElement() {
|
||||
assertEquals(-1, TERTIARY_LIST.indexOf(null));
|
||||
}
|
||||
|
||||
public void testIndexOf_incompatibleElementType() {
|
||||
assertEquals(-1, TERTIARY_LIST.indexOf(new Object()));
|
||||
}
|
||||
|
||||
public void testIndexOf_notInList() {
|
||||
assertEquals(-1, UNARY_LIST.indexOf(2L));
|
||||
}
|
||||
|
||||
public void testIndexOf_notInListWithDuplicates() {
|
||||
LongArrayList listWithDupes = newImmutableLongArrayList(1L, 1L);
|
||||
assertEquals(-1, listWithDupes.indexOf(2L));
|
||||
}
|
||||
|
||||
public void testIndexOf_inList() {
|
||||
assertEquals(1, TERTIARY_LIST.indexOf(2L));
|
||||
}
|
||||
|
||||
public void testIndexOf_inListWithDuplicates_matchAtHead() {
|
||||
LongArrayList listWithDupes = newImmutableLongArrayList(1L, 1L, 2L);
|
||||
assertEquals(0, listWithDupes.indexOf(1L));
|
||||
}
|
||||
|
||||
public void testIndexOf_inListWithDuplicates_matchMidList() {
|
||||
LongArrayList listWithDupes = newImmutableLongArrayList(2L, 1L, 1L, 2L);
|
||||
assertEquals(1, listWithDupes.indexOf(1L));
|
||||
}
|
||||
|
||||
public void testContains_nullElement() {
|
||||
assertEquals(false, TERTIARY_LIST.contains(null));
|
||||
}
|
||||
|
||||
public void testContains_incompatibleElementType() {
|
||||
assertEquals(false, TERTIARY_LIST.contains(new Object()));
|
||||
}
|
||||
|
||||
public void testContains_notInList() {
|
||||
assertEquals(false, UNARY_LIST.contains(2L));
|
||||
}
|
||||
|
||||
public void testContains_notInListWithDuplicates() {
|
||||
LongArrayList listWithDupes = newImmutableLongArrayList(1L, 1L);
|
||||
assertEquals(false, listWithDupes.contains(2L));
|
||||
}
|
||||
|
||||
public void testContains_inList() {
|
||||
assertEquals(true, TERTIARY_LIST.contains(2L));
|
||||
}
|
||||
|
||||
public void testContains_inListWithDuplicates_matchAtHead() {
|
||||
LongArrayList listWithDupes = newImmutableLongArrayList(1L, 1L, 2L);
|
||||
assertEquals(true, listWithDupes.contains(1L));
|
||||
}
|
||||
|
||||
public void testContains_inListWithDuplicates_matchMidList() {
|
||||
LongArrayList listWithDupes = newImmutableLongArrayList(2L, 1L, 1L, 2L);
|
||||
assertEquals(true, listWithDupes.contains(1L));
|
||||
}
|
||||
|
||||
public void testSize() {
|
||||
assertEquals(0, LongArrayList.emptyList().size());
|
||||
assertEquals(1, UNARY_LIST.size());
|
||||
|
@ -1536,4 +1536,42 @@ public class TextFormatTest extends TestCase {
|
||||
index, line, column));
|
||||
}
|
||||
}
|
||||
|
||||
public void testSortMapFields() throws Exception {
|
||||
TestMap message =
|
||||
TestMap.newBuilder()
|
||||
.putStringToInt32Field("cherry", 30)
|
||||
.putStringToInt32Field("banana", 20)
|
||||
.putStringToInt32Field("apple", 10)
|
||||
.putInt32ToStringField(30, "cherry")
|
||||
.putInt32ToStringField(20, "banana")
|
||||
.putInt32ToStringField(10, "apple")
|
||||
.build();
|
||||
String text =
|
||||
"int32_to_string_field {\n"
|
||||
+ " key: 10\n"
|
||||
+ " value: \"apple\"\n"
|
||||
+ "}\n"
|
||||
+ "int32_to_string_field {\n"
|
||||
+ " key: 20\n"
|
||||
+ " value: \"banana\"\n"
|
||||
+ "}\n"
|
||||
+ "int32_to_string_field {\n"
|
||||
+ " key: 30\n"
|
||||
+ " value: \"cherry\"\n"
|
||||
+ "}\n"
|
||||
+ "string_to_int32_field {\n"
|
||||
+ " key: \"apple\"\n"
|
||||
+ " value: 10\n"
|
||||
+ "}\n"
|
||||
+ "string_to_int32_field {\n"
|
||||
+ " key: \"banana\"\n"
|
||||
+ " value: 20\n"
|
||||
+ "}\n"
|
||||
+ "string_to_int32_field {\n"
|
||||
+ " key: \"cherry\"\n"
|
||||
+ " value: 30\n"
|
||||
+ "}\n";
|
||||
assertEquals(text, TextFormat.printer().printToString(message));
|
||||
}
|
||||
}
|
||||
|
@ -177,16 +177,20 @@ public final class Proto2MessageLiteInfoFactory implements MessageInfoFactory {
|
||||
// To update this after a proto change, run protoc on proto2_message_lite.proto and copy over
|
||||
// the content of the generated buildMessageInfo() method here.
|
||||
java.lang.String info =
|
||||
"\u0001U\u0001\u0002\u0001XU\u0000 \u0015\u0001\u0000\u0000\u0002\u0001\u0001\u0003"
|
||||
+ "\u0002\u0002\u0004\u0003\u0003\u0005\u0004\u0004\u0006\u0005\u0005\u0007\u0006\u0006"
|
||||
+ "\b\u0007\u0007\t\b\b\n\u0409\t\u000b\n\n\f\u000b\u000b\r\f\f\u000e\r\r\u000f\u000e"
|
||||
+ "\u000e\u0010\u000f\u000f\u0011\u0010\u0010\u0012\u0012\u0013\u0013\u0014\u0014\u0015"
|
||||
+ "\u0015\u0016\u0016\u0017\u0017\u0018\u0018\u0019\u0019\u001a\u001a\u001b\u041b\u001c"
|
||||
+ "\u001c\u001d\u001d\u001e\u001e\u001f\u001f !!\"\"##$$%%&&\'\'(())**++,,--..//00"
|
||||
+ "1\u0011\u00113153\u000064\u000075\u000086\u000097\u0000:8\u0000;9\u0000<:\u0000="
|
||||
+ ";\u0000>\u043c\u0000?=\u0000@>\u0000A@\u0000BA\u0000CB\u0000DC\u0000ED\u0000G\u0500"
|
||||
+ "#H\u0501$I\u0502%J\u0503&K\u0504\'L\u0505(M\u0506)N\u0507*O\u0508+P\u0509,Q\u050a"
|
||||
+ "-R\u050b.S\u050c/T\u050d0U\u050e1V\u050f2W\u05103X\u05114";
|
||||
"\u0001U\u0001\u0002\u0001XU\u0000 \u0015\u0001\u1000\u0000\u0002\u1001\u0001\u0003"
|
||||
+ "\u1002\u0002\u0004\u1003\u0003\u0005\u1004\u0004\u0006\u1005\u0005\u0007\u1006\u0006\b\u1007\u0007"
|
||||
+ "\t\u1008\b\n"
|
||||
+ "\u1409\t\u000b\u100a\n"
|
||||
+ "\f\u100b\u000b\r"
|
||||
+ "\u100c\f\u000e\u100d\r"
|
||||
+ "\u000f\u100e\u000e\u0010\u100f\u000f\u0011\u1010\u0010\u0012\u0012\u0013\u0013"
|
||||
+ "\u0014\u0014\u0015\u0015\u0016\u0016\u0017\u0017\u0018\u0018\u0019\u0019\u001a\u001a\u001b\u041b\u001c\u001c\u001d\u001d\u001e\u001e\u001f\u001f"
|
||||
+ " !!\"\"##$$%%&&\'\'"
|
||||
+ "(())**++,,--..//001\u1011\u0011315\u1033\u00006\u1034\u00007\u1035\u00008\u1036\u0000"
|
||||
+ "9\u1037\u0000:\u1038\u0000;\u1039\u0000<\u103a\u0000=\u103b\u0000>\u143c\u0000?\u103d"
|
||||
+ "\u0000@\u103e\u0000A\u1040\u0000B\u1041\u0000C\u1042\u0000D\u1043\u0000E\u1044\u0000"
|
||||
+ "G\u1500#H\u1501$I\u1502%J\u1503&K\u1504\'L\u1505(M\u1506)N\u1507*O\u1508+P\u1509"
|
||||
+ ",Q\u150a-R\u150b.S\u150c/T\u150d0U\u150e1V\u150f2W\u15103X\u15114";
|
||||
return new RawMessageInfo(Proto2MessageLite.getDefaultInstance(), info, objects);
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||
@ -49,7 +50,7 @@ import java.util.List;
|
||||
/**
|
||||
* Utility helper functions to work with {@link com.google.protobuf.FieldMask}.
|
||||
*/
|
||||
public class FieldMaskUtil {
|
||||
public final class FieldMaskUtil {
|
||||
private static final String FIELD_PATH_SEPARATOR = ",";
|
||||
private static final String FIELD_PATH_SEPARATOR_REGEX = ",";
|
||||
private static final String FIELD_SEPARATOR_REGEX = "\\.";
|
||||
@ -83,7 +84,7 @@ public class FieldMaskUtil {
|
||||
*/
|
||||
public static FieldMask fromString(String value) {
|
||||
// TODO(xiaofeng): Consider using com.google.common.base.Splitter here instead.
|
||||
return fromStringList(null, Arrays.asList(value.split(FIELD_PATH_SEPARATOR_REGEX)));
|
||||
return fromStringList(Arrays.asList(value.split(FIELD_PATH_SEPARATOR_REGEX)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,14 +104,36 @@ public class FieldMaskUtil {
|
||||
*/
|
||||
// TODO(xiaofeng): Consider renaming fromStrings()
|
||||
public static FieldMask fromStringList(Class<? extends Message> type, Iterable<String> paths) {
|
||||
return fromStringList(Internal.getDefaultInstance(type).getDescriptorForType(), paths);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a FieldMask for a list of field paths in a certain type.
|
||||
*
|
||||
* @throws IllegalArgumentException if any of the field path is not valid.
|
||||
*/
|
||||
public static FieldMask fromStringList(Descriptor descriptor, Iterable<String> paths) {
|
||||
return fromStringList(Optional.of(descriptor), paths);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a FieldMask for a list of field paths in a certain type. Does not validate the given
|
||||
* paths.
|
||||
*/
|
||||
public static FieldMask fromStringList(Iterable<String> paths) {
|
||||
return fromStringList(Optional.<Descriptor>absent(), paths);
|
||||
}
|
||||
|
||||
private static FieldMask fromStringList(Optional<Descriptor> descriptor, Iterable<String> paths) {
|
||||
FieldMask.Builder builder = FieldMask.newBuilder();
|
||||
for (String path : paths) {
|
||||
if (path.isEmpty()) {
|
||||
// Ignore empty field paths.
|
||||
continue;
|
||||
}
|
||||
if (type != null && !isValid(type, path)) {
|
||||
throw new IllegalArgumentException(path + " is not a valid path for " + type);
|
||||
if (descriptor.isPresent() && !isValid(descriptor.get(), path)) {
|
||||
throw new IllegalArgumentException(
|
||||
path + " is not a valid path for " + descriptor.get().getFullName());
|
||||
}
|
||||
builder.addPaths(path);
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ public class JsonFormat {
|
||||
registry,
|
||||
oldRegistry,
|
||||
alwaysOutputDefaultValueFields,
|
||||
Collections.<FieldDescriptor>emptySet(),
|
||||
includingDefaultValueFields,
|
||||
preservingProtoFieldNames,
|
||||
omittingInsignificantWhitespace,
|
||||
true,
|
||||
|
@ -71,8 +71,8 @@ public final class Values {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Value with ListValue set to the appending the result of calling {@link #of(Object)}
|
||||
* on each element in the iterable.
|
||||
* Returns a Value with ListValue set to the appending the result of calling {@link #of} on each
|
||||
* element in the iterable.
|
||||
*/
|
||||
public static Value of(Iterable<Value> values) {
|
||||
Value.Builder valueBuilder = Value.newBuilder();
|
||||
|
@ -30,10 +30,12 @@
|
||||
|
||||
package com.google.protobuf.util;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.protobuf.FieldMask;
|
||||
import protobuf_unittest.UnittestProto.NestedTestAllTypes;
|
||||
import protobuf_unittest.UnittestProto.TestAllTypes;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/** Unit tests for {@link FieldMaskUtil}. */
|
||||
@ -172,6 +174,38 @@ public class FieldMaskUtilTest extends TestCase {
|
||||
assertEquals("bar_baz", mask.getPaths(1));
|
||||
}
|
||||
|
||||
public void testFromStringList() throws Exception {
|
||||
FieldMask mask =
|
||||
FieldMaskUtil.fromStringList(
|
||||
NestedTestAllTypes.class, ImmutableList.of("payload.repeated_nested_message", "child"));
|
||||
assertThat(mask)
|
||||
.isEqualTo(
|
||||
FieldMask.newBuilder()
|
||||
.addPaths("payload.repeated_nested_message")
|
||||
.addPaths("child")
|
||||
.build());
|
||||
|
||||
mask =
|
||||
FieldMaskUtil.fromStringList(
|
||||
NestedTestAllTypes.getDescriptor(),
|
||||
ImmutableList.of("payload.repeated_nested_message", "child"));
|
||||
assertThat(mask)
|
||||
.isEqualTo(
|
||||
FieldMask.newBuilder()
|
||||
.addPaths("payload.repeated_nested_message")
|
||||
.addPaths("child")
|
||||
.build());
|
||||
|
||||
mask =
|
||||
FieldMaskUtil.fromStringList(ImmutableList.of("payload.repeated_nested_message", "child"));
|
||||
assertThat(mask)
|
||||
.isEqualTo(
|
||||
FieldMask.newBuilder()
|
||||
.addPaths("payload.repeated_nested_message")
|
||||
.addPaths("child")
|
||||
.build());
|
||||
}
|
||||
|
||||
public void testUnion() throws Exception {
|
||||
// Only test a simple case here and expect
|
||||
// {@link FieldMaskTreeTest#testAddFieldPath} to cover all scenarios.
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
package com.google.protobuf.util;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.protobuf.Any;
|
||||
import com.google.protobuf.BoolValue;
|
||||
import com.google.protobuf.ByteString;
|
||||
@ -1784,4 +1785,16 @@ public class JsonFormatTest extends TestCase {
|
||||
TestMap emptyMap = TestMap.getDefaultInstance();
|
||||
assertEquals("{\n}", toSortedJsonString(emptyMap));
|
||||
}
|
||||
|
||||
public void testPrintingEnumsAsIntsChainedAfterIncludingDefaultValueFields() throws Exception {
|
||||
TestAllTypes message = TestAllTypes.newBuilder().setOptionalBool(false).build();
|
||||
|
||||
assertEquals(
|
||||
"{\n" + " \"optionalBool\": false\n" + "}",
|
||||
JsonFormat.printer()
|
||||
.includingDefaultValueFields(
|
||||
ImmutableSet.of(message.getDescriptorForType().findFieldByName("optional_bool")))
|
||||
.printingEnumsAsInts()
|
||||
.print(message));
|
||||
}
|
||||
}
|
||||
|
@ -1080,7 +1080,7 @@ describe('Message test suite', function() {
|
||||
|
||||
it('testMessageWithLargeFieldNumbers', function() {
|
||||
var message = new proto.jspb.test.MessageWithLargeFieldNumbers;
|
||||
|
||||
|
||||
message.setAString('string');
|
||||
assertEquals('string', message.getAString());
|
||||
|
||||
|
@ -35,6 +35,7 @@ file, in types that make this information accessible in Python.
|
||||
__author__ = 'robinson@google.com (Will Robinson)'
|
||||
|
||||
import threading
|
||||
import warnings
|
||||
import six
|
||||
|
||||
from google.protobuf.internal import api_implementation
|
||||
@ -91,6 +92,25 @@ class _Lock(object):
|
||||
_lock = threading.Lock()
|
||||
|
||||
|
||||
def _Deprecated(name):
|
||||
if _Deprecated.count > 0:
|
||||
_Deprecated.count -= 1
|
||||
warnings.warn(
|
||||
'Call to deprecated create function %s(). Note: Create unlinked '
|
||||
'descriptors is going to go away. Please use get/find descriptors from '
|
||||
'generated code or query the descriptor_pool.'
|
||||
% name,
|
||||
category=DeprecationWarning, stacklevel=3)
|
||||
|
||||
|
||||
# Deprecated warnings will print 100 times at most which should be enough for
|
||||
# users to notice and do not cause timeout.
|
||||
_Deprecated.count = 100
|
||||
|
||||
|
||||
_internal_create_key = object()
|
||||
|
||||
|
||||
class DescriptorBase(six.with_metaclass(DescriptorMetaclass)):
|
||||
|
||||
"""Descriptors base class.
|
||||
@ -271,7 +291,7 @@ class Descriptor(_NestedDescriptorBase):
|
||||
serialized_options=None,
|
||||
is_extendable=True, extension_ranges=None, oneofs=None,
|
||||
file=None, serialized_start=None, serialized_end=None, # pylint: disable=redefined-builtin
|
||||
syntax=None):
|
||||
syntax=None, create_key=None):
|
||||
_message.Message._CheckCalledFromGeneratedFile()
|
||||
return _message.default_pool.FindMessageTypeByName(full_name)
|
||||
|
||||
@ -283,13 +303,16 @@ class Descriptor(_NestedDescriptorBase):
|
||||
serialized_options=None,
|
||||
is_extendable=True, extension_ranges=None, oneofs=None,
|
||||
file=None, serialized_start=None, serialized_end=None, # pylint: disable=redefined-builtin
|
||||
syntax=None):
|
||||
syntax=None, create_key=None):
|
||||
"""Arguments to __init__() are as described in the description
|
||||
of Descriptor fields above.
|
||||
|
||||
Note that filename is an obsolete argument, that is not used anymore.
|
||||
Please use file.name to access this as an attribute.
|
||||
"""
|
||||
if create_key is not _internal_create_key:
|
||||
_Deprecated('Descriptor')
|
||||
|
||||
super(Descriptor, self).__init__(
|
||||
options, 'MessageOptions', name, full_name, file,
|
||||
containing_type, serialized_start=serialized_start,
|
||||
@ -515,7 +538,7 @@ class FieldDescriptor(DescriptorBase):
|
||||
is_extension, extension_scope, options=None,
|
||||
serialized_options=None,
|
||||
has_default_value=True, containing_oneof=None, json_name=None,
|
||||
file=None): # pylint: disable=redefined-builtin
|
||||
file=None, create_key=None): # pylint: disable=redefined-builtin
|
||||
_message.Message._CheckCalledFromGeneratedFile()
|
||||
if is_extension:
|
||||
return _message.default_pool.FindExtensionByName(full_name)
|
||||
@ -527,7 +550,7 @@ class FieldDescriptor(DescriptorBase):
|
||||
is_extension, extension_scope, options=None,
|
||||
serialized_options=None,
|
||||
has_default_value=True, containing_oneof=None, json_name=None,
|
||||
file=None): # pylint: disable=redefined-builtin
|
||||
file=None, create_key=None): # pylint: disable=redefined-builtin
|
||||
"""The arguments are as described in the description of FieldDescriptor
|
||||
attributes above.
|
||||
|
||||
@ -535,6 +558,9 @@ class FieldDescriptor(DescriptorBase):
|
||||
(to deal with circular references between message types, for example).
|
||||
Likewise for extension_scope.
|
||||
"""
|
||||
if create_key is not _internal_create_key:
|
||||
_Deprecated('FieldDescriptor')
|
||||
|
||||
super(FieldDescriptor, self).__init__(
|
||||
options, serialized_options, 'FieldOptions')
|
||||
self.name = name
|
||||
@ -628,19 +654,22 @@ class EnumDescriptor(_NestedDescriptorBase):
|
||||
def __new__(cls, name, full_name, filename, values,
|
||||
containing_type=None, options=None,
|
||||
serialized_options=None, file=None, # pylint: disable=redefined-builtin
|
||||
serialized_start=None, serialized_end=None):
|
||||
serialized_start=None, serialized_end=None, create_key=None):
|
||||
_message.Message._CheckCalledFromGeneratedFile()
|
||||
return _message.default_pool.FindEnumTypeByName(full_name)
|
||||
|
||||
def __init__(self, name, full_name, filename, values,
|
||||
containing_type=None, options=None,
|
||||
serialized_options=None, file=None, # pylint: disable=redefined-builtin
|
||||
serialized_start=None, serialized_end=None):
|
||||
serialized_start=None, serialized_end=None, create_key=None):
|
||||
"""Arguments are as described in the attribute description above.
|
||||
|
||||
Note that filename is an obsolete argument, that is not used anymore.
|
||||
Please use file.name to access this as an attribute.
|
||||
"""
|
||||
if create_key is not _internal_create_key:
|
||||
_Deprecated('EnumDescriptor')
|
||||
|
||||
super(EnumDescriptor, self).__init__(
|
||||
options, 'EnumOptions', name, full_name, file,
|
||||
containing_type, serialized_start=serialized_start,
|
||||
@ -684,7 +713,7 @@ class EnumValueDescriptor(DescriptorBase):
|
||||
|
||||
def __new__(cls, name, index, number,
|
||||
type=None, # pylint: disable=redefined-builtin
|
||||
options=None, serialized_options=None):
|
||||
options=None, serialized_options=None, create_key=None):
|
||||
_message.Message._CheckCalledFromGeneratedFile()
|
||||
# There is no way we can build a complete EnumValueDescriptor with the
|
||||
# given parameters (the name of the Enum is not known, for example).
|
||||
@ -694,8 +723,11 @@ class EnumValueDescriptor(DescriptorBase):
|
||||
|
||||
def __init__(self, name, index, number,
|
||||
type=None, # pylint: disable=redefined-builtin
|
||||
options=None, serialized_options=None):
|
||||
options=None, serialized_options=None, create_key=None):
|
||||
"""Arguments are as described in the attribute description above."""
|
||||
if create_key is not _internal_create_key:
|
||||
_Deprecated('EnumValueDescriptor')
|
||||
|
||||
super(EnumValueDescriptor, self).__init__(
|
||||
options, serialized_options, 'EnumValueOptions')
|
||||
self.name = name
|
||||
@ -724,14 +756,17 @@ class OneofDescriptor(DescriptorBase):
|
||||
|
||||
def __new__(
|
||||
cls, name, full_name, index, containing_type, fields, options=None,
|
||||
serialized_options=None):
|
||||
serialized_options=None, create_key=None):
|
||||
_message.Message._CheckCalledFromGeneratedFile()
|
||||
return _message.default_pool.FindOneofByName(full_name)
|
||||
|
||||
def __init__(
|
||||
self, name, full_name, index, containing_type, fields, options=None,
|
||||
serialized_options=None):
|
||||
serialized_options=None, create_key=None):
|
||||
"""Arguments are as described in the attribute description above."""
|
||||
if create_key is not _internal_create_key:
|
||||
_Deprecated('OneofDescriptor')
|
||||
|
||||
super(OneofDescriptor, self).__init__(
|
||||
options, serialized_options, 'OneofOptions')
|
||||
self.name = name
|
||||
@ -765,13 +800,16 @@ class ServiceDescriptor(_NestedDescriptorBase):
|
||||
|
||||
def __new__(cls, name, full_name, index, methods, options=None,
|
||||
serialized_options=None, file=None, # pylint: disable=redefined-builtin
|
||||
serialized_start=None, serialized_end=None):
|
||||
serialized_start=None, serialized_end=None, create_key=None):
|
||||
_message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protected-access
|
||||
return _message.default_pool.FindServiceByName(full_name)
|
||||
|
||||
def __init__(self, name, full_name, index, methods, options=None,
|
||||
serialized_options=None, file=None, # pylint: disable=redefined-builtin
|
||||
serialized_start=None, serialized_end=None):
|
||||
serialized_start=None, serialized_end=None, create_key=None):
|
||||
if create_key is not _internal_create_key:
|
||||
_Deprecated('ServiceDescriptor')
|
||||
|
||||
super(ServiceDescriptor, self).__init__(
|
||||
options, 'ServiceOptions', name, full_name, file,
|
||||
None, serialized_start=serialized_start,
|
||||
@ -826,17 +864,22 @@ class MethodDescriptor(DescriptorBase):
|
||||
_C_DESCRIPTOR_CLASS = _message.MethodDescriptor
|
||||
|
||||
def __new__(cls, name, full_name, index, containing_service,
|
||||
input_type, output_type, options=None, serialized_options=None):
|
||||
input_type, output_type, options=None, serialized_options=None,
|
||||
create_key=None):
|
||||
_message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protected-access
|
||||
return _message.default_pool.FindMethodByName(full_name)
|
||||
|
||||
def __init__(self, name, full_name, index, containing_service,
|
||||
input_type, output_type, options=None, serialized_options=None):
|
||||
input_type, output_type, options=None, serialized_options=None,
|
||||
create_key=None):
|
||||
"""The arguments are as described in the description of MethodDescriptor
|
||||
attributes above.
|
||||
|
||||
Note that containing_service may be None, and may be set later if necessary.
|
||||
"""
|
||||
if create_key is not _internal_create_key:
|
||||
_Deprecated('MethodDescriptor')
|
||||
|
||||
super(MethodDescriptor, self).__init__(
|
||||
options, serialized_options, 'MethodOptions')
|
||||
self.name = name
|
||||
@ -884,11 +927,11 @@ class FileDescriptor(DescriptorBase):
|
||||
def __new__(cls, name, package, options=None,
|
||||
serialized_options=None, serialized_pb=None,
|
||||
dependencies=None, public_dependencies=None,
|
||||
syntax=None, pool=None):
|
||||
syntax=None, pool=None, create_key=None):
|
||||
# FileDescriptor() is called from various places, not only from generated
|
||||
# files, to register dynamic proto files and messages.
|
||||
# pylint: disable=g-explicit-bool-comparison
|
||||
if serialized_pb == '':
|
||||
if serialized_pb == b'':
|
||||
# Cpp generated code must be linked in if serialized_pb is ''
|
||||
try:
|
||||
return _message.default_pool.FindFileByName(name)
|
||||
@ -902,8 +945,11 @@ class FileDescriptor(DescriptorBase):
|
||||
def __init__(self, name, package, options=None,
|
||||
serialized_options=None, serialized_pb=None,
|
||||
dependencies=None, public_dependencies=None,
|
||||
syntax=None, pool=None):
|
||||
syntax=None, pool=None, create_key=None):
|
||||
"""Constructor."""
|
||||
if create_key is not _internal_create_key:
|
||||
_Deprecated('FileDescriptor')
|
||||
|
||||
super(FileDescriptor, self).__init__(
|
||||
options, serialized_options, 'FileOptions')
|
||||
|
||||
@ -1042,9 +1088,11 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True,
|
||||
for enum_proto in desc_proto.enum_type:
|
||||
full_name = '.'.join(full_message_name + [enum_proto.name])
|
||||
enum_desc = EnumDescriptor(
|
||||
enum_proto.name, full_name, None, [
|
||||
EnumValueDescriptor(enum_val.name, ii, enum_val.number)
|
||||
for ii, enum_val in enumerate(enum_proto.value)])
|
||||
enum_proto.name, full_name, None, [
|
||||
EnumValueDescriptor(enum_val.name, ii, enum_val.number,
|
||||
create_key=_internal_create_key)
|
||||
for ii, enum_val in enumerate(enum_proto.value)],
|
||||
create_key=_internal_create_key)
|
||||
enum_types[full_name] = enum_desc
|
||||
|
||||
# Create Descriptors for nested types
|
||||
@ -1083,10 +1131,11 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True,
|
||||
FieldDescriptor.ProtoTypeToCppProtoType(field_proto.type),
|
||||
field_proto.label, None, nested_desc, enum_desc, None, False, None,
|
||||
options=_OptionsOrNone(field_proto), has_default_value=False,
|
||||
json_name=json_name)
|
||||
json_name=json_name, create_key=_internal_create_key)
|
||||
fields.append(field)
|
||||
|
||||
desc_name = '.'.join(full_message_name)
|
||||
return Descriptor(desc_proto.name, desc_name, None, None, fields,
|
||||
list(nested_types.values()), list(enum_types.values()), [],
|
||||
options=_OptionsOrNone(desc_proto))
|
||||
options=_OptionsOrNone(desc_proto),
|
||||
create_key=_internal_create_key)
|
||||
|
@ -619,7 +619,7 @@ class DescriptorPool(object):
|
||||
def FindAllExtensions(self, message_descriptor):
|
||||
"""Gets all the known extensions of a given message.
|
||||
|
||||
Extensions have to be registered to this pool by calling
|
||||
Extensions have to be registered to this pool by build related
|
||||
:func:`Add` or :func:`AddExtensionDescriptor`.
|
||||
|
||||
Args:
|
||||
@ -662,18 +662,7 @@ class DescriptorPool(object):
|
||||
return
|
||||
|
||||
try:
|
||||
file_desc = self._ConvertFileProtoToFileDescriptor(file_proto)
|
||||
for extension in file_desc.extensions_by_name.values():
|
||||
self._extensions_by_number[extension.containing_type][
|
||||
extension.number] = extension
|
||||
self._extensions_by_name[extension.containing_type][
|
||||
extension.full_name] = extension
|
||||
for message_type in file_desc.message_types_by_name.values():
|
||||
for extension in message_type.extensions:
|
||||
self._extensions_by_number[extension.containing_type][
|
||||
extension.number] = extension
|
||||
self._extensions_by_name[extension.containing_type][
|
||||
extension.full_name] = extension
|
||||
self._ConvertFileProtoToFileDescriptor(file_proto)
|
||||
except:
|
||||
warn_msg = ('Unable to load proto file %s for extension number %d.' %
|
||||
(file_proto.name, number))
|
||||
@ -761,7 +750,9 @@ class DescriptorPool(object):
|
||||
options=_OptionsOrNone(file_proto),
|
||||
serialized_pb=file_proto.SerializeToString(),
|
||||
dependencies=direct_deps,
|
||||
public_dependencies=public_deps)
|
||||
public_dependencies=public_deps,
|
||||
# pylint: disable=protected-access
|
||||
create_key=descriptor._internal_create_key)
|
||||
scope = {}
|
||||
|
||||
# This loop extracts all the message and enum types from all the
|
||||
@ -820,7 +811,15 @@ class DescriptorPool(object):
|
||||
self.Add(file_proto)
|
||||
self._file_descriptors[file_proto.name] = file_descriptor
|
||||
|
||||
return self._file_descriptors[file_proto.name]
|
||||
# Add extensions to the pool
|
||||
file_desc = self._file_descriptors[file_proto.name]
|
||||
for extension in file_desc.extensions_by_name.values():
|
||||
self._AddExtensionDescriptor(extension)
|
||||
for message_type in file_desc.message_types_by_name.values():
|
||||
for extension in message_type.extensions:
|
||||
self._AddExtensionDescriptor(extension)
|
||||
|
||||
return file_desc
|
||||
|
||||
def _ConvertMessageDescriptor(self, desc_proto, package=None, file_desc=None,
|
||||
scope=None, syntax=None):
|
||||
@ -865,8 +864,11 @@ class DescriptorPool(object):
|
||||
is_extension=True)
|
||||
for index, extension in enumerate(desc_proto.extension)]
|
||||
oneofs = [
|
||||
# pylint: disable=g-complex-comprehension
|
||||
descriptor.OneofDescriptor(desc.name, '.'.join((desc_name, desc.name)),
|
||||
index, None, [], desc.options)
|
||||
index, None, [], desc.options,
|
||||
# pylint: disable=protected-access
|
||||
create_key=descriptor._internal_create_key)
|
||||
for index, desc in enumerate(desc_proto.oneof_decl)]
|
||||
extension_ranges = [(r.start, r.end) for r in desc_proto.extension_range]
|
||||
if extension_ranges:
|
||||
@ -889,7 +891,9 @@ class DescriptorPool(object):
|
||||
file=file_desc,
|
||||
serialized_start=None,
|
||||
serialized_end=None,
|
||||
syntax=syntax)
|
||||
syntax=syntax,
|
||||
# pylint: disable=protected-access
|
||||
create_key=descriptor._internal_create_key)
|
||||
for nested in desc.nested_types:
|
||||
nested.containing_type = desc
|
||||
for enum in desc.enum_types:
|
||||
@ -940,7 +944,9 @@ class DescriptorPool(object):
|
||||
file=file_desc,
|
||||
values=values,
|
||||
containing_type=containing_type,
|
||||
options=_OptionsOrNone(enum_proto))
|
||||
options=_OptionsOrNone(enum_proto),
|
||||
# pylint: disable=protected-access
|
||||
create_key=descriptor._internal_create_key)
|
||||
scope['.%s' % enum_name] = desc
|
||||
self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
|
||||
self._enum_descriptors[enum_name] = desc
|
||||
@ -997,7 +1003,9 @@ class DescriptorPool(object):
|
||||
is_extension=is_extension,
|
||||
extension_scope=None,
|
||||
options=_OptionsOrNone(field_proto),
|
||||
file=file_desc)
|
||||
file=file_desc,
|
||||
# pylint: disable=protected-access
|
||||
create_key=descriptor._internal_create_key)
|
||||
|
||||
def _SetAllFieldTypes(self, package, desc_proto, scope):
|
||||
"""Sets all the descriptor's fields's types.
|
||||
@ -1121,7 +1129,9 @@ class DescriptorPool(object):
|
||||
index=index,
|
||||
number=value_proto.number,
|
||||
options=_OptionsOrNone(value_proto),
|
||||
type=None)
|
||||
type=None,
|
||||
# pylint: disable=protected-access
|
||||
create_key=descriptor._internal_create_key)
|
||||
|
||||
def _MakeServiceDescriptor(self, service_proto, service_index, scope,
|
||||
package, file_desc):
|
||||
@ -1146,12 +1156,15 @@ class DescriptorPool(object):
|
||||
methods = [self._MakeMethodDescriptor(method_proto, service_name, package,
|
||||
scope, index)
|
||||
for index, method_proto in enumerate(service_proto.method)]
|
||||
desc = descriptor.ServiceDescriptor(name=service_proto.name,
|
||||
full_name=service_name,
|
||||
index=service_index,
|
||||
methods=methods,
|
||||
options=_OptionsOrNone(service_proto),
|
||||
file=file_desc)
|
||||
desc = descriptor.ServiceDescriptor(
|
||||
name=service_proto.name,
|
||||
full_name=service_name,
|
||||
index=service_index,
|
||||
methods=methods,
|
||||
options=_OptionsOrNone(service_proto),
|
||||
file=file_desc,
|
||||
# pylint: disable=protected-access
|
||||
create_key=descriptor._internal_create_key)
|
||||
self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
|
||||
self._service_descriptors[service_name] = desc
|
||||
return desc
|
||||
@ -1175,13 +1188,16 @@ class DescriptorPool(object):
|
||||
package, method_proto.input_type, scope)
|
||||
output_type = self._GetTypeFromScope(
|
||||
package, method_proto.output_type, scope)
|
||||
return descriptor.MethodDescriptor(name=method_proto.name,
|
||||
full_name=full_name,
|
||||
index=index,
|
||||
containing_service=None,
|
||||
input_type=input_type,
|
||||
output_type=output_type,
|
||||
options=_OptionsOrNone(method_proto))
|
||||
return descriptor.MethodDescriptor(
|
||||
name=method_proto.name,
|
||||
full_name=full_name,
|
||||
index=index,
|
||||
containing_service=None,
|
||||
input_type=input_type,
|
||||
output_type=output_type,
|
||||
options=_OptionsOrNone(method_proto),
|
||||
# pylint: disable=protected-access
|
||||
create_key=descriptor._internal_create_key)
|
||||
|
||||
def _ExtractSymbols(self, descriptors):
|
||||
"""Pulls out all the symbols from descriptor protos.
|
||||
|
@ -816,8 +816,12 @@ def MessageSetItemDecoder(descriptor):
|
||||
if extension is not None:
|
||||
value = field_dict.get(extension)
|
||||
if value is None:
|
||||
message_type = extension.message_type
|
||||
if not hasattr(message_type, '_concrete_class'):
|
||||
# pylint: disable=protected-access
|
||||
message._FACTORY.GetPrototype(message_type)
|
||||
value = field_dict.setdefault(
|
||||
extension, extension.message_type._concrete_class())
|
||||
extension, message_type._concrete_class())
|
||||
if value._InternalParse(buffer, message_start,message_end) != message_end:
|
||||
# The only reason _InternalParse would return early is if it encountered
|
||||
# an end-group tag.
|
||||
|
@ -36,6 +36,7 @@ __author__ = 'matthewtoia@google.com (Matt Toia)'
|
||||
|
||||
import copy
|
||||
import os
|
||||
import warnings
|
||||
|
||||
try:
|
||||
import unittest2 as unittest #PY26
|
||||
@ -63,6 +64,9 @@ from google.protobuf import symbol_database
|
||||
|
||||
|
||||
|
||||
warnings.simplefilter('error', DeprecationWarning)
|
||||
|
||||
|
||||
class DescriptorPoolTestBase(object):
|
||||
|
||||
def testFindFileByName(self):
|
||||
@ -336,12 +340,10 @@ class DescriptorPoolTestBase(object):
|
||||
'google.protobuf.python.internal.Factory2Message')
|
||||
# An extension defined in a message.
|
||||
one_more_field = factory2_message.extensions_by_name['one_more_field']
|
||||
self.pool.AddExtensionDescriptor(one_more_field)
|
||||
# An extension defined at file scope.
|
||||
factory_test2 = self.pool.FindFileByName(
|
||||
'google/protobuf/internal/factory_test2.proto')
|
||||
another_field = factory_test2.extensions_by_name['another_field']
|
||||
self.pool.AddExtensionDescriptor(another_field)
|
||||
|
||||
extensions = self.pool.FindAllExtensions(factory1_message)
|
||||
expected_extension_numbers = set([one_more_field, another_field])
|
||||
@ -356,16 +358,9 @@ class DescriptorPoolTestBase(object):
|
||||
def testFindExtensionByNumber(self):
|
||||
factory1_message = self.pool.FindMessageTypeByName(
|
||||
'google.protobuf.python.internal.Factory1Message')
|
||||
factory2_message = self.pool.FindMessageTypeByName(
|
||||
'google.protobuf.python.internal.Factory2Message')
|
||||
# An extension defined in a message.
|
||||
one_more_field = factory2_message.extensions_by_name['one_more_field']
|
||||
self.pool.AddExtensionDescriptor(one_more_field)
|
||||
# An extension defined at file scope.
|
||||
factory_test2 = self.pool.FindFileByName(
|
||||
# Build factory_test2.proto which will put extensions to the pool
|
||||
self.pool.FindFileByName(
|
||||
'google/protobuf/internal/factory_test2.proto')
|
||||
another_field = factory_test2.extensions_by_name['another_field']
|
||||
self.pool.AddExtensionDescriptor(another_field)
|
||||
|
||||
# An extension defined in a message.
|
||||
extension = self.pool.FindExtensionByNumber(factory1_message, 1001)
|
||||
@ -533,13 +528,13 @@ class DescriptorPoolTestBase(object):
|
||||
else:
|
||||
pool = copy.deepcopy(self.pool)
|
||||
file_descriptor = unittest_pb2.DESCRIPTOR
|
||||
pool.AddDescriptor(
|
||||
pool._AddDescriptor(
|
||||
file_descriptor.message_types_by_name['TestAllTypes'])
|
||||
pool.AddEnumDescriptor(
|
||||
pool._AddEnumDescriptor(
|
||||
file_descriptor.enum_types_by_name['ForeignEnum'])
|
||||
pool.AddServiceDescriptor(
|
||||
pool._AddServiceDescriptor(
|
||||
file_descriptor.services_by_name['TestService'])
|
||||
pool.AddExtensionDescriptor(
|
||||
pool._AddExtensionDescriptor(
|
||||
file_descriptor.extensions_by_name['optional_int32_extension'])
|
||||
pool.Add(unittest_fd)
|
||||
pool.Add(conflict_fd)
|
||||
@ -873,7 +868,7 @@ class AddDescriptorTest(unittest.TestCase):
|
||||
|
||||
def _TestMessage(self, prefix):
|
||||
pool = descriptor_pool.DescriptorPool()
|
||||
pool.AddDescriptor(unittest_pb2.TestAllTypes.DESCRIPTOR)
|
||||
pool._AddDescriptor(unittest_pb2.TestAllTypes.DESCRIPTOR)
|
||||
self.assertEqual(
|
||||
'protobuf_unittest.TestAllTypes',
|
||||
pool.FindMessageTypeByName(
|
||||
@ -884,7 +879,7 @@ class AddDescriptorTest(unittest.TestCase):
|
||||
pool.FindMessageTypeByName(
|
||||
prefix + 'protobuf_unittest.TestAllTypes.NestedMessage')
|
||||
|
||||
pool.AddDescriptor(unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR)
|
||||
pool._AddDescriptor(unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR)
|
||||
self.assertEqual(
|
||||
'protobuf_unittest.TestAllTypes.NestedMessage',
|
||||
pool.FindMessageTypeByName(
|
||||
@ -909,7 +904,10 @@ class AddDescriptorTest(unittest.TestCase):
|
||||
|
||||
def _TestEnum(self, prefix):
|
||||
pool = descriptor_pool.DescriptorPool()
|
||||
pool.AddEnumDescriptor(unittest_pb2.ForeignEnum.DESCRIPTOR)
|
||||
if api_implementation.Type() == 'cpp':
|
||||
pool.AddEnumDescriptor(unittest_pb2.ForeignEnum.DESCRIPTOR)
|
||||
else:
|
||||
pool._AddEnumDescriptor(unittest_pb2.ForeignEnum.DESCRIPTOR)
|
||||
self.assertEqual(
|
||||
'protobuf_unittest.ForeignEnum',
|
||||
pool.FindEnumTypeByName(
|
||||
@ -920,7 +918,10 @@ class AddDescriptorTest(unittest.TestCase):
|
||||
pool.FindEnumTypeByName(
|
||||
prefix + 'protobuf_unittest.ForeignEnum.NestedEnum')
|
||||
|
||||
pool.AddEnumDescriptor(unittest_pb2.TestAllTypes.NestedEnum.DESCRIPTOR)
|
||||
if api_implementation.Type() == 'cpp':
|
||||
pool.AddEnumDescriptor(unittest_pb2.TestAllTypes.NestedEnum.DESCRIPTOR)
|
||||
else:
|
||||
pool._AddEnumDescriptor(unittest_pb2.TestAllTypes.NestedEnum.DESCRIPTOR)
|
||||
self.assertEqual(
|
||||
'protobuf_unittest.TestAllTypes.NestedEnum',
|
||||
pool.FindEnumTypeByName(
|
||||
@ -949,7 +950,7 @@ class AddDescriptorTest(unittest.TestCase):
|
||||
pool = descriptor_pool.DescriptorPool()
|
||||
with self.assertRaises(KeyError):
|
||||
pool.FindServiceByName('protobuf_unittest.TestService')
|
||||
pool.AddServiceDescriptor(unittest_pb2._TESTSERVICE)
|
||||
pool._AddServiceDescriptor(unittest_pb2._TESTSERVICE)
|
||||
self.assertEqual(
|
||||
'protobuf_unittest.TestService',
|
||||
pool.FindServiceByName('protobuf_unittest.TestService').full_name)
|
||||
@ -958,7 +959,7 @@ class AddDescriptorTest(unittest.TestCase):
|
||||
'With the cpp implementation, Add() must be called first')
|
||||
def testFile(self):
|
||||
pool = descriptor_pool.DescriptorPool()
|
||||
pool.AddFileDescriptor(unittest_pb2.DESCRIPTOR)
|
||||
pool._AddFileDescriptor(unittest_pb2.DESCRIPTOR)
|
||||
self.assertEqual(
|
||||
'google/protobuf/unittest.proto',
|
||||
pool.FindFileByName(
|
||||
@ -1032,16 +1033,28 @@ class AddDescriptorTest(unittest.TestCase):
|
||||
|
||||
def testAddTypeError(self):
|
||||
pool = descriptor_pool.DescriptorPool()
|
||||
with self.assertRaises(TypeError):
|
||||
pool.AddDescriptor(0)
|
||||
with self.assertRaises(TypeError):
|
||||
pool.AddEnumDescriptor(0)
|
||||
with self.assertRaises(TypeError):
|
||||
pool.AddServiceDescriptor(0)
|
||||
with self.assertRaises(TypeError):
|
||||
pool.AddExtensionDescriptor(0)
|
||||
with self.assertRaises(TypeError):
|
||||
pool.AddFileDescriptor(0)
|
||||
if api_implementation.Type() == 'cpp':
|
||||
with self.assertRaises(TypeError):
|
||||
pool.AddDescriptor(0)
|
||||
with self.assertRaises(TypeError):
|
||||
pool.AddEnumDescriptor(0)
|
||||
with self.assertRaises(TypeError):
|
||||
pool.AddServiceDescriptor(0)
|
||||
with self.assertRaises(TypeError):
|
||||
pool.AddExtensionDescriptor(0)
|
||||
with self.assertRaises(TypeError):
|
||||
pool.AddFileDescriptor(0)
|
||||
else:
|
||||
with self.assertRaises(TypeError):
|
||||
pool._AddDescriptor(0)
|
||||
with self.assertRaises(TypeError):
|
||||
pool._AddEnumDescriptor(0)
|
||||
with self.assertRaises(TypeError):
|
||||
pool._AddServiceDescriptor(0)
|
||||
with self.assertRaises(TypeError):
|
||||
pool._AddExtensionDescriptor(0)
|
||||
with self.assertRaises(TypeError):
|
||||
pool._AddFileDescriptor(0)
|
||||
|
||||
|
||||
TEST1_FILE = ProtoFile(
|
||||
|
@ -35,6 +35,7 @@
|
||||
__author__ = 'robinson@google.com (Will Robinson)'
|
||||
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
try:
|
||||
import unittest2 as unittest #PY26
|
||||
@ -58,6 +59,9 @@ name: 'TestEmptyMessage'
|
||||
"""
|
||||
|
||||
|
||||
warnings.simplefilter('error', DeprecationWarning)
|
||||
|
||||
|
||||
class DescriptorTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -87,6 +87,10 @@ class _ExtensionDict(object):
|
||||
if extension_handle.label == FieldDescriptor.LABEL_REPEATED:
|
||||
result = extension_handle._default_constructor(self._extended_message)
|
||||
elif extension_handle.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE:
|
||||
message_type = extension_handle.message_type
|
||||
if not hasattr(message_type, '_concrete_class'):
|
||||
# pylint: disable=protected-access
|
||||
self._extended_message._FACTORY.GetPrototype(message_type)
|
||||
assert getattr(extension_handle.message_type, '_concrete_class', None), (
|
||||
'Uninitialized concrete class found for field %r (message type %r)'
|
||||
% (extension_handle.full_name,
|
||||
|
@ -821,6 +821,10 @@ class JsonFormatTest(JsonFormatBase):
|
||||
def testFloatPrecision(self):
|
||||
message = json_format_proto3_pb2.TestMessage()
|
||||
message.float_value = 1.123456789
|
||||
# Default to 8 valid digits.
|
||||
text = '{\n "floatValue": 1.1234568\n}'
|
||||
self.assertEqual(
|
||||
json_format.MessageToJson(message), text)
|
||||
# Set to 7 valid digits.
|
||||
text = '{\n "floatValue": 1.123457\n}'
|
||||
self.assertEqual(
|
||||
|
@ -106,6 +106,9 @@ def IsNegInf(val):
|
||||
return isinf(val) and (val < 0)
|
||||
|
||||
|
||||
warnings.simplefilter('error', DeprecationWarning)
|
||||
|
||||
|
||||
@_parameterized.named_parameters(
|
||||
('_proto2', unittest_pb2),
|
||||
('_proto3', unittest_proto3_arena_pb2))
|
||||
@ -438,12 +441,19 @@ class MessageTest(unittest.TestCase):
|
||||
self.assertEqual(str(message), 'optional_float: 2.0\n')
|
||||
|
||||
def testHighPrecisionFloatPrinting(self, message_module):
|
||||
message = message_module.TestAllTypes()
|
||||
message.optional_double = 0.12345678912345678
|
||||
msg = message_module.TestAllTypes()
|
||||
msg.optional_float = 0.12345678912345678
|
||||
old_float = msg.optional_float
|
||||
msg.ParseFromString(msg.SerializeToString())
|
||||
self.assertEqual(old_float, msg.optional_float)
|
||||
|
||||
def testHighPrecisionDoublePrinting(self, message_module):
|
||||
msg = message_module.TestAllTypes()
|
||||
msg.optional_double = 0.12345678912345678
|
||||
if sys.version_info >= (3,):
|
||||
self.assertEqual(str(message), 'optional_double: 0.12345678912345678\n')
|
||||
self.assertEqual(str(msg), 'optional_double: 0.12345678912345678\n')
|
||||
else:
|
||||
self.assertEqual(str(message), 'optional_double: 0.123456789123\n')
|
||||
self.assertEqual(str(msg), 'optional_double: 0.123456789123\n')
|
||||
|
||||
def testUnknownFieldPrinting(self, message_module):
|
||||
populated = message_module.TestAllTypes()
|
||||
@ -885,11 +895,13 @@ class MessageTest(unittest.TestCase):
|
||||
def testOneofDefaultValues(self, message_module):
|
||||
m = message_module.TestAllTypes()
|
||||
self.assertIs(None, m.WhichOneof('oneof_field'))
|
||||
self.assertFalse(m.HasField('oneof_field'))
|
||||
self.assertFalse(m.HasField('oneof_uint32'))
|
||||
|
||||
# Oneof is set even when setting it to a default value.
|
||||
m.oneof_uint32 = 0
|
||||
self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field'))
|
||||
self.assertTrue(m.HasField('oneof_field'))
|
||||
self.assertTrue(m.HasField('oneof_uint32'))
|
||||
self.assertFalse(m.HasField('oneof_string'))
|
||||
|
||||
|
@ -124,9 +124,16 @@ class GeneratedProtocolMessageType(type):
|
||||
|
||||
Returns:
|
||||
Newly-allocated class.
|
||||
|
||||
Raises:
|
||||
RuntimeError: Generated code only work with python cpp extension.
|
||||
"""
|
||||
descriptor = dictionary[GeneratedProtocolMessageType._DESCRIPTOR_KEY]
|
||||
|
||||
if isinstance(descriptor, str):
|
||||
raise RuntimeError('The generated code only work with python cpp '
|
||||
'extension, but it is using pure python runtime.')
|
||||
|
||||
# If a concrete class already exists for this descriptor, don't try to
|
||||
# create another. Doing so will break any messages that already exist with
|
||||
# the existing class.
|
||||
@ -838,10 +845,9 @@ def _AddHasFieldMethod(message_descriptor, cls):
|
||||
continue
|
||||
hassable_fields[field.name] = field
|
||||
|
||||
if not is_proto3:
|
||||
# Fields inside oneofs are never repeated (enforced by the compiler).
|
||||
for oneof in message_descriptor.oneofs:
|
||||
hassable_fields[oneof.name] = oneof
|
||||
# Has methods are supported for oneof descriptors.
|
||||
for oneof in message_descriptor.oneofs:
|
||||
hassable_fields[oneof.name] = oneof
|
||||
|
||||
def HasField(self, field_name):
|
||||
try:
|
||||
|
@ -40,6 +40,7 @@ import gc
|
||||
import operator
|
||||
import six
|
||||
import struct
|
||||
import warnings
|
||||
|
||||
try:
|
||||
import unittest2 as unittest #PY26
|
||||
@ -70,6 +71,9 @@ if six.PY3:
|
||||
long = int # pylint: disable=redefined-builtin,invalid-name
|
||||
|
||||
|
||||
warnings.simplefilter('error', DeprecationWarning)
|
||||
|
||||
|
||||
class _MiniDecoder(object):
|
||||
"""Decodes a stream of values from a string.
|
||||
|
||||
@ -1433,12 +1437,16 @@ class Proto2ReflectionTest(unittest.TestCase):
|
||||
label=FieldDescriptor.LABEL_OPTIONAL, default_value=0,
|
||||
containing_type=None, message_type=None, enum_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=descriptor_pb2.FieldOptions())
|
||||
options=descriptor_pb2.FieldOptions(),
|
||||
# pylint: disable=protected-access
|
||||
create_key=descriptor._internal_create_key)
|
||||
mydescriptor = descriptor.Descriptor(
|
||||
name='MyProto', full_name='MyProto', filename='ignored',
|
||||
containing_type=None, nested_types=[], enum_types=[],
|
||||
fields=[foo_field_descriptor], extensions=[],
|
||||
options=descriptor_pb2.MessageOptions())
|
||||
options=descriptor_pb2.MessageOptions(),
|
||||
# pylint: disable=protected-access
|
||||
create_key=descriptor._internal_create_key)
|
||||
class MyProtoClass(six.with_metaclass(reflection.GeneratedProtocolMessageType, message.Message)):
|
||||
DESCRIPTOR = mydescriptor
|
||||
myproto_instance = MyProtoClass()
|
||||
@ -3168,22 +3176,34 @@ class ClassAPITest(unittest.TestCase):
|
||||
'C++ implementation requires a call to MakeDescriptor()')
|
||||
@testing_refleaks.SkipReferenceLeakChecker('MakeClass is not repeatable')
|
||||
def testMakeClassWithNestedDescriptor(self):
|
||||
leaf_desc = descriptor.Descriptor('leaf', 'package.parent.child.leaf', '',
|
||||
containing_type=None, fields=[],
|
||||
nested_types=[], enum_types=[],
|
||||
extensions=[])
|
||||
child_desc = descriptor.Descriptor('child', 'package.parent.child', '',
|
||||
containing_type=None, fields=[],
|
||||
nested_types=[leaf_desc], enum_types=[],
|
||||
extensions=[])
|
||||
sibling_desc = descriptor.Descriptor('sibling', 'package.parent.sibling',
|
||||
'', containing_type=None, fields=[],
|
||||
nested_types=[], enum_types=[],
|
||||
extensions=[])
|
||||
parent_desc = descriptor.Descriptor('parent', 'package.parent', '',
|
||||
containing_type=None, fields=[],
|
||||
nested_types=[child_desc, sibling_desc],
|
||||
enum_types=[], extensions=[])
|
||||
leaf_desc = descriptor.Descriptor(
|
||||
'leaf', 'package.parent.child.leaf', '',
|
||||
containing_type=None, fields=[],
|
||||
nested_types=[], enum_types=[],
|
||||
extensions=[],
|
||||
# pylint: disable=protected-access
|
||||
create_key=descriptor._internal_create_key)
|
||||
child_desc = descriptor.Descriptor(
|
||||
'child', 'package.parent.child', '',
|
||||
containing_type=None, fields=[],
|
||||
nested_types=[leaf_desc], enum_types=[],
|
||||
extensions=[],
|
||||
# pylint: disable=protected-access
|
||||
create_key=descriptor._internal_create_key)
|
||||
sibling_desc = descriptor.Descriptor(
|
||||
'sibling', 'package.parent.sibling',
|
||||
'', containing_type=None, fields=[],
|
||||
nested_types=[], enum_types=[],
|
||||
extensions=[],
|
||||
# pylint: disable=protected-access
|
||||
create_key=descriptor._internal_create_key)
|
||||
parent_desc = descriptor.Descriptor(
|
||||
'parent', 'package.parent', '',
|
||||
containing_type=None, fields=[],
|
||||
nested_types=[child_desc, sibling_desc],
|
||||
enum_types=[], extensions=[],
|
||||
# pylint: disable=protected-access
|
||||
create_key=descriptor._internal_create_key)
|
||||
reflection.MakeClass(parent_desc)
|
||||
|
||||
def _GetSerializedFileDescriptor(self, name):
|
||||
@ -3305,4 +3325,3 @@ class ClassAPITest(unittest.TestCase):
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
@ -2194,5 +2194,23 @@ class WhitespaceTest(TextFormatBase):
|
||||
}"""))
|
||||
|
||||
|
||||
class OptionalColonMessageToStringTest(unittest.TestCase):
|
||||
|
||||
def testForcePrintOptionalColon(self):
|
||||
packed_message = unittest_pb2.OneString()
|
||||
packed_message.data = 'string'
|
||||
message = any_test_pb2.TestAny()
|
||||
message.any_value.Pack(packed_message)
|
||||
output = text_format.MessageToString(
|
||||
message,
|
||||
force_colon=True)
|
||||
expected = ('any_value: {\n'
|
||||
' [type.googleapis.com/protobuf_unittest.OneString]: {\n'
|
||||
' data: "string"\n'
|
||||
' }\n'
|
||||
'}\n')
|
||||
self.assertEqual(expected, output)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -45,6 +45,11 @@ TYPE_TO_DESERIALIZE_METHOD: A dictionary with field types and deserialization
|
||||
|
||||
__author__ = 'robinson@google.com (Will Robinson)'
|
||||
|
||||
try:
|
||||
import ctypes
|
||||
except Exception: # pylint: disable=broad-except
|
||||
ctypes = None
|
||||
import struct
|
||||
import numbers
|
||||
import six
|
||||
|
||||
@ -257,9 +262,10 @@ class FloatValueChecker(object):
|
||||
if converted_value < _FLOAT_MIN:
|
||||
return _NEG_INF
|
||||
|
||||
return converted_value
|
||||
# TODO(jieluo): convert to 4 bytes float (c style float) at setters:
|
||||
# return struct.unpack('f', struct.pack('f', converted_value))
|
||||
if ctypes:
|
||||
return ctypes.c_float(converted_value).value
|
||||
else:
|
||||
return struct.unpack('<f', struct.pack('<f', converted_value))[0]
|
||||
|
||||
def DefaultValue(self):
|
||||
return 0.0
|
||||
|
@ -104,7 +104,7 @@ def MessageToJson(
|
||||
sort_keys=False,
|
||||
use_integers_for_enums=False,
|
||||
descriptor_pool=None,
|
||||
float_precision=None):
|
||||
float_precision=8):
|
||||
"""Converts protobuf message to JSON format.
|
||||
|
||||
Args:
|
||||
@ -123,6 +123,7 @@ def MessageToJson(
|
||||
descriptor_pool: A Descriptor Pool for resolving types. If None use the
|
||||
default.
|
||||
float_precision: If set, use this to specify float field valid digits.
|
||||
Otherwise, 8 valid digits is used (default '.8g').
|
||||
|
||||
Returns:
|
||||
A string containing the JSON formatted protocol buffer message.
|
||||
@ -142,7 +143,7 @@ def MessageToDict(
|
||||
preserving_proto_field_name=False,
|
||||
use_integers_for_enums=False,
|
||||
descriptor_pool=None,
|
||||
float_precision=None):
|
||||
float_precision=8):
|
||||
"""Converts protobuf message to a dictionary.
|
||||
|
||||
When the dictionary is encoded to JSON, it conforms to proto3 JSON spec.
|
||||
@ -160,6 +161,7 @@ def MessageToDict(
|
||||
descriptor_pool: A Descriptor Pool for resolving types. If None use the
|
||||
default.
|
||||
float_precision: If set, use this to specify float field valid digits.
|
||||
Otherwise, 8 valid digits is used (default '.8g').
|
||||
|
||||
Returns:
|
||||
A dict representation of the protocol buffer message.
|
||||
|
@ -83,6 +83,8 @@ class MessageFactory(object):
|
||||
descriptor_name,
|
||||
(message.Message,),
|
||||
{'DESCRIPTOR': descriptor, '__module__': None})
|
||||
# pylint: disable=protected-access
|
||||
result_class._FACTORY = self
|
||||
# If module not set, it wrongly points to message_factory module.
|
||||
self._classes[descriptor] = result_class
|
||||
for field in descriptor.fields:
|
||||
|
@ -1425,16 +1425,7 @@ bool CheckHasPresence(const FieldDescriptor* field_descriptor, bool in_oneof) {
|
||||
}
|
||||
|
||||
if (field_descriptor->file()->syntax() == FileDescriptor::SYNTAX_PROTO3) {
|
||||
// HasField() for a oneof *itself* isn't supported.
|
||||
if (in_oneof) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"Can't test oneof field \"%s.%s\" for presence in proto3, "
|
||||
"use WhichOneof instead.", message_name.c_str(),
|
||||
field_descriptor->containing_oneof()->name().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// ...but HasField() for fields *in* a oneof is supported.
|
||||
// HasField() is supported for oneof fields.
|
||||
if (field_descriptor->containing_oneof() != NULL) {
|
||||
return true;
|
||||
}
|
||||
|
@ -107,9 +107,12 @@ PyMODINIT_FUNC INITFUNC() {
|
||||
}
|
||||
|
||||
// Adds the C++ API
|
||||
if (PyObject* api =
|
||||
PyCapsule_New(new ApiImplementation(),
|
||||
google::protobuf::python::PyProtoAPICapsuleName(), NULL)) {
|
||||
if (PyObject* api = PyCapsule_New(
|
||||
new ApiImplementation(), google::protobuf::python::PyProtoAPICapsuleName(),
|
||||
[](PyObject* o) {
|
||||
delete (ApiImplementation*)PyCapsule_GetPointer(
|
||||
o, google::protobuf::python::PyProtoAPICapsuleName());
|
||||
})) {
|
||||
PyModule_AddObject(m, "proto_API", api);
|
||||
} else {
|
||||
return INITFUNC_ERRORVAL;
|
||||
|
@ -132,7 +132,8 @@ def MessageToString(message,
|
||||
descriptor_pool=None,
|
||||
indent=0,
|
||||
message_formatter=None,
|
||||
print_unknown_fields=False):
|
||||
print_unknown_fields=False,
|
||||
force_colon=False):
|
||||
# type: (...) -> str
|
||||
"""Convert protobuf message to text format.
|
||||
|
||||
@ -170,17 +171,28 @@ def MessageToString(message,
|
||||
Custom formatter for selected sub-messages (usually based on message
|
||||
type). Use to pretty print parts of the protobuf for easier diffing.
|
||||
print_unknown_fields: If True, unknown fields will be printed.
|
||||
force_colon: If set, a colon will be added after the field name even if the
|
||||
field is a proto message.
|
||||
|
||||
Returns:
|
||||
str: A string of the text formatted protocol buffer message.
|
||||
"""
|
||||
out = TextWriter(as_utf8)
|
||||
printer = _Printer(out, indent, as_utf8, as_one_line,
|
||||
use_short_repeated_primitives, pointy_brackets,
|
||||
use_index_order, float_format, double_format,
|
||||
use_field_number,
|
||||
descriptor_pool, message_formatter,
|
||||
print_unknown_fields=print_unknown_fields)
|
||||
printer = _Printer(
|
||||
out,
|
||||
indent,
|
||||
as_utf8,
|
||||
as_one_line,
|
||||
use_short_repeated_primitives,
|
||||
pointy_brackets,
|
||||
use_index_order,
|
||||
float_format,
|
||||
double_format,
|
||||
use_field_number,
|
||||
descriptor_pool,
|
||||
message_formatter,
|
||||
print_unknown_fields=print_unknown_fields,
|
||||
force_colon=force_colon)
|
||||
printer.PrintMessage(message)
|
||||
result = out.getvalue()
|
||||
out.close()
|
||||
@ -218,7 +230,8 @@ def PrintMessage(message,
|
||||
use_field_number=False,
|
||||
descriptor_pool=None,
|
||||
message_formatter=None,
|
||||
print_unknown_fields=False):
|
||||
print_unknown_fields=False,
|
||||
force_colon=False):
|
||||
printer = _Printer(
|
||||
out=out, indent=indent, as_utf8=as_utf8,
|
||||
as_one_line=as_one_line,
|
||||
@ -230,7 +243,8 @@ def PrintMessage(message,
|
||||
use_field_number=use_field_number,
|
||||
descriptor_pool=descriptor_pool,
|
||||
message_formatter=message_formatter,
|
||||
print_unknown_fields=print_unknown_fields)
|
||||
print_unknown_fields=print_unknown_fields,
|
||||
force_colon=force_colon)
|
||||
printer.PrintMessage(message)
|
||||
|
||||
|
||||
@ -246,13 +260,15 @@ def PrintField(field,
|
||||
float_format=None,
|
||||
double_format=None,
|
||||
message_formatter=None,
|
||||
print_unknown_fields=False):
|
||||
print_unknown_fields=False,
|
||||
force_colon=False):
|
||||
"""Print a single field name/value pair."""
|
||||
printer = _Printer(out, indent, as_utf8, as_one_line,
|
||||
use_short_repeated_primitives, pointy_brackets,
|
||||
use_index_order, float_format, double_format,
|
||||
message_formatter=message_formatter,
|
||||
print_unknown_fields=print_unknown_fields)
|
||||
print_unknown_fields=print_unknown_fields,
|
||||
force_colon=force_colon)
|
||||
printer.PrintField(field, value)
|
||||
|
||||
|
||||
@ -268,13 +284,15 @@ def PrintFieldValue(field,
|
||||
float_format=None,
|
||||
double_format=None,
|
||||
message_formatter=None,
|
||||
print_unknown_fields=False):
|
||||
print_unknown_fields=False,
|
||||
force_colon=False):
|
||||
"""Print a single field value (not including name)."""
|
||||
printer = _Printer(out, indent, as_utf8, as_one_line,
|
||||
use_short_repeated_primitives, pointy_brackets,
|
||||
use_index_order, float_format, double_format,
|
||||
message_formatter=message_formatter,
|
||||
print_unknown_fields=print_unknown_fields)
|
||||
print_unknown_fields=print_unknown_fields,
|
||||
force_colon=force_colon)
|
||||
printer.PrintFieldValue(field, value)
|
||||
|
||||
|
||||
@ -324,7 +342,8 @@ class _Printer(object):
|
||||
use_field_number=False,
|
||||
descriptor_pool=None,
|
||||
message_formatter=None,
|
||||
print_unknown_fields=False):
|
||||
print_unknown_fields=False,
|
||||
force_colon=False):
|
||||
"""Initialize the Printer.
|
||||
|
||||
Double values can be formatted compactly with 15 digits of precision
|
||||
@ -358,6 +377,8 @@ class _Printer(object):
|
||||
to custom format selected sub-messages (usually based on message type).
|
||||
Use to pretty print parts of the protobuf for easier diffing.
|
||||
print_unknown_fields: If True, unknown fields will be printed.
|
||||
force_colon: If set, a colon will be added after the field name even if
|
||||
the field is a proto message.
|
||||
"""
|
||||
self.out = out
|
||||
self.indent = indent
|
||||
@ -375,6 +396,7 @@ class _Printer(object):
|
||||
self.descriptor_pool = descriptor_pool
|
||||
self.message_formatter = message_formatter
|
||||
self.print_unknown_fields = print_unknown_fields
|
||||
self.force_colon = force_colon
|
||||
|
||||
def _TryPrintAsAnyMessage(self, message):
|
||||
"""Serializes if message is a google.protobuf.Any field."""
|
||||
@ -384,7 +406,8 @@ class _Printer(object):
|
||||
self.descriptor_pool)
|
||||
if packed_message:
|
||||
packed_message.MergeFromString(message.value)
|
||||
self.out.write('%s[%s] ' % (self.indent * ' ', message.type_url))
|
||||
colon = ':' if self.force_colon else ''
|
||||
self.out.write('%s[%s]%s ' % (self.indent * ' ', message.type_url, colon))
|
||||
self._PrintMessageFieldValue(packed_message)
|
||||
self.out.write(' ' if self.as_one_line else '\n')
|
||||
return True
|
||||
@ -518,9 +541,11 @@ class _Printer(object):
|
||||
else:
|
||||
out.write(field.name)
|
||||
|
||||
if field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_MESSAGE:
|
||||
if (self.force_colon or
|
||||
field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_MESSAGE):
|
||||
# The colon is optional in this case, but our cross-language golden files
|
||||
# don't include it.
|
||||
# don't include it. Here, the colon is only included if force_colon is
|
||||
# set to True
|
||||
out.write(':')
|
||||
|
||||
def PrintField(self, field, value):
|
||||
@ -531,6 +556,7 @@ class _Printer(object):
|
||||
self.out.write(' ' if self.as_one_line else '\n')
|
||||
|
||||
def _PrintShortRepeatedPrimitivesValue(self, field, value):
|
||||
""""Prints short repeated primitives value."""
|
||||
# Note: this is called only when value has at least one element.
|
||||
self._PrintFieldName(field)
|
||||
self.out.write(' [')
|
||||
@ -539,6 +565,8 @@ class _Printer(object):
|
||||
self.out.write(', ')
|
||||
self.PrintFieldValue(field, value[-1])
|
||||
self.out.write(']')
|
||||
if self.force_colon:
|
||||
self.out.write(':')
|
||||
self.out.write(' ' if self.as_one_line else '\n')
|
||||
|
||||
def _PrintMessageFieldValue(self, value):
|
||||
|
@ -19,23 +19,17 @@ from distutils.command.build_py import build_py as _build_py
|
||||
from distutils.command.clean import clean as _clean
|
||||
from distutils.spawn import find_executable
|
||||
|
||||
|
||||
current_dir = (os.path.dirname(__file__) or os.curdir)
|
||||
current_dir_relative = os.path.relpath(current_dir)
|
||||
src_dir = os.path.abspath(os.path.join(current_dir, "..", "src"))
|
||||
vsprojects_dir = os.path.abspath(os.path.join(current_dir, "..", "vsprojects"))
|
||||
|
||||
# Find the Protocol Compiler.
|
||||
if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']):
|
||||
protoc = os.environ['PROTOC']
|
||||
elif os.path.exists(os.path.join(src_dir, "protoc")):
|
||||
protoc = os.path.join(src_dir, "protoc")
|
||||
elif os.path.exists(os.path.join(src_dir, "protoc.exe")):
|
||||
protoc = os.path.join(src_dir, "protoc.exe")
|
||||
elif os.path.exists(os.path.join(vsprojects_dir, "Debug", "protoc.exe")):
|
||||
protoc = os.path.join(vsprojects_dir, "Debug", "protoc.exe")
|
||||
elif os.path.exists(os.path.join(vsprojects_dir, "Release", "protoc.exe")):
|
||||
protoc = os.path.join(vsprojects_dir, "Release", "protoc.exe")
|
||||
elif os.path.exists("../src/protoc"):
|
||||
protoc = "../src/protoc"
|
||||
elif os.path.exists("../src/protoc.exe"):
|
||||
protoc = "../src/protoc.exe"
|
||||
elif os.path.exists("../vsprojects/Debug/protoc.exe"):
|
||||
protoc = "../vsprojects/Debug/protoc.exe"
|
||||
elif os.path.exists("../vsprojects/Release/protoc.exe"):
|
||||
protoc = "../vsprojects/Release/protoc.exe"
|
||||
else:
|
||||
protoc = find_executable("protoc")
|
||||
|
||||
@ -46,7 +40,7 @@ def GetVersion():
|
||||
Do not import google.protobuf.__init__ directly, because an installed
|
||||
protobuf library may be loaded instead."""
|
||||
|
||||
with open(os.path.join(current_dir, 'google', 'protobuf', '__init__.py')) as version_file:
|
||||
with open(os.path.join('google', 'protobuf', '__init__.py')) as version_file:
|
||||
exec(version_file.read(), globals())
|
||||
global __version__
|
||||
return __version__
|
||||
@ -57,21 +51,15 @@ def generate_proto(source, require = True):
|
||||
.proto file. Does nothing if the output already exists and is newer than
|
||||
the input."""
|
||||
|
||||
original_source = source
|
||||
source = source.replace("../src", src_dir)
|
||||
|
||||
if not require and not os.path.exists(source):
|
||||
return
|
||||
|
||||
output = os.path.join(
|
||||
current_dir,
|
||||
original_source.replace(".proto", "_pb2.py").replace("../src/", "")
|
||||
)
|
||||
output = source.replace(".proto", "_pb2.py").replace("../src/", "")
|
||||
|
||||
if (not os.path.exists(output) or
|
||||
(os.path.exists(source) and
|
||||
os.path.getmtime(source) > os.path.getmtime(output))):
|
||||
print("Generating %s..." % os.path.relpath(output))
|
||||
print("Generating %s..." % output)
|
||||
|
||||
if not os.path.exists(source):
|
||||
sys.stderr.write("Can't find required file: %s\n" % source)
|
||||
@ -83,13 +71,7 @@ def generate_proto(source, require = True):
|
||||
"or install the binary package.\n")
|
||||
sys.exit(-1)
|
||||
|
||||
protoc_command = [
|
||||
protoc,
|
||||
"-I{}".format(src_dir),
|
||||
"-I{}".format(current_dir),
|
||||
"--python_out={}".format(current_dir),
|
||||
source,
|
||||
]
|
||||
protoc_command = [ protoc, "-I../src", "-I.", "--python_out=.", source ]
|
||||
if subprocess.call(protoc_command) != 0:
|
||||
sys.exit(-1)
|
||||
|
||||
@ -134,7 +116,7 @@ def GenerateUnittestProtos():
|
||||
class clean(_clean):
|
||||
def run(self):
|
||||
# Delete generated files in the code tree.
|
||||
for (dirpath, dirnames, filenames) in os.walk(current_dir):
|
||||
for (dirpath, dirnames, filenames) in os.walk("."):
|
||||
for filename in filenames:
|
||||
filepath = os.path.join(dirpath, filename)
|
||||
if filepath.endswith("_pb2.py") or filepath.endswith(".pyc") or \
|
||||
@ -287,14 +269,7 @@ if __name__ == '__main__':
|
||||
"Programming Language :: Python :: 3.7",
|
||||
],
|
||||
namespace_packages=['google'],
|
||||
# package_dir is required when setup.py is not run from the python/
|
||||
# directory (such as from the ReadTheDocs build). See
|
||||
# https://setuptools.readthedocs.io/en/latest/setuptools.html#using-find-packages
|
||||
# package_dir must be a relative path. See:
|
||||
# https://stackoverflow.com/a/53547931/101923
|
||||
package_dir={"": current_dir_relative},
|
||||
packages=find_packages(
|
||||
where=current_dir,
|
||||
exclude=[
|
||||
'import_test_package',
|
||||
],
|
||||
|
@ -510,6 +510,7 @@ protoc_inputs = \
|
||||
google/protobuf/unittest_proto3_arena.proto \
|
||||
google/protobuf/unittest_proto3_arena_lite.proto \
|
||||
google/protobuf/unittest_proto3_lite.proto \
|
||||
google/protobuf/unittest_proto3_optional.proto \
|
||||
google/protobuf/unittest_well_known_types.proto \
|
||||
google/protobuf/util/internal/testdata/anys.proto \
|
||||
google/protobuf/util/internal/testdata/books.proto \
|
||||
@ -643,6 +644,8 @@ protoc_outputs = \
|
||||
google/protobuf/unittest_proto3_arena_lite.pb.h \
|
||||
google/protobuf/unittest_proto3_lite.pb.cc \
|
||||
google/protobuf/unittest_proto3_lite.pb.h \
|
||||
google/protobuf/unittest_proto3_optional.pb.cc \
|
||||
google/protobuf/unittest_proto3_optional.pb.h \
|
||||
google/protobuf/unittest_well_known_types.pb.cc \
|
||||
google/protobuf/unittest_well_known_types.pb.h \
|
||||
google/protobuf/util/internal/testdata/anys.pb.cc \
|
||||
@ -686,7 +689,7 @@ else
|
||||
# relative to srcdir, which may not be the same as the current directory when
|
||||
# building out-of-tree.
|
||||
unittest_proto_middleman: protoc$(EXEEXT) $(protoc_inputs)
|
||||
oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/protoc$(EXEEXT) -I. --cpp_out=$$oldpwd $(protoc_inputs) )
|
||||
oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/protoc$(EXEEXT) -I. --cpp_out=$$oldpwd $(protoc_inputs) --experimental_allow_proto3_optional )
|
||||
touch unittest_proto_middleman
|
||||
|
||||
endif
|
||||
|
@ -69,9 +69,8 @@ static ::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase*const descriptor_table_goo
|
||||
&scc_info_Any_google_2fprotobuf_2fany_2eproto.base,
|
||||
};
|
||||
static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_google_2fprotobuf_2fany_2eproto_once;
|
||||
static bool descriptor_table_google_2fprotobuf_2fany_2eproto_initialized = false;
|
||||
const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fany_2eproto = {
|
||||
&descriptor_table_google_2fprotobuf_2fany_2eproto_initialized, descriptor_table_protodef_google_2fprotobuf_2fany_2eproto, "google/protobuf/any.proto", 205,
|
||||
false, false, descriptor_table_protodef_google_2fprotobuf_2fany_2eproto, "google/protobuf/any.proto", 205,
|
||||
&descriptor_table_google_2fprotobuf_2fany_2eproto_once, descriptor_table_google_2fprotobuf_2fany_2eproto_sccs, descriptor_table_google_2fprotobuf_2fany_2eproto_deps, 1, 0,
|
||||
schemas, file_default_instances, TableStruct_google_2fprotobuf_2fany_2eproto::offsets,
|
||||
file_level_metadata_google_2fprotobuf_2fany_2eproto, 1, file_level_enum_descriptors_google_2fprotobuf_2fany_2eproto, file_level_service_descriptors_google_2fprotobuf_2fany_2eproto,
|
||||
@ -102,23 +101,26 @@ class Any::_Internal {
|
||||
public:
|
||||
};
|
||||
|
||||
Any::Any()
|
||||
: ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr), _any_metadata_(&type_url_, &value_) {
|
||||
Any::Any(::PROTOBUF_NAMESPACE_ID::Arena* arena)
|
||||
: ::PROTOBUF_NAMESPACE_ID::Message(arena),
|
||||
_any_metadata_(&type_url_, &value_) {
|
||||
SharedCtor();
|
||||
// @@protoc_insertion_point(constructor:google.protobuf.Any)
|
||||
RegisterArenaDtor(arena);
|
||||
// @@protoc_insertion_point(arena_constructor:google.protobuf.Any)
|
||||
}
|
||||
Any::Any(const Any& from)
|
||||
: ::PROTOBUF_NAMESPACE_ID::Message(),
|
||||
_internal_metadata_(nullptr),
|
||||
_any_metadata_(&type_url_, &value_) {
|
||||
_internal_metadata_.MergeFrom(from._internal_metadata_);
|
||||
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
|
||||
type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
if (!from._internal_type_url().empty()) {
|
||||
type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.type_url_);
|
||||
type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_type_url(),
|
||||
GetArena());
|
||||
}
|
||||
value_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
if (!from._internal_value().empty()) {
|
||||
value_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.value_);
|
||||
value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_value(),
|
||||
GetArena());
|
||||
}
|
||||
// @@protoc_insertion_point(copy_constructor:google.protobuf.Any)
|
||||
}
|
||||
@ -132,13 +134,21 @@ void Any::SharedCtor() {
|
||||
Any::~Any() {
|
||||
// @@protoc_insertion_point(destructor:google.protobuf.Any)
|
||||
SharedDtor();
|
||||
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
|
||||
}
|
||||
|
||||
void Any::SharedDtor() {
|
||||
GOOGLE_DCHECK(GetArena() == nullptr);
|
||||
type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
value_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
}
|
||||
|
||||
void Any::ArenaDtor(void* object) {
|
||||
Any* _this = reinterpret_cast< Any* >(object);
|
||||
(void)_this;
|
||||
}
|
||||
void Any::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
|
||||
}
|
||||
void Any::SetCachedSize(int size) const {
|
||||
_cached_size_.Set(size);
|
||||
}
|
||||
@ -154,13 +164,14 @@ void Any::Clear() {
|
||||
// Prevent compiler warnings about cached_has_bits being unused
|
||||
(void) cached_has_bits;
|
||||
|
||||
type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
value_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
_internal_metadata_.Clear();
|
||||
type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
value_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
|
||||
}
|
||||
|
||||
const char* Any::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
|
||||
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
|
||||
::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena;
|
||||
while (!ctx->Done(&ptr)) {
|
||||
::PROTOBUF_NAMESPACE_ID::uint32 tag;
|
||||
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
|
||||
@ -189,7 +200,9 @@ const char* Any::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::intern
|
||||
ctx->SetLastTag(tag);
|
||||
goto success;
|
||||
}
|
||||
ptr = UnknownFieldParse(tag, &_internal_metadata_, ptr, ctx);
|
||||
ptr = UnknownFieldParse(tag,
|
||||
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
|
||||
ptr, ctx);
|
||||
CHK_(ptr != nullptr);
|
||||
continue;
|
||||
}
|
||||
@ -227,7 +240,7 @@ failure:
|
||||
|
||||
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
|
||||
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
|
||||
_internal_metadata_.unknown_fields(), target, stream);
|
||||
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
|
||||
}
|
||||
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Any)
|
||||
return target;
|
||||
@ -282,17 +295,15 @@ void Any::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) {
|
||||
void Any::MergeFrom(const Any& from) {
|
||||
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Any)
|
||||
GOOGLE_DCHECK_NE(&from, this);
|
||||
_internal_metadata_.MergeFrom(from._internal_metadata_);
|
||||
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
|
||||
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
|
||||
(void) cached_has_bits;
|
||||
|
||||
if (from.type_url().size() > 0) {
|
||||
|
||||
type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.type_url_);
|
||||
_internal_set_type_url(from._internal_type_url());
|
||||
}
|
||||
if (from.value().size() > 0) {
|
||||
|
||||
value_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.value_);
|
||||
_internal_set_value(from._internal_value());
|
||||
}
|
||||
}
|
||||
|
||||
@ -316,11 +327,9 @@ bool Any::IsInitialized() const {
|
||||
|
||||
void Any::InternalSwap(Any* other) {
|
||||
using std::swap;
|
||||
_internal_metadata_.Swap(&other->_internal_metadata_);
|
||||
type_url_.Swap(&other->type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArenaNoVirtual());
|
||||
value_.Swap(&other->value_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArenaNoVirtual());
|
||||
_internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_);
|
||||
type_url_.Swap(&other->type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
value_.Swap(&other->value_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
|
||||
::PROTOBUF_NAMESPACE_ID::Metadata Any::GetMetadata() const {
|
||||
@ -332,7 +341,7 @@ void Any::InternalSwap(Any* other) {
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
template<> PROTOBUF_NOINLINE PROTOBUF_NAMESPACE_ID::Any* Arena::CreateMaybeMessage< PROTOBUF_NAMESPACE_ID::Any >(Arena* arena) {
|
||||
return Arena::CreateInternal< PROTOBUF_NAMESPACE_ID::Any >(arena);
|
||||
return Arena::CreateMessageInternal< PROTOBUF_NAMESPACE_ID::Any >(arena);
|
||||
}
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include <google/protobuf/generated_message_table_driven.h>
|
||||
#include <google/protobuf/generated_message_util.h>
|
||||
#include <google/protobuf/inlined_string_field.h>
|
||||
#include <google/protobuf/metadata.h>
|
||||
#include <google/protobuf/metadata_lite.h>
|
||||
#include <google/protobuf/generated_message_reflection.h>
|
||||
#include <google/protobuf/message.h>
|
||||
#include <google/protobuf/repeated_field.h> // IWYU pragma: export
|
||||
@ -66,10 +66,10 @@ PROTOBUF_NAMESPACE_OPEN
|
||||
|
||||
// ===================================================================
|
||||
|
||||
class PROTOBUF_EXPORT Any :
|
||||
class PROTOBUF_EXPORT Any PROTOBUF_FINAL :
|
||||
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Any) */ {
|
||||
public:
|
||||
Any();
|
||||
inline Any() : Any(nullptr) {};
|
||||
virtual ~Any();
|
||||
|
||||
Any(const Any& from);
|
||||
@ -83,7 +83,7 @@ class PROTOBUF_EXPORT Any :
|
||||
return *this;
|
||||
}
|
||||
inline Any& operator=(Any&& from) noexcept {
|
||||
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
|
||||
if (GetArena() == from.GetArena()) {
|
||||
if (this != &from) InternalSwap(&from);
|
||||
} else {
|
||||
CopyFrom(from);
|
||||
@ -148,6 +148,15 @@ class PROTOBUF_EXPORT Any :
|
||||
}
|
||||
inline void Swap(Any* other) {
|
||||
if (other == this) return;
|
||||
if (GetArena() == other->GetArena()) {
|
||||
InternalSwap(other);
|
||||
} else {
|
||||
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
|
||||
}
|
||||
}
|
||||
void UnsafeArenaSwap(Any* other) {
|
||||
if (other == this) return;
|
||||
GOOGLE_DCHECK(GetArena() == other->GetArena());
|
||||
InternalSwap(other);
|
||||
}
|
||||
|
||||
@ -182,13 +191,11 @@ class PROTOBUF_EXPORT Any :
|
||||
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
|
||||
return "google.protobuf.Any";
|
||||
}
|
||||
protected:
|
||||
explicit Any(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
private:
|
||||
inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const {
|
||||
return nullptr;
|
||||
}
|
||||
inline void* MaybeArenaPtr() const {
|
||||
return nullptr;
|
||||
}
|
||||
static void ArenaDtor(void* object);
|
||||
inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
public:
|
||||
|
||||
::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;
|
||||
@ -218,6 +225,15 @@ class PROTOBUF_EXPORT Any :
|
||||
std::string* mutable_type_url();
|
||||
std::string* release_type_url();
|
||||
void set_allocated_type_url(std::string* type_url);
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
std::string* unsafe_arena_release_type_url();
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
void unsafe_arena_set_allocated_type_url(
|
||||
std::string* type_url);
|
||||
private:
|
||||
const std::string& _internal_type_url() const;
|
||||
void _internal_set_type_url(const std::string& value);
|
||||
@ -234,6 +250,15 @@ class PROTOBUF_EXPORT Any :
|
||||
std::string* mutable_value();
|
||||
std::string* release_value();
|
||||
void set_allocated_value(std::string* value);
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
std::string* unsafe_arena_release_value();
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
void unsafe_arena_set_allocated_value(
|
||||
std::string* value);
|
||||
private:
|
||||
const std::string& _internal_value() const;
|
||||
void _internal_set_value(const std::string& value);
|
||||
@ -244,7 +269,9 @@ class PROTOBUF_EXPORT Any :
|
||||
private:
|
||||
class _Internal;
|
||||
|
||||
::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_;
|
||||
template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
|
||||
typedef void InternalArenaConstructable_;
|
||||
typedef void DestructorSkippable_;
|
||||
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr type_url_;
|
||||
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr value_;
|
||||
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
|
||||
@ -264,7 +291,7 @@ class PROTOBUF_EXPORT Any :
|
||||
|
||||
// string type_url = 1;
|
||||
inline void Any::clear_type_url() {
|
||||
type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline const std::string& Any::type_url() const {
|
||||
// @@protoc_insertion_point(field_get:google.protobuf.Any.type_url)
|
||||
@ -279,38 +306,40 @@ inline std::string* Any::mutable_type_url() {
|
||||
return _internal_mutable_type_url();
|
||||
}
|
||||
inline const std::string& Any::_internal_type_url() const {
|
||||
return type_url_.GetNoArena();
|
||||
return type_url_.Get();
|
||||
}
|
||||
inline void Any::_internal_set_type_url(const std::string& value) {
|
||||
|
||||
type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
|
||||
type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
|
||||
}
|
||||
inline void Any::set_type_url(std::string&& value) {
|
||||
|
||||
type_url_.SetNoArena(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
|
||||
type_url_.Set(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
|
||||
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Any.type_url)
|
||||
}
|
||||
inline void Any::set_type_url(const char* value) {
|
||||
GOOGLE_DCHECK(value != nullptr);
|
||||
|
||||
type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
|
||||
type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_char:google.protobuf.Any.type_url)
|
||||
}
|
||||
inline void Any::set_type_url(const char* value, size_t size) {
|
||||
inline void Any::set_type_url(const char* value,
|
||||
size_t size) {
|
||||
|
||||
type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
::std::string(reinterpret_cast<const char*>(value), size));
|
||||
type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
|
||||
reinterpret_cast<const char*>(value), size), GetArena());
|
||||
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Any.type_url)
|
||||
}
|
||||
inline std::string* Any::_internal_mutable_type_url() {
|
||||
|
||||
return type_url_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return type_url_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline std::string* Any::release_type_url() {
|
||||
// @@protoc_insertion_point(field_release:google.protobuf.Any.type_url)
|
||||
|
||||
return type_url_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline void Any::set_allocated_type_url(std::string* type_url) {
|
||||
if (type_url != nullptr) {
|
||||
@ -318,13 +347,33 @@ inline void Any::set_allocated_type_url(std::string* type_url) {
|
||||
} else {
|
||||
|
||||
}
|
||||
type_url_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), type_url);
|
||||
type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), type_url,
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.type_url)
|
||||
}
|
||||
inline std::string* Any::unsafe_arena_release_type_url() {
|
||||
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Any.type_url)
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
|
||||
return type_url_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArena());
|
||||
}
|
||||
inline void Any::unsafe_arena_set_allocated_type_url(
|
||||
std::string* type_url) {
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
if (type_url != nullptr) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
type_url_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
type_url, GetArena());
|
||||
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Any.type_url)
|
||||
}
|
||||
|
||||
// bytes value = 2;
|
||||
inline void Any::clear_value() {
|
||||
value_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
value_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline const std::string& Any::value() const {
|
||||
// @@protoc_insertion_point(field_get:google.protobuf.Any.value)
|
||||
@ -339,38 +388,40 @@ inline std::string* Any::mutable_value() {
|
||||
return _internal_mutable_value();
|
||||
}
|
||||
inline const std::string& Any::_internal_value() const {
|
||||
return value_.GetNoArena();
|
||||
return value_.Get();
|
||||
}
|
||||
inline void Any::_internal_set_value(const std::string& value) {
|
||||
|
||||
value_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
|
||||
value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
|
||||
}
|
||||
inline void Any::set_value(std::string&& value) {
|
||||
|
||||
value_.SetNoArena(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
|
||||
value_.Set(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
|
||||
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Any.value)
|
||||
}
|
||||
inline void Any::set_value(const char* value) {
|
||||
GOOGLE_DCHECK(value != nullptr);
|
||||
|
||||
value_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
|
||||
value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_char:google.protobuf.Any.value)
|
||||
}
|
||||
inline void Any::set_value(const void* value, size_t size) {
|
||||
inline void Any::set_value(const void* value,
|
||||
size_t size) {
|
||||
|
||||
value_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
::std::string(reinterpret_cast<const char*>(value), size));
|
||||
value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
|
||||
reinterpret_cast<const char*>(value), size), GetArena());
|
||||
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Any.value)
|
||||
}
|
||||
inline std::string* Any::_internal_mutable_value() {
|
||||
|
||||
return value_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return value_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline std::string* Any::release_value() {
|
||||
// @@protoc_insertion_point(field_release:google.protobuf.Any.value)
|
||||
|
||||
return value_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return value_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline void Any::set_allocated_value(std::string* value) {
|
||||
if (value != nullptr) {
|
||||
@ -378,9 +429,29 @@ inline void Any::set_allocated_value(std::string* value) {
|
||||
} else {
|
||||
|
||||
}
|
||||
value_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
|
||||
value_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value,
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.value)
|
||||
}
|
||||
inline std::string* Any::unsafe_arena_release_value() {
|
||||
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Any.value)
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
|
||||
return value_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArena());
|
||||
}
|
||||
inline void Any::unsafe_arena_set_allocated_value(
|
||||
std::string* value) {
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
if (value != nullptr) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
value_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
value, GetArena());
|
||||
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Any.value)
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
|
@ -159,9 +159,8 @@ static ::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase*const descriptor_table_goo
|
||||
&scc_info_Mixin_google_2fprotobuf_2fapi_2eproto.base,
|
||||
};
|
||||
static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_google_2fprotobuf_2fapi_2eproto_once;
|
||||
static bool descriptor_table_google_2fprotobuf_2fapi_2eproto_initialized = false;
|
||||
const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fapi_2eproto = {
|
||||
&descriptor_table_google_2fprotobuf_2fapi_2eproto_initialized, descriptor_table_protodef_google_2fprotobuf_2fapi_2eproto, "google/protobuf/api.proto", 750,
|
||||
false, false, descriptor_table_protodef_google_2fprotobuf_2fapi_2eproto, "google/protobuf/api.proto", 750,
|
||||
&descriptor_table_google_2fprotobuf_2fapi_2eproto_once, descriptor_table_google_2fprotobuf_2fapi_2eproto_sccs, descriptor_table_google_2fprotobuf_2fapi_2eproto_deps, 3, 2,
|
||||
schemas, file_default_instances, TableStruct_google_2fprotobuf_2fapi_2eproto::offsets,
|
||||
file_level_metadata_google_2fprotobuf_2fapi_2eproto, 3, file_level_enum_descriptors_google_2fprotobuf_2fapi_2eproto, file_level_service_descriptors_google_2fprotobuf_2fapi_2eproto,
|
||||
@ -190,30 +189,35 @@ void Api::clear_options() {
|
||||
options_.Clear();
|
||||
}
|
||||
void Api::clear_source_context() {
|
||||
if (GetArenaNoVirtual() == nullptr && source_context_ != nullptr) {
|
||||
if (GetArena() == nullptr && source_context_ != nullptr) {
|
||||
delete source_context_;
|
||||
}
|
||||
source_context_ = nullptr;
|
||||
}
|
||||
Api::Api()
|
||||
: ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) {
|
||||
Api::Api(::PROTOBUF_NAMESPACE_ID::Arena* arena)
|
||||
: ::PROTOBUF_NAMESPACE_ID::Message(arena),
|
||||
methods_(arena),
|
||||
options_(arena),
|
||||
mixins_(arena) {
|
||||
SharedCtor();
|
||||
// @@protoc_insertion_point(constructor:google.protobuf.Api)
|
||||
RegisterArenaDtor(arena);
|
||||
// @@protoc_insertion_point(arena_constructor:google.protobuf.Api)
|
||||
}
|
||||
Api::Api(const Api& from)
|
||||
: ::PROTOBUF_NAMESPACE_ID::Message(),
|
||||
_internal_metadata_(nullptr),
|
||||
methods_(from.methods_),
|
||||
options_(from.options_),
|
||||
mixins_(from.mixins_) {
|
||||
_internal_metadata_.MergeFrom(from._internal_metadata_);
|
||||
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
|
||||
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
if (!from._internal_name().empty()) {
|
||||
name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_);
|
||||
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_name(),
|
||||
GetArena());
|
||||
}
|
||||
version_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
if (!from._internal_version().empty()) {
|
||||
version_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.version_);
|
||||
version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_version(),
|
||||
GetArena());
|
||||
}
|
||||
if (from._internal_has_source_context()) {
|
||||
source_context_ = new PROTOBUF_NAMESPACE_ID::SourceContext(*from.source_context_);
|
||||
@ -236,14 +240,22 @@ void Api::SharedCtor() {
|
||||
Api::~Api() {
|
||||
// @@protoc_insertion_point(destructor:google.protobuf.Api)
|
||||
SharedDtor();
|
||||
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
|
||||
}
|
||||
|
||||
void Api::SharedDtor() {
|
||||
GOOGLE_DCHECK(GetArena() == nullptr);
|
||||
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
version_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
if (this != internal_default_instance()) delete source_context_;
|
||||
}
|
||||
|
||||
void Api::ArenaDtor(void* object) {
|
||||
Api* _this = reinterpret_cast< Api* >(object);
|
||||
(void)_this;
|
||||
}
|
||||
void Api::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
|
||||
}
|
||||
void Api::SetCachedSize(int size) const {
|
||||
_cached_size_.Set(size);
|
||||
}
|
||||
@ -262,18 +274,19 @@ void Api::Clear() {
|
||||
methods_.Clear();
|
||||
options_.Clear();
|
||||
mixins_.Clear();
|
||||
name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
version_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
if (GetArenaNoVirtual() == nullptr && source_context_ != nullptr) {
|
||||
name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
version_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
if (GetArena() == nullptr && source_context_ != nullptr) {
|
||||
delete source_context_;
|
||||
}
|
||||
source_context_ = nullptr;
|
||||
syntax_ = 0;
|
||||
_internal_metadata_.Clear();
|
||||
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
|
||||
}
|
||||
|
||||
const char* Api::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
|
||||
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
|
||||
::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena;
|
||||
while (!ctx->Done(&ptr)) {
|
||||
::PROTOBUF_NAMESPACE_ID::uint32 tag;
|
||||
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
|
||||
@ -354,7 +367,9 @@ const char* Api::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::intern
|
||||
ctx->SetLastTag(tag);
|
||||
goto success;
|
||||
}
|
||||
ptr = UnknownFieldParse(tag, &_internal_metadata_, ptr, ctx);
|
||||
ptr = UnknownFieldParse(tag,
|
||||
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
|
||||
ptr, ctx);
|
||||
CHK_(ptr != nullptr);
|
||||
continue;
|
||||
}
|
||||
@ -435,7 +450,7 @@ failure:
|
||||
|
||||
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
|
||||
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
|
||||
_internal_metadata_.unknown_fields(), target, stream);
|
||||
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
|
||||
}
|
||||
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Api)
|
||||
return target;
|
||||
@ -524,7 +539,7 @@ void Api::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) {
|
||||
void Api::MergeFrom(const Api& from) {
|
||||
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Api)
|
||||
GOOGLE_DCHECK_NE(&from, this);
|
||||
_internal_metadata_.MergeFrom(from._internal_metadata_);
|
||||
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
|
||||
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
|
||||
(void) cached_has_bits;
|
||||
|
||||
@ -532,12 +547,10 @@ void Api::MergeFrom(const Api& from) {
|
||||
options_.MergeFrom(from.options_);
|
||||
mixins_.MergeFrom(from.mixins_);
|
||||
if (from.name().size() > 0) {
|
||||
|
||||
name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_);
|
||||
_internal_set_name(from._internal_name());
|
||||
}
|
||||
if (from.version().size() > 0) {
|
||||
|
||||
version_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.version_);
|
||||
_internal_set_version(from._internal_version());
|
||||
}
|
||||
if (from.has_source_context()) {
|
||||
_internal_mutable_source_context()->PROTOBUF_NAMESPACE_ID::SourceContext::MergeFrom(from._internal_source_context());
|
||||
@ -567,16 +580,18 @@ bool Api::IsInitialized() const {
|
||||
|
||||
void Api::InternalSwap(Api* other) {
|
||||
using std::swap;
|
||||
_internal_metadata_.Swap(&other->_internal_metadata_);
|
||||
_internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_);
|
||||
methods_.InternalSwap(&other->methods_);
|
||||
options_.InternalSwap(&other->options_);
|
||||
mixins_.InternalSwap(&other->mixins_);
|
||||
name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArenaNoVirtual());
|
||||
version_.Swap(&other->version_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArenaNoVirtual());
|
||||
swap(source_context_, other->source_context_);
|
||||
swap(syntax_, other->syntax_);
|
||||
name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
version_.Swap(&other->version_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
::PROTOBUF_NAMESPACE_ID::internal::memswap<
|
||||
PROTOBUF_FIELD_OFFSET(Api, syntax_)
|
||||
+ sizeof(Api::syntax_)
|
||||
- PROTOBUF_FIELD_OFFSET(Api, source_context_)>(
|
||||
reinterpret_cast<char*>(&source_context_),
|
||||
reinterpret_cast<char*>(&other->source_context_));
|
||||
}
|
||||
|
||||
::PROTOBUF_NAMESPACE_ID::Metadata Api::GetMetadata() const {
|
||||
@ -595,27 +610,31 @@ class Method::_Internal {
|
||||
void Method::clear_options() {
|
||||
options_.Clear();
|
||||
}
|
||||
Method::Method()
|
||||
: ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) {
|
||||
Method::Method(::PROTOBUF_NAMESPACE_ID::Arena* arena)
|
||||
: ::PROTOBUF_NAMESPACE_ID::Message(arena),
|
||||
options_(arena) {
|
||||
SharedCtor();
|
||||
// @@protoc_insertion_point(constructor:google.protobuf.Method)
|
||||
RegisterArenaDtor(arena);
|
||||
// @@protoc_insertion_point(arena_constructor:google.protobuf.Method)
|
||||
}
|
||||
Method::Method(const Method& from)
|
||||
: ::PROTOBUF_NAMESPACE_ID::Message(),
|
||||
_internal_metadata_(nullptr),
|
||||
options_(from.options_) {
|
||||
_internal_metadata_.MergeFrom(from._internal_metadata_);
|
||||
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
|
||||
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
if (!from._internal_name().empty()) {
|
||||
name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_);
|
||||
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_name(),
|
||||
GetArena());
|
||||
}
|
||||
request_type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
if (!from._internal_request_type_url().empty()) {
|
||||
request_type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.request_type_url_);
|
||||
request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_request_type_url(),
|
||||
GetArena());
|
||||
}
|
||||
response_type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
if (!from._internal_response_type_url().empty()) {
|
||||
response_type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.response_type_url_);
|
||||
response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_response_type_url(),
|
||||
GetArena());
|
||||
}
|
||||
::memcpy(&request_streaming_, &from.request_streaming_,
|
||||
static_cast<size_t>(reinterpret_cast<char*>(&syntax_) -
|
||||
@ -636,14 +655,22 @@ void Method::SharedCtor() {
|
||||
Method::~Method() {
|
||||
// @@protoc_insertion_point(destructor:google.protobuf.Method)
|
||||
SharedDtor();
|
||||
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
|
||||
}
|
||||
|
||||
void Method::SharedDtor() {
|
||||
GOOGLE_DCHECK(GetArena() == nullptr);
|
||||
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
request_type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
response_type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
}
|
||||
|
||||
void Method::ArenaDtor(void* object) {
|
||||
Method* _this = reinterpret_cast< Method* >(object);
|
||||
(void)_this;
|
||||
}
|
||||
void Method::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
|
||||
}
|
||||
void Method::SetCachedSize(int size) const {
|
||||
_cached_size_.Set(size);
|
||||
}
|
||||
@ -660,17 +687,18 @@ void Method::Clear() {
|
||||
(void) cached_has_bits;
|
||||
|
||||
options_.Clear();
|
||||
name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
request_type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
response_type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
request_type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
response_type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
::memset(&request_streaming_, 0, static_cast<size_t>(
|
||||
reinterpret_cast<char*>(&syntax_) -
|
||||
reinterpret_cast<char*>(&request_streaming_)) + sizeof(syntax_));
|
||||
_internal_metadata_.Clear();
|
||||
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
|
||||
}
|
||||
|
||||
const char* Method::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
|
||||
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
|
||||
::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena;
|
||||
while (!ctx->Done(&ptr)) {
|
||||
::PROTOBUF_NAMESPACE_ID::uint32 tag;
|
||||
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
|
||||
@ -743,7 +771,9 @@ const char* Method::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::int
|
||||
ctx->SetLastTag(tag);
|
||||
goto success;
|
||||
}
|
||||
ptr = UnknownFieldParse(tag, &_internal_metadata_, ptr, ctx);
|
||||
ptr = UnknownFieldParse(tag,
|
||||
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
|
||||
ptr, ctx);
|
||||
CHK_(ptr != nullptr);
|
||||
continue;
|
||||
}
|
||||
@ -822,7 +852,7 @@ failure:
|
||||
|
||||
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
|
||||
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
|
||||
_internal_metadata_.unknown_fields(), target, stream);
|
||||
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
|
||||
}
|
||||
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Method)
|
||||
return target;
|
||||
@ -907,22 +937,19 @@ void Method::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) {
|
||||
void Method::MergeFrom(const Method& from) {
|
||||
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Method)
|
||||
GOOGLE_DCHECK_NE(&from, this);
|
||||
_internal_metadata_.MergeFrom(from._internal_metadata_);
|
||||
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
|
||||
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
|
||||
(void) cached_has_bits;
|
||||
|
||||
options_.MergeFrom(from.options_);
|
||||
if (from.name().size() > 0) {
|
||||
|
||||
name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_);
|
||||
_internal_set_name(from._internal_name());
|
||||
}
|
||||
if (from.request_type_url().size() > 0) {
|
||||
|
||||
request_type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.request_type_url_);
|
||||
_internal_set_request_type_url(from._internal_request_type_url());
|
||||
}
|
||||
if (from.response_type_url().size() > 0) {
|
||||
|
||||
response_type_url_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.response_type_url_);
|
||||
_internal_set_response_type_url(from._internal_response_type_url());
|
||||
}
|
||||
if (from.request_streaming() != 0) {
|
||||
_internal_set_request_streaming(from._internal_request_streaming());
|
||||
@ -955,17 +982,17 @@ bool Method::IsInitialized() const {
|
||||
|
||||
void Method::InternalSwap(Method* other) {
|
||||
using std::swap;
|
||||
_internal_metadata_.Swap(&other->_internal_metadata_);
|
||||
_internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_);
|
||||
options_.InternalSwap(&other->options_);
|
||||
name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArenaNoVirtual());
|
||||
request_type_url_.Swap(&other->request_type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArenaNoVirtual());
|
||||
response_type_url_.Swap(&other->response_type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArenaNoVirtual());
|
||||
swap(request_streaming_, other->request_streaming_);
|
||||
swap(response_streaming_, other->response_streaming_);
|
||||
swap(syntax_, other->syntax_);
|
||||
name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
request_type_url_.Swap(&other->request_type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
response_type_url_.Swap(&other->response_type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
::PROTOBUF_NAMESPACE_ID::internal::memswap<
|
||||
PROTOBUF_FIELD_OFFSET(Method, syntax_)
|
||||
+ sizeof(Method::syntax_)
|
||||
- PROTOBUF_FIELD_OFFSET(Method, request_streaming_)>(
|
||||
reinterpret_cast<char*>(&request_streaming_),
|
||||
reinterpret_cast<char*>(&other->request_streaming_));
|
||||
}
|
||||
|
||||
::PROTOBUF_NAMESPACE_ID::Metadata Method::GetMetadata() const {
|
||||
@ -981,22 +1008,24 @@ class Mixin::_Internal {
|
||||
public:
|
||||
};
|
||||
|
||||
Mixin::Mixin()
|
||||
: ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) {
|
||||
Mixin::Mixin(::PROTOBUF_NAMESPACE_ID::Arena* arena)
|
||||
: ::PROTOBUF_NAMESPACE_ID::Message(arena) {
|
||||
SharedCtor();
|
||||
// @@protoc_insertion_point(constructor:google.protobuf.Mixin)
|
||||
RegisterArenaDtor(arena);
|
||||
// @@protoc_insertion_point(arena_constructor:google.protobuf.Mixin)
|
||||
}
|
||||
Mixin::Mixin(const Mixin& from)
|
||||
: ::PROTOBUF_NAMESPACE_ID::Message(),
|
||||
_internal_metadata_(nullptr) {
|
||||
_internal_metadata_.MergeFrom(from._internal_metadata_);
|
||||
: ::PROTOBUF_NAMESPACE_ID::Message() {
|
||||
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
|
||||
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
if (!from._internal_name().empty()) {
|
||||
name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_);
|
||||
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_name(),
|
||||
GetArena());
|
||||
}
|
||||
root_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
if (!from._internal_root().empty()) {
|
||||
root_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.root_);
|
||||
root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_root(),
|
||||
GetArena());
|
||||
}
|
||||
// @@protoc_insertion_point(copy_constructor:google.protobuf.Mixin)
|
||||
}
|
||||
@ -1010,13 +1039,21 @@ void Mixin::SharedCtor() {
|
||||
Mixin::~Mixin() {
|
||||
// @@protoc_insertion_point(destructor:google.protobuf.Mixin)
|
||||
SharedDtor();
|
||||
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
|
||||
}
|
||||
|
||||
void Mixin::SharedDtor() {
|
||||
GOOGLE_DCHECK(GetArena() == nullptr);
|
||||
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
root_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
}
|
||||
|
||||
void Mixin::ArenaDtor(void* object) {
|
||||
Mixin* _this = reinterpret_cast< Mixin* >(object);
|
||||
(void)_this;
|
||||
}
|
||||
void Mixin::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
|
||||
}
|
||||
void Mixin::SetCachedSize(int size) const {
|
||||
_cached_size_.Set(size);
|
||||
}
|
||||
@ -1032,13 +1069,14 @@ void Mixin::Clear() {
|
||||
// Prevent compiler warnings about cached_has_bits being unused
|
||||
(void) cached_has_bits;
|
||||
|
||||
name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
root_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
_internal_metadata_.Clear();
|
||||
name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
root_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
|
||||
}
|
||||
|
||||
const char* Mixin::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
|
||||
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
|
||||
::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena;
|
||||
while (!ctx->Done(&ptr)) {
|
||||
::PROTOBUF_NAMESPACE_ID::uint32 tag;
|
||||
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
|
||||
@ -1068,7 +1106,9 @@ const char* Mixin::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte
|
||||
ctx->SetLastTag(tag);
|
||||
goto success;
|
||||
}
|
||||
ptr = UnknownFieldParse(tag, &_internal_metadata_, ptr, ctx);
|
||||
ptr = UnknownFieldParse(tag,
|
||||
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
|
||||
ptr, ctx);
|
||||
CHK_(ptr != nullptr);
|
||||
continue;
|
||||
}
|
||||
@ -1110,7 +1150,7 @@ failure:
|
||||
|
||||
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
|
||||
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
|
||||
_internal_metadata_.unknown_fields(), target, stream);
|
||||
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
|
||||
}
|
||||
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Mixin)
|
||||
return target;
|
||||
@ -1165,17 +1205,15 @@ void Mixin::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) {
|
||||
void Mixin::MergeFrom(const Mixin& from) {
|
||||
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Mixin)
|
||||
GOOGLE_DCHECK_NE(&from, this);
|
||||
_internal_metadata_.MergeFrom(from._internal_metadata_);
|
||||
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
|
||||
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
|
||||
(void) cached_has_bits;
|
||||
|
||||
if (from.name().size() > 0) {
|
||||
|
||||
name_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.name_);
|
||||
_internal_set_name(from._internal_name());
|
||||
}
|
||||
if (from.root().size() > 0) {
|
||||
|
||||
root_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.root_);
|
||||
_internal_set_root(from._internal_root());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1199,11 +1237,9 @@ bool Mixin::IsInitialized() const {
|
||||
|
||||
void Mixin::InternalSwap(Mixin* other) {
|
||||
using std::swap;
|
||||
_internal_metadata_.Swap(&other->_internal_metadata_);
|
||||
name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArenaNoVirtual());
|
||||
root_.Swap(&other->root_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArenaNoVirtual());
|
||||
_internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_);
|
||||
name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
root_.Swap(&other->root_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
|
||||
::PROTOBUF_NAMESPACE_ID::Metadata Mixin::GetMetadata() const {
|
||||
@ -1215,13 +1251,13 @@ void Mixin::InternalSwap(Mixin* other) {
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
template<> PROTOBUF_NOINLINE PROTOBUF_NAMESPACE_ID::Api* Arena::CreateMaybeMessage< PROTOBUF_NAMESPACE_ID::Api >(Arena* arena) {
|
||||
return Arena::CreateInternal< PROTOBUF_NAMESPACE_ID::Api >(arena);
|
||||
return Arena::CreateMessageInternal< PROTOBUF_NAMESPACE_ID::Api >(arena);
|
||||
}
|
||||
template<> PROTOBUF_NOINLINE PROTOBUF_NAMESPACE_ID::Method* Arena::CreateMaybeMessage< PROTOBUF_NAMESPACE_ID::Method >(Arena* arena) {
|
||||
return Arena::CreateInternal< PROTOBUF_NAMESPACE_ID::Method >(arena);
|
||||
return Arena::CreateMessageInternal< PROTOBUF_NAMESPACE_ID::Method >(arena);
|
||||
}
|
||||
template<> PROTOBUF_NOINLINE PROTOBUF_NAMESPACE_ID::Mixin* Arena::CreateMaybeMessage< PROTOBUF_NAMESPACE_ID::Mixin >(Arena* arena) {
|
||||
return Arena::CreateInternal< PROTOBUF_NAMESPACE_ID::Mixin >(arena);
|
||||
return Arena::CreateMessageInternal< PROTOBUF_NAMESPACE_ID::Mixin >(arena);
|
||||
}
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include <google/protobuf/generated_message_table_driven.h>
|
||||
#include <google/protobuf/generated_message_util.h>
|
||||
#include <google/protobuf/inlined_string_field.h>
|
||||
#include <google/protobuf/metadata.h>
|
||||
#include <google/protobuf/metadata_lite.h>
|
||||
#include <google/protobuf/generated_message_reflection.h>
|
||||
#include <google/protobuf/message.h>
|
||||
#include <google/protobuf/repeated_field.h> // IWYU pragma: export
|
||||
@ -76,10 +76,10 @@ PROTOBUF_NAMESPACE_OPEN
|
||||
|
||||
// ===================================================================
|
||||
|
||||
class PROTOBUF_EXPORT Api :
|
||||
class PROTOBUF_EXPORT Api PROTOBUF_FINAL :
|
||||
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Api) */ {
|
||||
public:
|
||||
Api();
|
||||
inline Api() : Api(nullptr) {};
|
||||
virtual ~Api();
|
||||
|
||||
Api(const Api& from);
|
||||
@ -93,7 +93,7 @@ class PROTOBUF_EXPORT Api :
|
||||
return *this;
|
||||
}
|
||||
inline Api& operator=(Api&& from) noexcept {
|
||||
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
|
||||
if (GetArena() == from.GetArena()) {
|
||||
if (this != &from) InternalSwap(&from);
|
||||
} else {
|
||||
CopyFrom(from);
|
||||
@ -125,6 +125,15 @@ class PROTOBUF_EXPORT Api :
|
||||
}
|
||||
inline void Swap(Api* other) {
|
||||
if (other == this) return;
|
||||
if (GetArena() == other->GetArena()) {
|
||||
InternalSwap(other);
|
||||
} else {
|
||||
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
|
||||
}
|
||||
}
|
||||
void UnsafeArenaSwap(Api* other) {
|
||||
if (other == this) return;
|
||||
GOOGLE_DCHECK(GetArena() == other->GetArena());
|
||||
InternalSwap(other);
|
||||
}
|
||||
|
||||
@ -159,13 +168,11 @@ class PROTOBUF_EXPORT Api :
|
||||
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
|
||||
return "google.protobuf.Api";
|
||||
}
|
||||
protected:
|
||||
explicit Api(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
private:
|
||||
inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const {
|
||||
return nullptr;
|
||||
}
|
||||
inline void* MaybeArenaPtr() const {
|
||||
return nullptr;
|
||||
}
|
||||
static void ArenaDtor(void* object);
|
||||
inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
public:
|
||||
|
||||
::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;
|
||||
@ -254,6 +261,15 @@ class PROTOBUF_EXPORT Api :
|
||||
std::string* mutable_name();
|
||||
std::string* release_name();
|
||||
void set_allocated_name(std::string* name);
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
std::string* unsafe_arena_release_name();
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
void unsafe_arena_set_allocated_name(
|
||||
std::string* name);
|
||||
private:
|
||||
const std::string& _internal_name() const;
|
||||
void _internal_set_name(const std::string& value);
|
||||
@ -270,6 +286,15 @@ class PROTOBUF_EXPORT Api :
|
||||
std::string* mutable_version();
|
||||
std::string* release_version();
|
||||
void set_allocated_version(std::string* version);
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
std::string* unsafe_arena_release_version();
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
void unsafe_arena_set_allocated_version(
|
||||
std::string* version);
|
||||
private:
|
||||
const std::string& _internal_version() const;
|
||||
void _internal_set_version(const std::string& value);
|
||||
@ -290,6 +315,9 @@ class PROTOBUF_EXPORT Api :
|
||||
const PROTOBUF_NAMESPACE_ID::SourceContext& _internal_source_context() const;
|
||||
PROTOBUF_NAMESPACE_ID::SourceContext* _internal_mutable_source_context();
|
||||
public:
|
||||
void unsafe_arena_set_allocated_source_context(
|
||||
PROTOBUF_NAMESPACE_ID::SourceContext* source_context);
|
||||
PROTOBUF_NAMESPACE_ID::SourceContext* unsafe_arena_release_source_context();
|
||||
|
||||
// .google.protobuf.Syntax syntax = 7;
|
||||
void clear_syntax();
|
||||
@ -304,7 +332,9 @@ class PROTOBUF_EXPORT Api :
|
||||
private:
|
||||
class _Internal;
|
||||
|
||||
::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_;
|
||||
template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
|
||||
typedef void InternalArenaConstructable_;
|
||||
typedef void DestructorSkippable_;
|
||||
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Method > methods_;
|
||||
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Option > options_;
|
||||
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Mixin > mixins_;
|
||||
@ -317,10 +347,10 @@ class PROTOBUF_EXPORT Api :
|
||||
};
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
class PROTOBUF_EXPORT Method :
|
||||
class PROTOBUF_EXPORT Method PROTOBUF_FINAL :
|
||||
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Method) */ {
|
||||
public:
|
||||
Method();
|
||||
inline Method() : Method(nullptr) {};
|
||||
virtual ~Method();
|
||||
|
||||
Method(const Method& from);
|
||||
@ -334,7 +364,7 @@ class PROTOBUF_EXPORT Method :
|
||||
return *this;
|
||||
}
|
||||
inline Method& operator=(Method&& from) noexcept {
|
||||
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
|
||||
if (GetArena() == from.GetArena()) {
|
||||
if (this != &from) InternalSwap(&from);
|
||||
} else {
|
||||
CopyFrom(from);
|
||||
@ -366,6 +396,15 @@ class PROTOBUF_EXPORT Method :
|
||||
}
|
||||
inline void Swap(Method* other) {
|
||||
if (other == this) return;
|
||||
if (GetArena() == other->GetArena()) {
|
||||
InternalSwap(other);
|
||||
} else {
|
||||
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
|
||||
}
|
||||
}
|
||||
void UnsafeArenaSwap(Method* other) {
|
||||
if (other == this) return;
|
||||
GOOGLE_DCHECK(GetArena() == other->GetArena());
|
||||
InternalSwap(other);
|
||||
}
|
||||
|
||||
@ -400,13 +439,11 @@ class PROTOBUF_EXPORT Method :
|
||||
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
|
||||
return "google.protobuf.Method";
|
||||
}
|
||||
protected:
|
||||
explicit Method(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
private:
|
||||
inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const {
|
||||
return nullptr;
|
||||
}
|
||||
inline void* MaybeArenaPtr() const {
|
||||
return nullptr;
|
||||
}
|
||||
static void ArenaDtor(void* object);
|
||||
inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
public:
|
||||
|
||||
::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;
|
||||
@ -459,6 +496,15 @@ class PROTOBUF_EXPORT Method :
|
||||
std::string* mutable_name();
|
||||
std::string* release_name();
|
||||
void set_allocated_name(std::string* name);
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
std::string* unsafe_arena_release_name();
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
void unsafe_arena_set_allocated_name(
|
||||
std::string* name);
|
||||
private:
|
||||
const std::string& _internal_name() const;
|
||||
void _internal_set_name(const std::string& value);
|
||||
@ -475,6 +521,15 @@ class PROTOBUF_EXPORT Method :
|
||||
std::string* mutable_request_type_url();
|
||||
std::string* release_request_type_url();
|
||||
void set_allocated_request_type_url(std::string* request_type_url);
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
std::string* unsafe_arena_release_request_type_url();
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
void unsafe_arena_set_allocated_request_type_url(
|
||||
std::string* request_type_url);
|
||||
private:
|
||||
const std::string& _internal_request_type_url() const;
|
||||
void _internal_set_request_type_url(const std::string& value);
|
||||
@ -491,6 +546,15 @@ class PROTOBUF_EXPORT Method :
|
||||
std::string* mutable_response_type_url();
|
||||
std::string* release_response_type_url();
|
||||
void set_allocated_response_type_url(std::string* response_type_url);
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
std::string* unsafe_arena_release_response_type_url();
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
void unsafe_arena_set_allocated_response_type_url(
|
||||
std::string* response_type_url);
|
||||
private:
|
||||
const std::string& _internal_response_type_url() const;
|
||||
void _internal_set_response_type_url(const std::string& value);
|
||||
@ -528,7 +592,9 @@ class PROTOBUF_EXPORT Method :
|
||||
private:
|
||||
class _Internal;
|
||||
|
||||
::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_;
|
||||
template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
|
||||
typedef void InternalArenaConstructable_;
|
||||
typedef void DestructorSkippable_;
|
||||
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Option > options_;
|
||||
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_;
|
||||
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr request_type_url_;
|
||||
@ -541,10 +607,10 @@ class PROTOBUF_EXPORT Method :
|
||||
};
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
class PROTOBUF_EXPORT Mixin :
|
||||
class PROTOBUF_EXPORT Mixin PROTOBUF_FINAL :
|
||||
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Mixin) */ {
|
||||
public:
|
||||
Mixin();
|
||||
inline Mixin() : Mixin(nullptr) {};
|
||||
virtual ~Mixin();
|
||||
|
||||
Mixin(const Mixin& from);
|
||||
@ -558,7 +624,7 @@ class PROTOBUF_EXPORT Mixin :
|
||||
return *this;
|
||||
}
|
||||
inline Mixin& operator=(Mixin&& from) noexcept {
|
||||
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
|
||||
if (GetArena() == from.GetArena()) {
|
||||
if (this != &from) InternalSwap(&from);
|
||||
} else {
|
||||
CopyFrom(from);
|
||||
@ -590,6 +656,15 @@ class PROTOBUF_EXPORT Mixin :
|
||||
}
|
||||
inline void Swap(Mixin* other) {
|
||||
if (other == this) return;
|
||||
if (GetArena() == other->GetArena()) {
|
||||
InternalSwap(other);
|
||||
} else {
|
||||
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
|
||||
}
|
||||
}
|
||||
void UnsafeArenaSwap(Mixin* other) {
|
||||
if (other == this) return;
|
||||
GOOGLE_DCHECK(GetArena() == other->GetArena());
|
||||
InternalSwap(other);
|
||||
}
|
||||
|
||||
@ -624,13 +699,11 @@ class PROTOBUF_EXPORT Mixin :
|
||||
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
|
||||
return "google.protobuf.Mixin";
|
||||
}
|
||||
protected:
|
||||
explicit Mixin(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
private:
|
||||
inline ::PROTOBUF_NAMESPACE_ID::Arena* GetArenaNoVirtual() const {
|
||||
return nullptr;
|
||||
}
|
||||
inline void* MaybeArenaPtr() const {
|
||||
return nullptr;
|
||||
}
|
||||
static void ArenaDtor(void* object);
|
||||
inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
public:
|
||||
|
||||
::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;
|
||||
@ -660,6 +733,15 @@ class PROTOBUF_EXPORT Mixin :
|
||||
std::string* mutable_name();
|
||||
std::string* release_name();
|
||||
void set_allocated_name(std::string* name);
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
std::string* unsafe_arena_release_name();
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
void unsafe_arena_set_allocated_name(
|
||||
std::string* name);
|
||||
private:
|
||||
const std::string& _internal_name() const;
|
||||
void _internal_set_name(const std::string& value);
|
||||
@ -676,6 +758,15 @@ class PROTOBUF_EXPORT Mixin :
|
||||
std::string* mutable_root();
|
||||
std::string* release_root();
|
||||
void set_allocated_root(std::string* root);
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
std::string* unsafe_arena_release_root();
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
void unsafe_arena_set_allocated_root(
|
||||
std::string* root);
|
||||
private:
|
||||
const std::string& _internal_root() const;
|
||||
void _internal_set_root(const std::string& value);
|
||||
@ -686,7 +777,9 @@ class PROTOBUF_EXPORT Mixin :
|
||||
private:
|
||||
class _Internal;
|
||||
|
||||
::PROTOBUF_NAMESPACE_ID::internal::InternalMetadataWithArena _internal_metadata_;
|
||||
template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
|
||||
typedef void InternalArenaConstructable_;
|
||||
typedef void DestructorSkippable_;
|
||||
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_;
|
||||
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr root_;
|
||||
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
|
||||
@ -705,7 +798,7 @@ class PROTOBUF_EXPORT Mixin :
|
||||
|
||||
// string name = 1;
|
||||
inline void Api::clear_name() {
|
||||
name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline const std::string& Api::name() const {
|
||||
// @@protoc_insertion_point(field_get:google.protobuf.Api.name)
|
||||
@ -720,38 +813,40 @@ inline std::string* Api::mutable_name() {
|
||||
return _internal_mutable_name();
|
||||
}
|
||||
inline const std::string& Api::_internal_name() const {
|
||||
return name_.GetNoArena();
|
||||
return name_.Get();
|
||||
}
|
||||
inline void Api::_internal_set_name(const std::string& value) {
|
||||
|
||||
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
|
||||
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
|
||||
}
|
||||
inline void Api::set_name(std::string&& value) {
|
||||
|
||||
name_.SetNoArena(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
|
||||
name_.Set(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
|
||||
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Api.name)
|
||||
}
|
||||
inline void Api::set_name(const char* value) {
|
||||
GOOGLE_DCHECK(value != nullptr);
|
||||
|
||||
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
|
||||
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_char:google.protobuf.Api.name)
|
||||
}
|
||||
inline void Api::set_name(const char* value, size_t size) {
|
||||
inline void Api::set_name(const char* value,
|
||||
size_t size) {
|
||||
|
||||
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
::std::string(reinterpret_cast<const char*>(value), size));
|
||||
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
|
||||
reinterpret_cast<const char*>(value), size), GetArena());
|
||||
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Api.name)
|
||||
}
|
||||
inline std::string* Api::_internal_mutable_name() {
|
||||
|
||||
return name_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return name_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline std::string* Api::release_name() {
|
||||
// @@protoc_insertion_point(field_release:google.protobuf.Api.name)
|
||||
|
||||
return name_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline void Api::set_allocated_name(std::string* name) {
|
||||
if (name != nullptr) {
|
||||
@ -759,9 +854,29 @@ inline void Api::set_allocated_name(std::string* name) {
|
||||
} else {
|
||||
|
||||
}
|
||||
name_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name);
|
||||
name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name,
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.name)
|
||||
}
|
||||
inline std::string* Api::unsafe_arena_release_name() {
|
||||
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Api.name)
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
|
||||
return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArena());
|
||||
}
|
||||
inline void Api::unsafe_arena_set_allocated_name(
|
||||
std::string* name) {
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
if (name != nullptr) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
name, GetArena());
|
||||
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Api.name)
|
||||
}
|
||||
|
||||
// repeated .google.protobuf.Method methods = 2;
|
||||
inline int Api::_internal_methods_size() const {
|
||||
@ -840,7 +955,7 @@ Api::options() const {
|
||||
|
||||
// string version = 4;
|
||||
inline void Api::clear_version() {
|
||||
version_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
version_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline const std::string& Api::version() const {
|
||||
// @@protoc_insertion_point(field_get:google.protobuf.Api.version)
|
||||
@ -855,38 +970,40 @@ inline std::string* Api::mutable_version() {
|
||||
return _internal_mutable_version();
|
||||
}
|
||||
inline const std::string& Api::_internal_version() const {
|
||||
return version_.GetNoArena();
|
||||
return version_.Get();
|
||||
}
|
||||
inline void Api::_internal_set_version(const std::string& value) {
|
||||
|
||||
version_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
|
||||
version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
|
||||
}
|
||||
inline void Api::set_version(std::string&& value) {
|
||||
|
||||
version_.SetNoArena(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
|
||||
version_.Set(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
|
||||
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Api.version)
|
||||
}
|
||||
inline void Api::set_version(const char* value) {
|
||||
GOOGLE_DCHECK(value != nullptr);
|
||||
|
||||
version_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
|
||||
version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_char:google.protobuf.Api.version)
|
||||
}
|
||||
inline void Api::set_version(const char* value, size_t size) {
|
||||
inline void Api::set_version(const char* value,
|
||||
size_t size) {
|
||||
|
||||
version_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
::std::string(reinterpret_cast<const char*>(value), size));
|
||||
version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
|
||||
reinterpret_cast<const char*>(value), size), GetArena());
|
||||
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Api.version)
|
||||
}
|
||||
inline std::string* Api::_internal_mutable_version() {
|
||||
|
||||
return version_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return version_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline std::string* Api::release_version() {
|
||||
// @@protoc_insertion_point(field_release:google.protobuf.Api.version)
|
||||
|
||||
return version_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return version_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline void Api::set_allocated_version(std::string* version) {
|
||||
if (version != nullptr) {
|
||||
@ -894,9 +1011,29 @@ inline void Api::set_allocated_version(std::string* version) {
|
||||
} else {
|
||||
|
||||
}
|
||||
version_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), version);
|
||||
version_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), version,
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.version)
|
||||
}
|
||||
inline std::string* Api::unsafe_arena_release_version() {
|
||||
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Api.version)
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
|
||||
return version_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArena());
|
||||
}
|
||||
inline void Api::unsafe_arena_set_allocated_version(
|
||||
std::string* version) {
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
if (version != nullptr) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
version_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
version, GetArena());
|
||||
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Api.version)
|
||||
}
|
||||
|
||||
// .google.protobuf.SourceContext source_context = 5;
|
||||
inline bool Api::_internal_has_source_context() const {
|
||||
@ -914,7 +1051,27 @@ inline const PROTOBUF_NAMESPACE_ID::SourceContext& Api::source_context() const {
|
||||
// @@protoc_insertion_point(field_get:google.protobuf.Api.source_context)
|
||||
return _internal_source_context();
|
||||
}
|
||||
inline void Api::unsafe_arena_set_allocated_source_context(
|
||||
PROTOBUF_NAMESPACE_ID::SourceContext* source_context) {
|
||||
if (GetArena() == nullptr) {
|
||||
delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context_);
|
||||
}
|
||||
source_context_ = source_context;
|
||||
if (source_context) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Api.source_context)
|
||||
}
|
||||
inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::release_source_context() {
|
||||
auto temp = unsafe_arena_release_source_context();
|
||||
if (GetArena() != nullptr) {
|
||||
temp = ::PROTOBUF_NAMESPACE_ID::internal::DuplicateIfNonNull(temp);
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::unsafe_arena_release_source_context() {
|
||||
// @@protoc_insertion_point(field_release:google.protobuf.Api.source_context)
|
||||
|
||||
PROTOBUF_NAMESPACE_ID::SourceContext* temp = source_context_;
|
||||
@ -924,7 +1081,7 @@ inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::release_source_context() {
|
||||
inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::_internal_mutable_source_context() {
|
||||
|
||||
if (source_context_ == nullptr) {
|
||||
auto* p = CreateMaybeMessage<PROTOBUF_NAMESPACE_ID::SourceContext>(GetArenaNoVirtual());
|
||||
auto* p = CreateMaybeMessage<PROTOBUF_NAMESPACE_ID::SourceContext>(GetArena());
|
||||
source_context_ = p;
|
||||
}
|
||||
return source_context_;
|
||||
@ -934,12 +1091,13 @@ inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::mutable_source_context() {
|
||||
return _internal_mutable_source_context();
|
||||
}
|
||||
inline void Api::set_allocated_source_context(PROTOBUF_NAMESPACE_ID::SourceContext* source_context) {
|
||||
::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArenaNoVirtual();
|
||||
::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArena();
|
||||
if (message_arena == nullptr) {
|
||||
delete reinterpret_cast< ::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context_);
|
||||
}
|
||||
if (source_context) {
|
||||
::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena = nullptr;
|
||||
::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena =
|
||||
reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context)->GetArena();
|
||||
if (message_arena != submessage_arena) {
|
||||
source_context = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage(
|
||||
message_arena, source_context, submessage_arena);
|
||||
@ -1017,7 +1175,7 @@ inline void Api::set_syntax(PROTOBUF_NAMESPACE_ID::Syntax value) {
|
||||
|
||||
// string name = 1;
|
||||
inline void Method::clear_name() {
|
||||
name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline const std::string& Method::name() const {
|
||||
// @@protoc_insertion_point(field_get:google.protobuf.Method.name)
|
||||
@ -1032,38 +1190,40 @@ inline std::string* Method::mutable_name() {
|
||||
return _internal_mutable_name();
|
||||
}
|
||||
inline const std::string& Method::_internal_name() const {
|
||||
return name_.GetNoArena();
|
||||
return name_.Get();
|
||||
}
|
||||
inline void Method::_internal_set_name(const std::string& value) {
|
||||
|
||||
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
|
||||
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
|
||||
}
|
||||
inline void Method::set_name(std::string&& value) {
|
||||
|
||||
name_.SetNoArena(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
|
||||
name_.Set(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
|
||||
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.name)
|
||||
}
|
||||
inline void Method::set_name(const char* value) {
|
||||
GOOGLE_DCHECK(value != nullptr);
|
||||
|
||||
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
|
||||
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_char:google.protobuf.Method.name)
|
||||
}
|
||||
inline void Method::set_name(const char* value, size_t size) {
|
||||
inline void Method::set_name(const char* value,
|
||||
size_t size) {
|
||||
|
||||
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
::std::string(reinterpret_cast<const char*>(value), size));
|
||||
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
|
||||
reinterpret_cast<const char*>(value), size), GetArena());
|
||||
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.name)
|
||||
}
|
||||
inline std::string* Method::_internal_mutable_name() {
|
||||
|
||||
return name_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return name_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline std::string* Method::release_name() {
|
||||
// @@protoc_insertion_point(field_release:google.protobuf.Method.name)
|
||||
|
||||
return name_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline void Method::set_allocated_name(std::string* name) {
|
||||
if (name != nullptr) {
|
||||
@ -1071,13 +1231,33 @@ inline void Method::set_allocated_name(std::string* name) {
|
||||
} else {
|
||||
|
||||
}
|
||||
name_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name);
|
||||
name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name,
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.name)
|
||||
}
|
||||
inline std::string* Method::unsafe_arena_release_name() {
|
||||
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Method.name)
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
|
||||
return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArena());
|
||||
}
|
||||
inline void Method::unsafe_arena_set_allocated_name(
|
||||
std::string* name) {
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
if (name != nullptr) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
name, GetArena());
|
||||
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Method.name)
|
||||
}
|
||||
|
||||
// string request_type_url = 2;
|
||||
inline void Method::clear_request_type_url() {
|
||||
request_type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
request_type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline const std::string& Method::request_type_url() const {
|
||||
// @@protoc_insertion_point(field_get:google.protobuf.Method.request_type_url)
|
||||
@ -1092,38 +1272,40 @@ inline std::string* Method::mutable_request_type_url() {
|
||||
return _internal_mutable_request_type_url();
|
||||
}
|
||||
inline const std::string& Method::_internal_request_type_url() const {
|
||||
return request_type_url_.GetNoArena();
|
||||
return request_type_url_.Get();
|
||||
}
|
||||
inline void Method::_internal_set_request_type_url(const std::string& value) {
|
||||
|
||||
request_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
|
||||
request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
|
||||
}
|
||||
inline void Method::set_request_type_url(std::string&& value) {
|
||||
|
||||
request_type_url_.SetNoArena(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
|
||||
request_type_url_.Set(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
|
||||
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.request_type_url)
|
||||
}
|
||||
inline void Method::set_request_type_url(const char* value) {
|
||||
GOOGLE_DCHECK(value != nullptr);
|
||||
|
||||
request_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
|
||||
request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_char:google.protobuf.Method.request_type_url)
|
||||
}
|
||||
inline void Method::set_request_type_url(const char* value, size_t size) {
|
||||
inline void Method::set_request_type_url(const char* value,
|
||||
size_t size) {
|
||||
|
||||
request_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
::std::string(reinterpret_cast<const char*>(value), size));
|
||||
request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
|
||||
reinterpret_cast<const char*>(value), size), GetArena());
|
||||
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.request_type_url)
|
||||
}
|
||||
inline std::string* Method::_internal_mutable_request_type_url() {
|
||||
|
||||
return request_type_url_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return request_type_url_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline std::string* Method::release_request_type_url() {
|
||||
// @@protoc_insertion_point(field_release:google.protobuf.Method.request_type_url)
|
||||
|
||||
return request_type_url_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return request_type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline void Method::set_allocated_request_type_url(std::string* request_type_url) {
|
||||
if (request_type_url != nullptr) {
|
||||
@ -1131,9 +1313,29 @@ inline void Method::set_allocated_request_type_url(std::string* request_type_url
|
||||
} else {
|
||||
|
||||
}
|
||||
request_type_url_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), request_type_url);
|
||||
request_type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), request_type_url,
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.request_type_url)
|
||||
}
|
||||
inline std::string* Method::unsafe_arena_release_request_type_url() {
|
||||
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Method.request_type_url)
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
|
||||
return request_type_url_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArena());
|
||||
}
|
||||
inline void Method::unsafe_arena_set_allocated_request_type_url(
|
||||
std::string* request_type_url) {
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
if (request_type_url != nullptr) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
request_type_url_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
request_type_url, GetArena());
|
||||
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Method.request_type_url)
|
||||
}
|
||||
|
||||
// bool request_streaming = 3;
|
||||
inline void Method::clear_request_streaming() {
|
||||
@ -1157,7 +1359,7 @@ inline void Method::set_request_streaming(bool value) {
|
||||
|
||||
// string response_type_url = 4;
|
||||
inline void Method::clear_response_type_url() {
|
||||
response_type_url_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
response_type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline const std::string& Method::response_type_url() const {
|
||||
// @@protoc_insertion_point(field_get:google.protobuf.Method.response_type_url)
|
||||
@ -1172,38 +1374,40 @@ inline std::string* Method::mutable_response_type_url() {
|
||||
return _internal_mutable_response_type_url();
|
||||
}
|
||||
inline const std::string& Method::_internal_response_type_url() const {
|
||||
return response_type_url_.GetNoArena();
|
||||
return response_type_url_.Get();
|
||||
}
|
||||
inline void Method::_internal_set_response_type_url(const std::string& value) {
|
||||
|
||||
response_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
|
||||
response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
|
||||
}
|
||||
inline void Method::set_response_type_url(std::string&& value) {
|
||||
|
||||
response_type_url_.SetNoArena(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
|
||||
response_type_url_.Set(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
|
||||
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.response_type_url)
|
||||
}
|
||||
inline void Method::set_response_type_url(const char* value) {
|
||||
GOOGLE_DCHECK(value != nullptr);
|
||||
|
||||
response_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
|
||||
response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_char:google.protobuf.Method.response_type_url)
|
||||
}
|
||||
inline void Method::set_response_type_url(const char* value, size_t size) {
|
||||
inline void Method::set_response_type_url(const char* value,
|
||||
size_t size) {
|
||||
|
||||
response_type_url_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
::std::string(reinterpret_cast<const char*>(value), size));
|
||||
response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
|
||||
reinterpret_cast<const char*>(value), size), GetArena());
|
||||
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.response_type_url)
|
||||
}
|
||||
inline std::string* Method::_internal_mutable_response_type_url() {
|
||||
|
||||
return response_type_url_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return response_type_url_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline std::string* Method::release_response_type_url() {
|
||||
// @@protoc_insertion_point(field_release:google.protobuf.Method.response_type_url)
|
||||
|
||||
return response_type_url_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return response_type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline void Method::set_allocated_response_type_url(std::string* response_type_url) {
|
||||
if (response_type_url != nullptr) {
|
||||
@ -1211,9 +1415,29 @@ inline void Method::set_allocated_response_type_url(std::string* response_type_u
|
||||
} else {
|
||||
|
||||
}
|
||||
response_type_url_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), response_type_url);
|
||||
response_type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), response_type_url,
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.response_type_url)
|
||||
}
|
||||
inline std::string* Method::unsafe_arena_release_response_type_url() {
|
||||
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Method.response_type_url)
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
|
||||
return response_type_url_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArena());
|
||||
}
|
||||
inline void Method::unsafe_arena_set_allocated_response_type_url(
|
||||
std::string* response_type_url) {
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
if (response_type_url != nullptr) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
response_type_url_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
response_type_url, GetArena());
|
||||
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Method.response_type_url)
|
||||
}
|
||||
|
||||
// bool response_streaming = 5;
|
||||
inline void Method::clear_response_streaming() {
|
||||
@ -1297,7 +1521,7 @@ inline void Method::set_syntax(PROTOBUF_NAMESPACE_ID::Syntax value) {
|
||||
|
||||
// string name = 1;
|
||||
inline void Mixin::clear_name() {
|
||||
name_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline const std::string& Mixin::name() const {
|
||||
// @@protoc_insertion_point(field_get:google.protobuf.Mixin.name)
|
||||
@ -1312,38 +1536,40 @@ inline std::string* Mixin::mutable_name() {
|
||||
return _internal_mutable_name();
|
||||
}
|
||||
inline const std::string& Mixin::_internal_name() const {
|
||||
return name_.GetNoArena();
|
||||
return name_.Get();
|
||||
}
|
||||
inline void Mixin::_internal_set_name(const std::string& value) {
|
||||
|
||||
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
|
||||
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
|
||||
}
|
||||
inline void Mixin::set_name(std::string&& value) {
|
||||
|
||||
name_.SetNoArena(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
|
||||
name_.Set(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
|
||||
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Mixin.name)
|
||||
}
|
||||
inline void Mixin::set_name(const char* value) {
|
||||
GOOGLE_DCHECK(value != nullptr);
|
||||
|
||||
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
|
||||
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.name)
|
||||
}
|
||||
inline void Mixin::set_name(const char* value, size_t size) {
|
||||
inline void Mixin::set_name(const char* value,
|
||||
size_t size) {
|
||||
|
||||
name_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
::std::string(reinterpret_cast<const char*>(value), size));
|
||||
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
|
||||
reinterpret_cast<const char*>(value), size), GetArena());
|
||||
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Mixin.name)
|
||||
}
|
||||
inline std::string* Mixin::_internal_mutable_name() {
|
||||
|
||||
return name_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return name_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline std::string* Mixin::release_name() {
|
||||
// @@protoc_insertion_point(field_release:google.protobuf.Mixin.name)
|
||||
|
||||
return name_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline void Mixin::set_allocated_name(std::string* name) {
|
||||
if (name != nullptr) {
|
||||
@ -1351,13 +1577,33 @@ inline void Mixin::set_allocated_name(std::string* name) {
|
||||
} else {
|
||||
|
||||
}
|
||||
name_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name);
|
||||
name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name,
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.name)
|
||||
}
|
||||
inline std::string* Mixin::unsafe_arena_release_name() {
|
||||
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Mixin.name)
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
|
||||
return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArena());
|
||||
}
|
||||
inline void Mixin::unsafe_arena_set_allocated_name(
|
||||
std::string* name) {
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
if (name != nullptr) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
name, GetArena());
|
||||
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Mixin.name)
|
||||
}
|
||||
|
||||
// string root = 2;
|
||||
inline void Mixin::clear_root() {
|
||||
root_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
root_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline const std::string& Mixin::root() const {
|
||||
// @@protoc_insertion_point(field_get:google.protobuf.Mixin.root)
|
||||
@ -1372,38 +1618,40 @@ inline std::string* Mixin::mutable_root() {
|
||||
return _internal_mutable_root();
|
||||
}
|
||||
inline const std::string& Mixin::_internal_root() const {
|
||||
return root_.GetNoArena();
|
||||
return root_.Get();
|
||||
}
|
||||
inline void Mixin::_internal_set_root(const std::string& value) {
|
||||
|
||||
root_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value);
|
||||
root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
|
||||
}
|
||||
inline void Mixin::set_root(std::string&& value) {
|
||||
|
||||
root_.SetNoArena(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
|
||||
root_.Set(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
|
||||
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Mixin.root)
|
||||
}
|
||||
inline void Mixin::set_root(const char* value) {
|
||||
GOOGLE_DCHECK(value != nullptr);
|
||||
|
||||
root_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
|
||||
root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.root)
|
||||
}
|
||||
inline void Mixin::set_root(const char* value, size_t size) {
|
||||
inline void Mixin::set_root(const char* value,
|
||||
size_t size) {
|
||||
|
||||
root_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
::std::string(reinterpret_cast<const char*>(value), size));
|
||||
root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
|
||||
reinterpret_cast<const char*>(value), size), GetArena());
|
||||
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Mixin.root)
|
||||
}
|
||||
inline std::string* Mixin::_internal_mutable_root() {
|
||||
|
||||
return root_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return root_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline std::string* Mixin::release_root() {
|
||||
// @@protoc_insertion_point(field_release:google.protobuf.Mixin.root)
|
||||
|
||||
return root_.ReleaseNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
|
||||
return root_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline void Mixin::set_allocated_root(std::string* root) {
|
||||
if (root != nullptr) {
|
||||
@ -1411,9 +1659,29 @@ inline void Mixin::set_allocated_root(std::string* root) {
|
||||
} else {
|
||||
|
||||
}
|
||||
root_.SetAllocatedNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), root);
|
||||
root_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), root,
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.root)
|
||||
}
|
||||
inline std::string* Mixin::unsafe_arena_release_root() {
|
||||
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Mixin.root)
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
|
||||
return root_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArena());
|
||||
}
|
||||
inline void Mixin::unsafe_arena_set_allocated_root(
|
||||
std::string* root) {
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
if (root != nullptr) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
root_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
root, GetArena());
|
||||
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Mixin.root)
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
|
@ -338,10 +338,8 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
|
||||
template <typename T>
|
||||
PROTOBUF_ALWAYS_INLINE static T* CreateArray(Arena* arena,
|
||||
size_t num_elements) {
|
||||
#ifndef __INTEL_COMPILER // icc mis-evaluates some types as non-pod
|
||||
static_assert(std::is_pod<T>::value,
|
||||
"CreateArray requires a trivially constructible type");
|
||||
#endif
|
||||
static_assert(std::is_trivially_destructible<T>::value,
|
||||
"CreateArray requires a trivially destructible type");
|
||||
GOOGLE_CHECK_LE(num_elements, std::numeric_limits<size_t>::max() / sizeof(T))
|
||||
@ -455,7 +453,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
|
||||
return new (ptr) T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
static Arena* GetArena(const T* p) { return p->GetArenaNoVirtual(); }
|
||||
static Arena* GetArena(const T* p) { return p->GetArena(); }
|
||||
|
||||
friend class Arena;
|
||||
};
|
||||
@ -534,6 +532,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
|
||||
// the cookie is not null.
|
||||
template <typename T>
|
||||
PROTOBUF_ALWAYS_INLINE void* AllocateInternal(bool skip_explicit_ownership) {
|
||||
static_assert(alignof(T) <= 8, "T is overaligned, see b/151247138");
|
||||
const size_t n = internal::AlignUpTo8(sizeof(T));
|
||||
AllocHook(RTTI_TYPE_ID(T), n);
|
||||
// Monitor allocation if needed.
|
||||
@ -618,24 +617,25 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
|
||||
// CreateInArenaStorage is used to implement map field. Without it,
|
||||
// Map need to call generated message's protected arena constructor,
|
||||
// which needs to declare Map as friend of generated message.
|
||||
template <typename T>
|
||||
static void CreateInArenaStorage(T* ptr, Arena* arena) {
|
||||
template <typename T, typename... Args>
|
||||
static void CreateInArenaStorage(T* ptr, Arena* arena, Args&&... args) {
|
||||
CreateInArenaStorageInternal(ptr, arena,
|
||||
typename is_arena_constructable<T>::type());
|
||||
typename is_arena_constructable<T>::type(),
|
||||
std::forward<Args>(args)...);
|
||||
RegisterDestructorInternal(
|
||||
ptr, arena,
|
||||
typename InternalHelper<T>::is_destructor_skippable::type());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename T, typename... Args>
|
||||
static void CreateInArenaStorageInternal(T* ptr, Arena* arena,
|
||||
std::true_type) {
|
||||
InternalHelper<T>::Construct(ptr, arena);
|
||||
std::true_type, Args&&... args) {
|
||||
InternalHelper<T>::Construct(ptr, arena, std::forward<Args>(args)...);
|
||||
}
|
||||
template <typename T>
|
||||
template <typename T, typename... Args>
|
||||
static void CreateInArenaStorageInternal(T* ptr, Arena* /* arena */,
|
||||
std::false_type) {
|
||||
new (ptr) T();
|
||||
std::false_type, Args&&... args) {
|
||||
new (ptr) T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -667,7 +667,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
|
||||
|
||||
// Implementation for GetArena(). Only message objects with
|
||||
// InternalArenaConstructable_ tags can be associated with an arena, and such
|
||||
// objects must implement a GetArenaNoVirtual() method.
|
||||
// objects must implement a GetArena() method.
|
||||
template <typename T, typename std::enable_if<
|
||||
is_arena_constructable<T>::value, int>::type = 0>
|
||||
PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(const T* value) {
|
||||
@ -694,6 +694,17 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
|
||||
AllocHook(NULL, n);
|
||||
return AllocateAlignedNoHook(internal::AlignUpTo8(n));
|
||||
}
|
||||
template<size_t Align>
|
||||
void* AllocateAlignedTo(size_t n) {
|
||||
static_assert(Align > 0, "Alignment must be greater than 0");
|
||||
static_assert((Align & (Align - 1)) == 0, "Alignment must be power of two");
|
||||
if (Align <= 8) return AllocateAligned(n);
|
||||
// TODO(b/151247138): if the pointer would have been aligned already,
|
||||
// this is wasting space. We should pass the alignment down.
|
||||
uintptr_t ptr = reinterpret_cast<uintptr_t>(AllocateAligned(n + Align - 8));
|
||||
ptr = (ptr + Align - 1) & -Align;
|
||||
return reinterpret_cast<void*>(ptr);
|
||||
}
|
||||
|
||||
void* AllocateAlignedNoHook(size_t n);
|
||||
|
||||
|
@ -102,6 +102,16 @@ class PROTOC_EXPORT CodeGenerator {
|
||||
GeneratorContext* generator_context,
|
||||
std::string* error) const;
|
||||
|
||||
// Sync with plugin.proto.
|
||||
enum Feature {
|
||||
FEATURE_PROTO3_OPTIONAL = 1,
|
||||
};
|
||||
|
||||
// Implement this to indicate what features this code generator supports.
|
||||
// This should be a bitwise OR of features from the Features enum in
|
||||
// plugin.proto.
|
||||
virtual uint64 GetSupportedFeatures() const { return 0; }
|
||||
|
||||
// This is no longer used, but this class is part of the opensource protobuf
|
||||
// library, so it has to remain to keep vtables the same for the current
|
||||
// version of the library. When protobufs does a api breaking change, the
|
||||
|
@ -773,16 +773,9 @@ const char* const CommandLineInterface::kPathSeparator = ":";
|
||||
#endif
|
||||
|
||||
CommandLineInterface::CommandLineInterface()
|
||||
: mode_(MODE_COMPILE),
|
||||
print_mode_(PRINT_NONE),
|
||||
error_format_(ERROR_FORMAT_GCC),
|
||||
direct_dependencies_explicitly_set_(false),
|
||||
direct_dependencies_violation_msg_(
|
||||
kDefaultDirectDependenciesViolationMsg),
|
||||
imports_in_descriptor_set_(false),
|
||||
source_info_in_descriptor_set_(false),
|
||||
disallow_services_(false) {
|
||||
}
|
||||
: direct_dependencies_violation_msg_(
|
||||
kDefaultDirectDependenciesViolationMsg) {}
|
||||
|
||||
CommandLineInterface::~CommandLineInterface() {}
|
||||
|
||||
void CommandLineInterface::RegisterGenerator(const std::string& flag_name,
|
||||
@ -811,6 +804,39 @@ void CommandLineInterface::AllowPlugins(const std::string& exe_name_prefix) {
|
||||
plugin_prefix_ = exe_name_prefix;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
bool ContainsProto3Optional(const Descriptor* desc) {
|
||||
for (int i = 0; i < desc->field_count(); i++) {
|
||||
if (desc->field(i)->has_optional_keyword()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < desc->nested_type_count(); i++) {
|
||||
if (ContainsProto3Optional(desc->nested_type(i))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ContainsProto3Optional(const FileDescriptor* file) {
|
||||
if (file->syntax() == FileDescriptor::SYNTAX_PROTO3) {
|
||||
for (int i = 0; i < file->message_type_count(); i++) {
|
||||
if (ContainsProto3Optional(file->message_type(i))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
std::unique_ptr<SimpleDescriptorDatabase>
|
||||
PopulateSingleSimpleDescriptorDatabase(const std::string& descriptor_set_name);
|
||||
}
|
||||
|
||||
int CommandLineInterface::Run(int argc, const char* const argv[]) {
|
||||
Clear();
|
||||
@ -827,16 +853,38 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {
|
||||
std::unique_ptr<DiskSourceTree> disk_source_tree;
|
||||
std::unique_ptr<ErrorPrinter> error_collector;
|
||||
std::unique_ptr<DescriptorPool> descriptor_pool;
|
||||
std::unique_ptr<SimpleDescriptorDatabase> descriptor_set_in_database;
|
||||
|
||||
// The SimpleDescriptorDatabases here are the constituents of the
|
||||
// MergedDescriptorDatabase descriptor_set_in_database, so this vector is for
|
||||
// managing their lifetimes. Its scope should match descriptor_set_in_database
|
||||
std::vector<std::unique_ptr<SimpleDescriptorDatabase>>
|
||||
databases_per_descriptor_set;
|
||||
std::unique_ptr<MergedDescriptorDatabase> descriptor_set_in_database;
|
||||
|
||||
std::unique_ptr<SourceTreeDescriptorDatabase> source_tree_database;
|
||||
|
||||
// Any --descriptor_set_in FileDescriptorSet objects will be used as a
|
||||
// fallback to input_files on command line, so create that db first.
|
||||
if (!descriptor_set_in_names_.empty()) {
|
||||
descriptor_set_in_database.reset(new SimpleDescriptorDatabase());
|
||||
if (!PopulateSimpleDescriptorDatabase(descriptor_set_in_database.get())) {
|
||||
return 1;
|
||||
for (const std::string& name : descriptor_set_in_names_) {
|
||||
std::unique_ptr<SimpleDescriptorDatabase> database_for_descriptor_set =
|
||||
PopulateSingleSimpleDescriptorDatabase(name);
|
||||
if (!database_for_descriptor_set) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
databases_per_descriptor_set.push_back(
|
||||
std::move(database_for_descriptor_set));
|
||||
}
|
||||
|
||||
std::vector<DescriptorDatabase*> raw_databases_per_descriptor_set;
|
||||
raw_databases_per_descriptor_set.reserve(
|
||||
databases_per_descriptor_set.size());
|
||||
for (const std::unique_ptr<SimpleDescriptorDatabase>& db :
|
||||
databases_per_descriptor_set) {
|
||||
raw_databases_per_descriptor_set.push_back(db.get());
|
||||
}
|
||||
descriptor_set_in_database.reset(
|
||||
new MergedDescriptorDatabase(raw_databases_per_descriptor_set));
|
||||
}
|
||||
|
||||
if (proto_path_.empty()) {
|
||||
@ -876,6 +924,16 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {
|
||||
}
|
||||
|
||||
|
||||
for (auto fd : parsed_files) {
|
||||
if (!AllowProto3Optional(*fd) && ContainsProto3Optional(fd)) {
|
||||
std::cerr << fd->name()
|
||||
<< ": This file contains proto3 optional fields, but "
|
||||
"--experimental_allow_proto3_optional was not set."
|
||||
<< std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// We construct a separate GeneratorContext for each output location. Note
|
||||
// that two code generators may output to the same location, in which case
|
||||
// they should share a single GeneratorContext so that OpenForInsert() works.
|
||||
@ -1000,46 +1058,54 @@ bool CommandLineInterface::InitializeDiskSourceTree(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandLineInterface::PopulateSimpleDescriptorDatabase(
|
||||
SimpleDescriptorDatabase* database) {
|
||||
for (int i = 0; i < descriptor_set_in_names_.size(); i++) {
|
||||
int fd;
|
||||
do {
|
||||
fd = open(descriptor_set_in_names_[i].c_str(), O_RDONLY | O_BINARY);
|
||||
} while (fd < 0 && errno == EINTR);
|
||||
if (fd < 0) {
|
||||
std::cerr << descriptor_set_in_names_[i] << ": " << strerror(ENOENT)
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
namespace {
|
||||
std::unique_ptr<SimpleDescriptorDatabase>
|
||||
PopulateSingleSimpleDescriptorDatabase(const std::string& descriptor_set_name) {
|
||||
int fd;
|
||||
do {
|
||||
fd = open(descriptor_set_name.c_str(), O_RDONLY | O_BINARY);
|
||||
} while (fd < 0 && errno == EINTR);
|
||||
if (fd < 0) {
|
||||
std::cerr << descriptor_set_name << ": " << strerror(ENOENT) << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FileDescriptorSet file_descriptor_set;
|
||||
bool parsed = file_descriptor_set.ParseFromFileDescriptor(fd);
|
||||
if (close(fd) != 0) {
|
||||
std::cerr << descriptor_set_in_names_[i] << ": close: " << strerror(errno)
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
FileDescriptorSet file_descriptor_set;
|
||||
bool parsed = file_descriptor_set.ParseFromFileDescriptor(fd);
|
||||
if (close(fd) != 0) {
|
||||
std::cerr << descriptor_set_name << ": close: " << strerror(errno)
|
||||
<< std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!parsed) {
|
||||
std::cerr << descriptor_set_in_names_[i] << ": Unable to parse."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
if (!parsed) {
|
||||
std::cerr << descriptor_set_name << ": Unable to parse." << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (int j = 0; j < file_descriptor_set.file_size(); j++) {
|
||||
FileDescriptorProto previously_added_file_descriptor_proto;
|
||||
if (database->FindFileByName(file_descriptor_set.file(j).name(),
|
||||
&previously_added_file_descriptor_proto)) {
|
||||
// already present - skip
|
||||
continue;
|
||||
}
|
||||
if (!database->Add(file_descriptor_set.file(j))) {
|
||||
return false;
|
||||
}
|
||||
std::unique_ptr<SimpleDescriptorDatabase> database{
|
||||
new SimpleDescriptorDatabase()};
|
||||
|
||||
for (int j = 0; j < file_descriptor_set.file_size(); j++) {
|
||||
FileDescriptorProto previously_added_file_descriptor_proto;
|
||||
if (database->FindFileByName(file_descriptor_set.file(j).name(),
|
||||
&previously_added_file_descriptor_proto)) {
|
||||
// already present - skip
|
||||
continue;
|
||||
}
|
||||
if (!database->Add(file_descriptor_set.file(j))) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return database;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool CommandLineInterface::AllowProto3Optional(
|
||||
const FileDescriptor& file) const {
|
||||
if (allow_proto3_optional_) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CommandLineInterface::VerifyInputFilesInDescriptors(
|
||||
@ -1068,10 +1134,26 @@ bool CommandLineInterface::ParseInputFiles(
|
||||
DescriptorPool* descriptor_pool, DiskSourceTree* source_tree,
|
||||
std::vector<const FileDescriptor*>* parsed_files) {
|
||||
|
||||
// Track unused imports in all source files
|
||||
for (const auto& input_file : input_files_) {
|
||||
descriptor_pool->AddUnusedImportTrackFile(input_file);
|
||||
if (!proto_path_.empty()) {
|
||||
// Track unused imports in all source files that were loaded from the
|
||||
// filesystem. We do not track unused imports for files loaded from
|
||||
// descriptor sets as they may be programmatically generated in which case
|
||||
// exerting this level of rigor is less desirable. We're also making the
|
||||
// assumption that the initial parse of the proto from the filesystem
|
||||
// was rigorous in checking unused imports and that the descriptor set
|
||||
// being parsed was produced then and that it was subsequent mutations
|
||||
// of that descriptor set that left unused imports.
|
||||
//
|
||||
// Note that relying on proto_path exclusively is limited in that we may
|
||||
// be loading descriptors from both the filesystem and descriptor sets
|
||||
// depending on the invocation. At least for invocations that are
|
||||
// exclusively reading from descriptor sets, we can eliminate this failure
|
||||
// condition.
|
||||
for (const auto& input_file : input_files_) {
|
||||
descriptor_pool->AddUnusedImportTrackFile(input_file);
|
||||
}
|
||||
}
|
||||
|
||||
bool result = true;
|
||||
// Parse each file.
|
||||
for (const auto& input_file : input_files_) {
|
||||
@ -1139,6 +1221,7 @@ void CommandLineInterface::Clear() {
|
||||
source_info_in_descriptor_set_ = false;
|
||||
disallow_services_ = false;
|
||||
direct_dependencies_explicitly_set_ = false;
|
||||
allow_proto3_optional_ = false;
|
||||
}
|
||||
|
||||
bool CommandLineInterface::MakeProtoProtoPathRelative(
|
||||
@ -1414,7 +1497,8 @@ bool CommandLineInterface::ParseArgument(const char* arg, std::string* name,
|
||||
if (*name == "-h" || *name == "--help" || *name == "--disallow_services" ||
|
||||
*name == "--include_imports" || *name == "--include_source_info" ||
|
||||
*name == "--version" || *name == "--decode_raw" ||
|
||||
*name == "--print_free_field_numbers") {
|
||||
*name == "--print_free_field_numbers" ||
|
||||
*name == "--experimental_allow_proto3_optional") {
|
||||
// HACK: These are the only flags that don't take a value.
|
||||
// They probably should not be hard-coded like this but for now it's
|
||||
// not worth doing better.
|
||||
@ -1621,6 +1705,9 @@ CommandLineInterface::InterpretArgument(const std::string& name,
|
||||
} else if (name == "--disallow_services") {
|
||||
disallow_services_ = true;
|
||||
|
||||
} else if (name == "--experimental_allow_proto3_optional") {
|
||||
allow_proto3_optional_ = true;
|
||||
|
||||
} else if (name == "--encode" || name == "--decode" ||
|
||||
name == "--decode_raw") {
|
||||
if (mode_ != MODE_COMPILE) {
|
||||
@ -1921,6 +2008,28 @@ void CommandLineInterface::PrintHelpText() {
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
bool CommandLineInterface::EnforceProto3OptionalSupport(
|
||||
const std::string& codegen_name, uint64 supported_features,
|
||||
const std::vector<const FileDescriptor*>& parsed_files) const {
|
||||
bool supports_proto3_optional =
|
||||
supported_features & CodeGenerator::FEATURE_PROTO3_OPTIONAL;
|
||||
if (!supports_proto3_optional) {
|
||||
for (const auto fd : parsed_files) {
|
||||
if (ContainsProto3Optional(fd)) {
|
||||
std::cerr << fd->name()
|
||||
<< ": is a proto3 file that contains optional fields, but "
|
||||
"code generator "
|
||||
<< codegen_name
|
||||
<< " hasn't been updated to support optional fields in "
|
||||
"proto3. Please ask the owner of this code generator to "
|
||||
"support proto3 optional.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandLineInterface::GenerateOutput(
|
||||
const std::vector<const FileDescriptor*>& parsed_files,
|
||||
const OutputDirective& output_directive,
|
||||
@ -1955,6 +2064,12 @@ bool CommandLineInterface::GenerateOutput(
|
||||
}
|
||||
parameters.append(generator_parameters_[output_directive.name]);
|
||||
}
|
||||
if (!EnforceProto3OptionalSupport(
|
||||
output_directive.name,
|
||||
output_directive.generator->GetSupportedFeatures(), parsed_files)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!output_directive.generator->GenerateAll(parsed_files, parameters,
|
||||
generator_context, &error)) {
|
||||
// Generator returned an error.
|
||||
@ -2119,6 +2234,9 @@ bool CommandLineInterface::GeneratePluginOutput(
|
||||
// Generator returned an error.
|
||||
*error = response.error();
|
||||
return false;
|
||||
} else if (!EnforceProto3OptionalSupport(
|
||||
plugin_name, response.supported_features(), parsed_files)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -226,6 +226,17 @@ class PROTOC_EXPORT CommandLineInterface {
|
||||
bool MakeInputsBeProtoPathRelative(DiskSourceTree* source_tree,
|
||||
DescriptorDatabase* fallback_database);
|
||||
|
||||
// Is this .proto file whitelisted, or do we have a command-line flag allowing
|
||||
// us to use proto3 optional? This is a temporary control to avoid people from
|
||||
// using proto3 optional until code generators have implemented it.
|
||||
bool AllowProto3Optional(const FileDescriptor& file) const;
|
||||
|
||||
// Fails if these files use proto3 optional and the code generator doesn't
|
||||
// support it. This is a permanent check.
|
||||
bool EnforceProto3OptionalSupport(
|
||||
const std::string& codegen_name, uint64 supported_features,
|
||||
const std::vector<const FileDescriptor*>& parsed_files) const;
|
||||
|
||||
|
||||
// Return status for ParseArguments() and InterpretArgument().
|
||||
enum ParseArgumentStatus {
|
||||
@ -269,9 +280,6 @@ class PROTOC_EXPORT CommandLineInterface {
|
||||
// Verify that all the input files exist in the given database.
|
||||
bool VerifyInputFilesInDescriptors(DescriptorDatabase* fallback_database);
|
||||
|
||||
// Loads descriptor_set_in into the provided database
|
||||
bool PopulateSimpleDescriptorDatabase(SimpleDescriptorDatabase* database);
|
||||
|
||||
// Parses input_files_ into parsed_files
|
||||
bool ParseInputFiles(DescriptorPool* descriptor_pool,
|
||||
DiskSourceTree* source_tree,
|
||||
@ -373,21 +381,21 @@ class PROTOC_EXPORT CommandLineInterface {
|
||||
MODE_PRINT, // Print mode: print info of the given .proto files and exit.
|
||||
};
|
||||
|
||||
Mode mode_;
|
||||
Mode mode_ = MODE_COMPILE;
|
||||
|
||||
enum PrintMode {
|
||||
PRINT_NONE, // Not in MODE_PRINT
|
||||
PRINT_FREE_FIELDS, // --print_free_fields
|
||||
};
|
||||
|
||||
PrintMode print_mode_;
|
||||
PrintMode print_mode_ = PRINT_NONE;
|
||||
|
||||
enum ErrorFormat {
|
||||
ERROR_FORMAT_GCC, // GCC error output format (default).
|
||||
ERROR_FORMAT_MSVS // Visual Studio output (--error_format=msvs).
|
||||
};
|
||||
|
||||
ErrorFormat error_format_;
|
||||
ErrorFormat error_format_ = ERROR_FORMAT_GCC;
|
||||
|
||||
std::vector<std::pair<std::string, std::string> >
|
||||
proto_path_; // Search path for proto files.
|
||||
@ -396,7 +404,7 @@ class PROTOC_EXPORT CommandLineInterface {
|
||||
// Names of proto files which are allowed to be imported. Used by build
|
||||
// systems to enforce depend-on-what-you-import.
|
||||
std::set<std::string> direct_dependencies_;
|
||||
bool direct_dependencies_explicitly_set_;
|
||||
bool direct_dependencies_explicitly_set_ = false;
|
||||
|
||||
// If there's a violation of depend-on-what-you-import, this string will be
|
||||
// presented to the user. "%s" will be replaced with the violating import.
|
||||
@ -435,10 +443,13 @@ class PROTOC_EXPORT CommandLineInterface {
|
||||
|
||||
// True if --include_source_info was given, meaning that we should not strip
|
||||
// SourceCodeInfo from the DescriptorSet.
|
||||
bool source_info_in_descriptor_set_;
|
||||
bool source_info_in_descriptor_set_ = false;
|
||||
|
||||
// Was the --disallow_services flag used?
|
||||
bool disallow_services_;
|
||||
bool disallow_services_ = false;
|
||||
|
||||
// Was the --experimental_allow_proto3_optional flag used?
|
||||
bool allow_proto3_optional_ = false;
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CommandLineInterface);
|
||||
};
|
||||
|
@ -205,6 +205,17 @@ class CommandLineInterfaceTest : public testing::Test {
|
||||
void ExpectFileContent(const std::string& filename,
|
||||
const std::string& content);
|
||||
|
||||
// The default code generators support all features. Use this to create a
|
||||
// code generator that omits the given feature(s).
|
||||
void CreateGeneratorWithMissingFeatures(const std::string& name,
|
||||
const std::string& description,
|
||||
uint64 features) {
|
||||
MockCodeGenerator* generator = new MockCodeGenerator(name);
|
||||
generator->SuppressFeatures(features);
|
||||
mock_generators_to_delete_.push_back(generator);
|
||||
cli_.RegisterGenerator(name, generator, description);
|
||||
}
|
||||
|
||||
private:
|
||||
// The object we are testing.
|
||||
CommandLineInterface cli_;
|
||||
@ -913,6 +924,58 @@ TEST_F(CommandLineInterfaceTest,
|
||||
ExpectErrorSubstring("bar.proto: \"Baz\" is not defined.");
|
||||
}
|
||||
|
||||
TEST_F(CommandLineInterfaceTest,
|
||||
InputsOnlyFromDescriptorSetIn_UnusedImportIsNotReported) {
|
||||
FileDescriptorSet file_descriptor_set;
|
||||
|
||||
FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file();
|
||||
file_descriptor_proto->set_name("unused.proto");
|
||||
file_descriptor_proto->add_message_type()->set_name("Unused");
|
||||
|
||||
file_descriptor_proto = file_descriptor_set.add_file();
|
||||
file_descriptor_proto->set_name("bar.proto");
|
||||
file_descriptor_proto->add_dependency("unused.proto");
|
||||
file_descriptor_proto->add_message_type()->set_name("Bar");
|
||||
|
||||
WriteDescriptorSet("unused_and_bar.bin", &file_descriptor_set);
|
||||
|
||||
Run("protocol_compiler --test_out=$tmpdir --plug_out=$tmpdir "
|
||||
"--descriptor_set_in=$tmpdir/unused_and_bar.bin unused.proto bar.proto");
|
||||
ExpectNoErrors();
|
||||
}
|
||||
|
||||
TEST_F(CommandLineInterfaceTest,
|
||||
InputsFromDescriptorSetInAndFileSystem_UnusedImportIsReported) {
|
||||
FileDescriptorSet file_descriptor_set;
|
||||
|
||||
FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file();
|
||||
file_descriptor_proto->set_name("unused.proto");
|
||||
file_descriptor_proto->add_message_type()->set_name("Unused");
|
||||
|
||||
file_descriptor_proto = file_descriptor_set.add_file();
|
||||
file_descriptor_proto->set_name("bar.proto");
|
||||
file_descriptor_proto->add_dependency("unused.proto");
|
||||
file_descriptor_proto->add_message_type()->set_name("Bar");
|
||||
|
||||
WriteDescriptorSet("unused_and_bar.bin", &file_descriptor_set);
|
||||
|
||||
CreateTempFile("foo.proto",
|
||||
"syntax = \"proto2\";\n"
|
||||
"import \"bar.proto\";\n"
|
||||
"message Foo {\n"
|
||||
" optional Bar bar = 1;\n"
|
||||
"}\n");
|
||||
|
||||
Run("protocol_compiler --test_out=$tmpdir --plug_out=$tmpdir "
|
||||
"--descriptor_set_in=$tmpdir/unused_and_bar.bin "
|
||||
"--proto_path=$tmpdir unused.proto bar.proto foo.proto");
|
||||
// Reporting unused imports here is unfair, since it's unactionable. Notice
|
||||
// the lack of a line number.
|
||||
// TODO(b/144853061): If the file with unused import is from the descriptor
|
||||
// set and not from the file system, suppress the warning.
|
||||
ExpectWarningSubstring("bar.proto: warning: Import unused.proto is unused.");
|
||||
}
|
||||
|
||||
TEST_F(CommandLineInterfaceTest,
|
||||
OnlyReportsUnusedImportsForFilesBeingGenerated) {
|
||||
CreateTempFile("unused.proto",
|
||||
@ -975,7 +1038,6 @@ TEST_F(CommandLineInterfaceTest, ReportsTransitiveMisingImports_LeafLast) {
|
||||
ExpectWarningSubstring(
|
||||
"bar.proto:2:1: warning: Import unused.proto is unused.");
|
||||
}
|
||||
|
||||
TEST_F(CommandLineInterfaceTest, CreateDirectory) {
|
||||
// Test that when we output to a sub-directory, it is created.
|
||||
|
||||
@ -2310,6 +2372,78 @@ TEST_F(CommandLineInterfaceTest, MissingValueAtEndError) {
|
||||
ExpectErrorText("Missing value for flag: --test_out\n");
|
||||
}
|
||||
|
||||
TEST_F(CommandLineInterfaceTest, Proto3OptionalDisallowed) {
|
||||
CreateTempFile("foo.proto",
|
||||
"syntax = \"proto3\";\n"
|
||||
"message Foo {\n"
|
||||
" optional int32 i = 1;\n"
|
||||
"}\n");
|
||||
|
||||
Run("protocol_compiler --proto_path=$tmpdir foo.proto -odescriptor.pb");
|
||||
|
||||
ExpectErrorSubstring("--experimental_allow_proto3_optional was not set");
|
||||
}
|
||||
|
||||
TEST_F(CommandLineInterfaceTest, Proto3OptionalDisallowedDescriptor) {
|
||||
CreateTempFile("foo.proto",
|
||||
"syntax = \"proto3\";\n"
|
||||
"message Foo {\n"
|
||||
" optional int32 i = 1;\n"
|
||||
"}\n");
|
||||
|
||||
Run("protocol_compiler --experimental_allow_proto3_optional "
|
||||
"--proto_path=$tmpdir foo.proto "
|
||||
" -o$tmpdir/descriptor.pb");
|
||||
ExpectNoErrors();
|
||||
|
||||
Run("protocol_compiler --descriptor_set_in=$tmpdir/descriptor.pb foo.proto "
|
||||
"--test_out=$tmpdir");
|
||||
ExpectErrorSubstring("--experimental_allow_proto3_optional was not set");
|
||||
}
|
||||
|
||||
TEST_F(CommandLineInterfaceTest, Proto3OptionalDisallowedGenCode) {
|
||||
CreateTempFile("foo.proto",
|
||||
"syntax = \"proto3\";\n"
|
||||
"message Foo {\n"
|
||||
" optional int32 i = 1;\n"
|
||||
"}\n");
|
||||
|
||||
Run("protocol_compiler --proto_path=$tmpdir foo.proto --test_out=$tmpdir");
|
||||
|
||||
ExpectErrorSubstring("--experimental_allow_proto3_optional was not set");
|
||||
}
|
||||
|
||||
TEST_F(CommandLineInterfaceTest, Proto3OptionalDisallowedNoCodegenSupport) {
|
||||
CreateTempFile("foo.proto",
|
||||
"syntax = \"proto3\";\n"
|
||||
"message Foo {\n"
|
||||
" optional int32 i = 1;\n"
|
||||
"}\n");
|
||||
|
||||
CreateGeneratorWithMissingFeatures("--no_proto3_optional_out",
|
||||
"Doesn't support proto3 optional",
|
||||
CodeGenerator::FEATURE_PROTO3_OPTIONAL);
|
||||
|
||||
Run("protocol_compiler --experimental_allow_proto3_optional "
|
||||
"--proto_path=$tmpdir foo.proto --no_proto3_optional_out=$tmpdir");
|
||||
|
||||
ExpectErrorSubstring(
|
||||
"code generator --no_proto3_optional_out hasn't been updated to support "
|
||||
"optional fields in proto3");
|
||||
}
|
||||
|
||||
TEST_F(CommandLineInterfaceTest, Proto3OptionalAllowWithFlag) {
|
||||
CreateTempFile("foo.proto",
|
||||
"syntax = \"proto3\";\n"
|
||||
"message Foo {\n"
|
||||
" optional int32 i = 1;\n"
|
||||
"}\n");
|
||||
|
||||
Run("protocol_compiler --experimental_allow_proto3_optional "
|
||||
"--proto_path=$tmpdir foo.proto --test_out=$tmpdir");
|
||||
ExpectNoErrors();
|
||||
}
|
||||
|
||||
TEST_F(CommandLineInterfaceTest, PrintFreeFieldNumbers) {
|
||||
CreateTempFile("foo.proto",
|
||||
"syntax = \"proto2\";\n"
|
||||
|
@ -76,8 +76,8 @@ class MockErrorCollector : public MultiFileErrorCollector {
|
||||
// implements ErrorCollector ---------------------------------------
|
||||
void AddError(const std::string& filename, int line, int column,
|
||||
const std::string& message) {
|
||||
strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line,
|
||||
column, message);
|
||||
strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column,
|
||||
message);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -94,7 +94,7 @@ ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor,
|
||||
variables_["constant_name"] = FieldConstantName(descriptor_);
|
||||
variables_["field_type"] =
|
||||
StrCat(static_cast<int>(descriptor_->type()));
|
||||
variables_["packed"] = descriptor_->options().packed() ? "true" : "false";
|
||||
variables_["packed"] = descriptor_->is_packed() ? "true" : "false";
|
||||
|
||||
std::string scope =
|
||||
IsScoped() ? ClassName(descriptor_->extension_scope(), false) + "::" : "";
|
||||
@ -157,6 +157,11 @@ void ExtensionGenerator::GenerateDefinition(io::Printer* printer) {
|
||||
StringReplace(variables_["scoped_name"], "::", "_", true) + "_default";
|
||||
format("const std::string $1$($2$);\n", default_str,
|
||||
DefaultValue(options_, descriptor_));
|
||||
} else if (descriptor_->message_type()) {
|
||||
// We have to initialize the default instance for extensions at registration
|
||||
// time.
|
||||
default_str =
|
||||
FieldMessageTypeName(descriptor_, options_) + "::default_instance()";
|
||||
} else {
|
||||
default_str = DefaultValue(options_, descriptor_);
|
||||
}
|
||||
|
@ -411,11 +411,6 @@ void FileGenerator::GenerateSourceIncludes(io::Printer* printer) {
|
||||
IncludeFile("net/proto2/public/reflection_ops.h", printer);
|
||||
IncludeFile("net/proto2/public/wire_format.h", printer);
|
||||
}
|
||||
if (IsProto2MessageSetFile(file_, options_)) {
|
||||
format(
|
||||
// Implementation of proto1 MessageSet API methods.
|
||||
"#include \"net/proto2/internal/message_set_util.h\"\n");
|
||||
}
|
||||
|
||||
if (options_.proto_h) {
|
||||
// Use the smaller .proto.h files.
|
||||
@ -898,18 +893,21 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* printer) {
|
||||
format("};\n");
|
||||
|
||||
// The DescriptorTable itself.
|
||||
// Should be "bool eager = NeedsEagerDescriptorAssignment(file_, options_);"
|
||||
// however this might cause a tsan failure in superroot b/148382879,
|
||||
// so disable for now.
|
||||
bool eager = false;
|
||||
format(
|
||||
"static ::$proto_ns$::internal::once_flag $desc_table$_once;\n"
|
||||
"static bool $desc_table$_initialized = false;\n"
|
||||
"const ::$proto_ns$::internal::DescriptorTable $desc_table$ = {\n"
|
||||
" &$desc_table$_initialized, $1$, \"$filename$\", $2$,\n"
|
||||
" &$desc_table$_once, $desc_table$_sccs, $desc_table$_deps, $3$, $4$,\n"
|
||||
" false, $1$, $2$, \"$filename$\", $3$,\n"
|
||||
" &$desc_table$_once, $desc_table$_sccs, $desc_table$_deps, $4$, $5$,\n"
|
||||
" schemas, file_default_instances, $tablename$::offsets,\n"
|
||||
" $file_level_metadata$, $5$, $file_level_enum_descriptors$, "
|
||||
" $file_level_metadata$, $6$, $file_level_enum_descriptors$, "
|
||||
"$file_level_service_descriptors$,\n"
|
||||
"};\n\n",
|
||||
protodef_name, file_data.size(), sccs_.size(), num_deps,
|
||||
message_generators_.size());
|
||||
eager ? "true" : "false", protodef_name, file_data.size(), sccs_.size(),
|
||||
num_deps, message_generators_.size());
|
||||
|
||||
// For descriptor.proto we want to avoid doing any dynamic initialization,
|
||||
// because in some situations that would otherwise pull in a lot of
|
||||
@ -1297,12 +1295,10 @@ void FileGenerator::GenerateLibraryIncludes(io::Printer* printer) {
|
||||
IncludeFile("net/proto2/public/generated_message_table_driven.h", printer);
|
||||
IncludeFile("net/proto2/public/generated_message_util.h", printer);
|
||||
IncludeFile("net/proto2/public/inlined_string_field.h", printer);
|
||||
IncludeFile("net/proto2/public/metadata_lite.h", printer);
|
||||
|
||||
if (HasDescriptorMethods(file_, options_)) {
|
||||
IncludeFile("net/proto2/public/metadata.h", printer);
|
||||
IncludeFile("net/proto2/public/generated_message_reflection.h", printer);
|
||||
} else {
|
||||
IncludeFile("net/proto2/public/metadata_lite.h", printer);
|
||||
}
|
||||
|
||||
if (!message_generators_.empty()) {
|
||||
|
@ -93,6 +93,8 @@ bool CppGenerator::Generate(const FileDescriptor* file,
|
||||
file_options.annotation_guard_name = options[i].second;
|
||||
} else if (options[i].first == "speed") {
|
||||
file_options.enforce_mode = EnforceOptimizeMode::kSpeed;
|
||||
} else if (options[i].first == "code_size") {
|
||||
file_options.enforce_mode = EnforceOptimizeMode::kCodeSize;
|
||||
} else if (options[i].first == "lite") {
|
||||
file_options.enforce_mode = EnforceOptimizeMode::kLiteRuntime;
|
||||
} else if (options[i].first == "lite_implicit_weak_fields") {
|
||||
|
@ -83,6 +83,12 @@ class PROTOC_EXPORT CppGenerator : public CodeGenerator {
|
||||
bool Generate(const FileDescriptor* file, const std::string& parameter,
|
||||
GeneratorContext* generator_context, std::string* error) const;
|
||||
|
||||
uint64 GetSupportedFeatures() const override {
|
||||
// We don't fully support this yet, but this is needed to unblock the tests,
|
||||
// and we will have full support before the experimental flag is removed.
|
||||
return FEATURE_PROTO3_OPTIONAL;
|
||||
}
|
||||
|
||||
private:
|
||||
bool opensource_runtime_ = true;
|
||||
std::string runtime_include_base_;
|
||||
|
@ -43,10 +43,13 @@
|
||||
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/stubs/logging.h>
|
||||
#include <google/protobuf/compiler/cpp/cpp_options.h>
|
||||
#include <google/protobuf/descriptor.pb.h>
|
||||
#include <google/protobuf/descriptor.h>
|
||||
#include <google/protobuf/compiler/scc.h>
|
||||
#include <google/protobuf/io/printer.h>
|
||||
#include <google/protobuf/io/zero_copy_stream.h>
|
||||
#include <google/protobuf/dynamic_message.h>
|
||||
#include <google/protobuf/wire_format.h>
|
||||
#include <google/protobuf/wire_format_lite.h>
|
||||
#include <google/protobuf/stubs/strutil.h>
|
||||
@ -244,6 +247,31 @@ void SetCommonVars(const Options& options,
|
||||
(*variables)["string"] = "std::string";
|
||||
}
|
||||
|
||||
void SetUnknkownFieldsVariable(const Descriptor* descriptor,
|
||||
const Options& options,
|
||||
std::map<std::string, std::string>* variables) {
|
||||
std::string proto_ns = ProtobufNamespace(options);
|
||||
std::string unknown_fields_type;
|
||||
if (UseUnknownFieldSet(descriptor->file(), options)) {
|
||||
unknown_fields_type = "::" + proto_ns + "::UnknownFieldSet";
|
||||
(*variables)["unknown_fields"] =
|
||||
"_internal_metadata_.unknown_fields<" + unknown_fields_type + ">(" +
|
||||
unknown_fields_type + "::default_instance)";
|
||||
} else {
|
||||
unknown_fields_type =
|
||||
PrimitiveTypeName(options, FieldDescriptor::CPPTYPE_STRING);
|
||||
(*variables)["unknown_fields"] = "_internal_metadata_.unknown_fields<" +
|
||||
unknown_fields_type + ">(::" + proto_ns +
|
||||
"::internal::GetEmptyString)";
|
||||
}
|
||||
(*variables)["unknown_fields_type"] = unknown_fields_type;
|
||||
(*variables)["have_unknown_fields"] =
|
||||
"_internal_metadata_.have_unknown_fields()";
|
||||
(*variables)["mutable_unknown_fields"] =
|
||||
"_internal_metadata_.mutable_unknown_fields<" + unknown_fields_type +
|
||||
">()";
|
||||
}
|
||||
|
||||
std::string UnderscoresToCamelCase(const std::string& input,
|
||||
bool cap_next_letter) {
|
||||
std::string result;
|
||||
@ -334,6 +362,16 @@ std::string QualifiedClassName(const EnumDescriptor* d) {
|
||||
return QualifiedClassName(d, Options());
|
||||
}
|
||||
|
||||
std::string QualifiedExtensionName(const FieldDescriptor* d,
|
||||
const Options& options) {
|
||||
GOOGLE_DCHECK(d->is_extension());
|
||||
return QualifiedFileLevelSymbol(d->file(), FieldName(d), options);
|
||||
}
|
||||
|
||||
std::string QualifiedExtensionName(const FieldDescriptor* d) {
|
||||
return QualifiedExtensionName(d, Options());
|
||||
}
|
||||
|
||||
std::string Namespace(const std::string& package) {
|
||||
if (package.empty()) return "";
|
||||
return "::" + DotsToColons(package);
|
||||
@ -1345,11 +1383,14 @@ class ParseLoopGenerator {
|
||||
format_.Set("GOOGLE_PROTOBUF", MacroPrefix(options_));
|
||||
std::map<std::string, std::string> vars;
|
||||
SetCommonVars(options_, &vars);
|
||||
SetUnknkownFieldsVariable(descriptor, options_, &vars);
|
||||
format_.AddMap(vars);
|
||||
|
||||
std::vector<const FieldDescriptor*> ordered_fields;
|
||||
for (auto field : FieldRange(descriptor)) {
|
||||
ordered_fields.push_back(field);
|
||||
if (IsFieldUsed(field, options_)) {
|
||||
ordered_fields.push_back(field);
|
||||
}
|
||||
}
|
||||
std::sort(ordered_fields.begin(), ordered_fields.end(),
|
||||
[](const FieldDescriptor* a, const FieldDescriptor* b) {
|
||||
@ -1375,12 +1416,13 @@ class ParseLoopGenerator {
|
||||
}
|
||||
|
||||
if (descriptor->file()->options().cc_enable_arenas()) {
|
||||
format_("$p_ns$::Arena* arena = GetArenaNoVirtual(); (void)arena;\n");
|
||||
format_("$p_ns$::Arena* arena = GetArena(); (void)arena;\n");
|
||||
}
|
||||
GenerateParseLoop(descriptor, ordered_fields);
|
||||
format_.Outdent();
|
||||
format_("success:\n");
|
||||
if (hasbits_size) format_(" _has_bits_.Or(has_bits);\n");
|
||||
|
||||
format_(
|
||||
" return ptr;\n"
|
||||
"failure:\n"
|
||||
@ -1495,12 +1537,20 @@ class ParseLoopGenerator {
|
||||
enum_validator =
|
||||
StrCat(", ", QualifiedClassName(field->enum_type(), options_),
|
||||
"_IsValid, &_internal_metadata_, ", field->number());
|
||||
format_(
|
||||
"ptr = "
|
||||
"$pi_ns$::Packed$1$Parser<$unknown_fields_type$>(_internal_mutable_"
|
||||
"$2$(), ptr, "
|
||||
"ctx$3$);\n",
|
||||
DeclaredTypeMethodName(field->type()), FieldName(field),
|
||||
enum_validator);
|
||||
} else {
|
||||
format_(
|
||||
"ptr = $pi_ns$::Packed$1$Parser(_internal_mutable_$2$(), ptr, "
|
||||
"ctx$3$);\n",
|
||||
DeclaredTypeMethodName(field->type()), FieldName(field),
|
||||
enum_validator);
|
||||
}
|
||||
format_(
|
||||
"ptr = $pi_ns$::Packed$1$Parser(_internal_mutable_$2$(), ptr, "
|
||||
"ctx$3$);\n",
|
||||
DeclaredTypeMethodName(field->type()), FieldName(field),
|
||||
enum_validator);
|
||||
} else {
|
||||
auto field_type = field->type();
|
||||
switch (field_type) {
|
||||
@ -1518,7 +1568,9 @@ class ParseLoopGenerator {
|
||||
if (HasFieldPresence(field->file()) &&
|
||||
val->type() == FieldDescriptor::TYPE_ENUM) {
|
||||
format_(
|
||||
"auto object = ::$proto_ns$::internal::InitEnumParseWrapper("
|
||||
"auto object = "
|
||||
"::$proto_ns$::internal::InitEnumParseWrapper<$unknown_"
|
||||
"fields_type$>("
|
||||
"&$1$_, $2$_IsValid, $3$, &_internal_metadata_);\n"
|
||||
"ptr = ctx->ParseMessage(&object, ptr);\n",
|
||||
FieldName(field), QualifiedClassName(val->enum_type()),
|
||||
@ -1533,8 +1585,7 @@ class ParseLoopGenerator {
|
||||
"if (!_internal_has_$1$()) {\n"
|
||||
" clear_$2$();\n"
|
||||
" $2$_.$1$_ = ::$proto_ns$::Arena::CreateMessage<\n"
|
||||
" $pi_ns$::LazyField>("
|
||||
"GetArenaNoVirtual());\n"
|
||||
" $pi_ns$::LazyField>(GetArena());\n"
|
||||
" set_has_$1$();\n"
|
||||
"}\n"
|
||||
"ptr = ctx->ParseMessage($2$_.$1$_, ptr);\n",
|
||||
@ -1624,7 +1675,10 @@ class ParseLoopGenerator {
|
||||
field->number());
|
||||
}
|
||||
} else {
|
||||
std::string size = (field->type() == FieldDescriptor::TYPE_SINT32 || field->type() == FieldDescriptor::TYPE_UINT32) ? "32" : "64";
|
||||
std::string size = (field->type() == FieldDescriptor::TYPE_SINT32 ||
|
||||
field->type() == FieldDescriptor::TYPE_UINT32)
|
||||
? "32"
|
||||
: "64";
|
||||
std::string zigzag;
|
||||
if ((field->type() == FieldDescriptor::TYPE_SINT32 ||
|
||||
field->type() == FieldDescriptor::TYPE_SINT64)) {
|
||||
@ -1807,7 +1861,10 @@ class ParseLoopGenerator {
|
||||
"}\n");
|
||||
}
|
||||
format_(
|
||||
" ptr = UnknownFieldParse(tag, &_internal_metadata_, ptr, ctx);\n"
|
||||
" ptr = UnknownFieldParse(tag,\n"
|
||||
" _internal_metadata_.mutable_unknown_fields<$unknown_"
|
||||
"fields_type$>(),\n"
|
||||
" ptr, ctx);\n"
|
||||
" CHK_(ptr != nullptr);\n"
|
||||
" continue;\n");
|
||||
}
|
||||
@ -1827,6 +1884,130 @@ void GenerateParserLoop(const Descriptor* descriptor, int num_hasbits,
|
||||
generator.GenerateParserLoop(descriptor);
|
||||
}
|
||||
|
||||
static bool HasExtensionFromFile(const Message& msg, const FileDescriptor* file,
|
||||
const Options& options,
|
||||
bool* has_opt_codesize_extension) {
|
||||
std::vector<const FieldDescriptor*> fields;
|
||||
auto reflection = msg.GetReflection();
|
||||
reflection->ListFields(msg, &fields);
|
||||
for (auto field : fields) {
|
||||
const auto* field_msg = field->message_type();
|
||||
if (field_msg == nullptr) {
|
||||
// It so happens that enums Is_Valid are still generated so enums work.
|
||||
// Only messages have potential problems.
|
||||
continue;
|
||||
}
|
||||
// If this option has an extension set AND that extension is defined in the
|
||||
// same file we have bootstrap problem.
|
||||
if (field->is_extension()) {
|
||||
const auto* msg_extension_file = field->message_type()->file();
|
||||
if (msg_extension_file == file) return true;
|
||||
if (has_opt_codesize_extension &&
|
||||
GetOptimizeFor(msg_extension_file, options) ==
|
||||
FileOptions::CODE_SIZE) {
|
||||
*has_opt_codesize_extension = true;
|
||||
}
|
||||
}
|
||||
// Recurse in this field to see if there is a problem in there
|
||||
if (field->is_repeated()) {
|
||||
for (int i = 0; i < reflection->FieldSize(msg, field); i++) {
|
||||
if (HasExtensionFromFile(reflection->GetRepeatedMessage(msg, field, i),
|
||||
file, options, has_opt_codesize_extension)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (HasExtensionFromFile(reflection->GetMessage(msg, field), file,
|
||||
options, has_opt_codesize_extension)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool HasBootstrapProblem(const FileDescriptor* file,
|
||||
const Options& options,
|
||||
bool* has_opt_codesize_extension) {
|
||||
static auto& cache = *new std::unordered_map<const FileDescriptor*, bool>;
|
||||
auto it = cache.find(file);
|
||||
if (it != cache.end()) return it->second;
|
||||
// In order to build the data structures for the reflective parse, it needs
|
||||
// to parse the serialized descriptor describing all the messages defined in
|
||||
// this file. Obviously this presents a bootstrap problem for descriptor
|
||||
// messages.
|
||||
if (file->name() == "net/proto2/proto/descriptor.proto" ||
|
||||
file->name() == "google/protobuf/descriptor.proto") {
|
||||
return true;
|
||||
}
|
||||
// Unfortunately we're not done yet. The descriptor option messages allow
|
||||
// for extensions. So we need to be able to parse these extensions in order
|
||||
// to parse the file descriptor for a file that has custom options. This is a
|
||||
// problem when these custom options extensions are defined in the same file.
|
||||
FileDescriptorProto linkedin_fd_proto;
|
||||
const DescriptorPool* pool = file->pool();
|
||||
const Descriptor* fd_proto_descriptor =
|
||||
pool->FindMessageTypeByName(linkedin_fd_proto.GetTypeName());
|
||||
// Not all pools have descriptor.proto in them. In these cases there for sure
|
||||
// are no custom options.
|
||||
if (fd_proto_descriptor == nullptr) return false;
|
||||
|
||||
// It's easier to inspect file as a proto, because we can use reflection on
|
||||
// the proto to iterate over all content.
|
||||
file->CopyTo(&linkedin_fd_proto);
|
||||
|
||||
// linkedin_fd_proto is a generated proto linked in the proto compiler. As
|
||||
// such it doesn't know the extensions that are potentially present in the
|
||||
// descriptor pool constructed from the protos that are being compiled. These
|
||||
// custom options are therefore in the unknown fields.
|
||||
// By building the corresponding FileDescriptorProto in the pool constructed
|
||||
// by the protos that are being compiled, ie. file's pool, the unknown fields
|
||||
// are converted to extensions.
|
||||
DynamicMessageFactory factory(pool);
|
||||
Message* fd_proto = factory.GetPrototype(fd_proto_descriptor)->New();
|
||||
fd_proto->ParseFromString(linkedin_fd_proto.SerializeAsString());
|
||||
|
||||
bool& res = cache[file];
|
||||
res = HasExtensionFromFile(*fd_proto, file, options,
|
||||
has_opt_codesize_extension);
|
||||
delete fd_proto;
|
||||
return res;
|
||||
}
|
||||
|
||||
FileOptions_OptimizeMode GetOptimizeFor(const FileDescriptor* file,
|
||||
const Options& options,
|
||||
bool* has_opt_codesize_extension) {
|
||||
if (has_opt_codesize_extension) *has_opt_codesize_extension = false;
|
||||
switch (options.enforce_mode) {
|
||||
case EnforceOptimizeMode::kSpeed:
|
||||
return FileOptions::SPEED;
|
||||
case EnforceOptimizeMode::kLiteRuntime:
|
||||
return FileOptions::LITE_RUNTIME;
|
||||
case EnforceOptimizeMode::kCodeSize:
|
||||
if (file->options().optimize_for() == FileOptions::LITE_RUNTIME) {
|
||||
return FileOptions::LITE_RUNTIME;
|
||||
}
|
||||
if (HasBootstrapProblem(file, options, has_opt_codesize_extension)) {
|
||||
return FileOptions::SPEED;
|
||||
}
|
||||
return FileOptions::CODE_SIZE;
|
||||
case EnforceOptimizeMode::kNoEnforcement:
|
||||
if (file->options().optimize_for() == FileOptions::CODE_SIZE) {
|
||||
if (HasBootstrapProblem(file, options, has_opt_codesize_extension)) {
|
||||
GOOGLE_LOG(WARNING) << "Proto states optimize_for = CODE_SIZE, but we "
|
||||
"cannot honor that because it contains custom option "
|
||||
"extensions defined in the same proto.";
|
||||
return FileOptions::SPEED;
|
||||
}
|
||||
}
|
||||
return file->options().optimize_for();
|
||||
}
|
||||
|
||||
GOOGLE_LOG(FATAL) << "Unknown optimization enforcement requested.";
|
||||
// The phony return below serves to silence a warning from GCC 8.
|
||||
return FileOptions::SPEED;
|
||||
}
|
||||
|
||||
} // namespace cpp
|
||||
} // namespace compiler
|
||||
} // namespace protobuf
|
||||
|
@ -83,6 +83,10 @@ extern const char kThinSeparator[];
|
||||
void SetCommonVars(const Options& options,
|
||||
std::map<std::string, std::string>* variables);
|
||||
|
||||
void SetUnknkownFieldsVariable(const Descriptor* descriptor,
|
||||
const Options& options,
|
||||
std::map<std::string, std::string>* variables);
|
||||
|
||||
bool GetBootstrapBasename(const Options& options, const std::string& basename,
|
||||
std::string* bootstrap_basename);
|
||||
bool MaybeBootstrap(const Options& options, GeneratorContext* generator_context,
|
||||
@ -130,6 +134,10 @@ inline std::string ClassName(const EnumDescriptor* descriptor, bool qualified) {
|
||||
: ClassName(descriptor);
|
||||
}
|
||||
|
||||
std::string QualifiedExtensionName(const FieldDescriptor* d,
|
||||
const Options& options);
|
||||
std::string QualifiedExtensionName(const FieldDescriptor* d);
|
||||
|
||||
// Type name of default instance.
|
||||
std::string DefaultInstanceType(const Descriptor* descriptor,
|
||||
const Options& options);
|
||||
@ -339,6 +347,12 @@ inline bool IsLazy(const FieldDescriptor* field, const Options& options) {
|
||||
!options.opensource_runtime;
|
||||
}
|
||||
|
||||
// Returns true if "field" is used.
|
||||
inline bool IsFieldUsed(const FieldDescriptor* /*field*/,
|
||||
const Options& /*options*/) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Does the file contain any definitions that need extension_set.h?
|
||||
bool HasExtensionsOrExtendableMessage(const FileDescriptor* file);
|
||||
|
||||
@ -414,6 +428,12 @@ inline bool HasFieldPresence(const FileDescriptor* file) {
|
||||
return file->syntax() != FileDescriptor::SYNTAX_PROTO3;
|
||||
}
|
||||
|
||||
inline bool HasHasbit(const FieldDescriptor* field) {
|
||||
// TODO(haberman): remove, and give some proto3 fields hasbits.
|
||||
if (field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3) return false;
|
||||
return field->is_singular_with_presence();
|
||||
}
|
||||
|
||||
// Returns true if 'enum' semantics are such that unknown values are preserved
|
||||
// in the enum field itself, rather than going to the UnknownFieldSet.
|
||||
inline bool HasPreservingUnknownEnumSemantics(const FieldDescriptor* field) {
|
||||
@ -475,16 +495,32 @@ inline std::string IncludeGuard(const FileDescriptor* file, bool pb_h,
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the OptimizeMode for this file, furthermore it updates a status
|
||||
// bool if has_opt_codesize_extension is non-null. If this status bool is true
|
||||
// it means this file contains an extension that itself is defined as
|
||||
// optimized_for = CODE_SIZE.
|
||||
FileOptions_OptimizeMode GetOptimizeFor(const FileDescriptor* file,
|
||||
const Options& options,
|
||||
bool* has_opt_codesize_extension);
|
||||
inline FileOptions_OptimizeMode GetOptimizeFor(const FileDescriptor* file,
|
||||
const Options& options) {
|
||||
switch (options.enforce_mode) {
|
||||
case EnforceOptimizeMode::kSpeed:
|
||||
return FileOptions::SPEED;
|
||||
case EnforceOptimizeMode::kLiteRuntime:
|
||||
return FileOptions::LITE_RUNTIME;
|
||||
case EnforceOptimizeMode::kNoEnforcement:
|
||||
default:
|
||||
return file->options().optimize_for();
|
||||
return GetOptimizeFor(file, options, nullptr);
|
||||
}
|
||||
inline bool NeedsEagerDescriptorAssignment(const FileDescriptor* file,
|
||||
const Options& options) {
|
||||
bool has_opt_codesize_extension;
|
||||
if (GetOptimizeFor(file, options, &has_opt_codesize_extension) ==
|
||||
FileOptions::CODE_SIZE &&
|
||||
has_opt_codesize_extension) {
|
||||
// If this filedescriptor contains an extension from another file which
|
||||
// is optimized_for = CODE_SIZE. We need to be careful in the ordering so
|
||||
// we eagerly build the descriptors in the dependencies before building
|
||||
// the descriptors of this file.
|
||||
return true;
|
||||
} else {
|
||||
// If we have a generated code based parser we never need eager
|
||||
// initialization of descriptors of our deps.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -144,6 +144,7 @@ class MessageGenerator {
|
||||
void GenerateSerializeWithCachedSizesBody(io::Printer* printer);
|
||||
void GenerateByteSize(io::Printer* printer);
|
||||
void GenerateMergeFrom(io::Printer* printer);
|
||||
void GenerateClassSpecificMergeFrom(io::Printer* printer);
|
||||
void GenerateCopyFrom(io::Printer* printer);
|
||||
void GenerateSwap(io::Printer* printer);
|
||||
void GenerateIsInitialized(io::Printer* printer);
|
||||
@ -180,6 +181,10 @@ class MessageGenerator {
|
||||
bool copy_constructor) const;
|
||||
|
||||
size_t HasBitsSize() const;
|
||||
int HasBitIndex(const FieldDescriptor* a) const;
|
||||
int HasByteIndex(const FieldDescriptor* a) const;
|
||||
int HasWordIndex(const FieldDescriptor* a) const;
|
||||
bool SameHasByte(const FieldDescriptor* a, const FieldDescriptor* b) const;
|
||||
std::vector<uint32> RequiredFieldsBitMask() const;
|
||||
|
||||
const Descriptor* descriptor_;
|
||||
|
@ -66,10 +66,10 @@ void SetMessageVariables(const FieldDescriptor* descriptor,
|
||||
(*variables)["type_default_instance_ptr"] =
|
||||
QualifiedDefaultInstancePtr(descriptor->message_type(), options);
|
||||
(*variables)["type_reference_function"] =
|
||||
implicit_weak
|
||||
? (" " + (*variables)["proto_ns"] + "::internal::StrongReference(" +
|
||||
(*variables)["type_default_instance"] + ");\n")
|
||||
: "";
|
||||
implicit_weak ? (" ::" + (*variables)["proto_ns"] +
|
||||
"::internal::StrongReference(" +
|
||||
(*variables)["type_default_instance"] + ");\n")
|
||||
: "";
|
||||
// NOTE: Escaped here to unblock proto1->proto2 migration.
|
||||
// TODO(liujisi): Extend this to apply for other conflicting methods.
|
||||
(*variables)["release_name"] =
|
||||
@ -104,17 +104,43 @@ void MessageFieldGenerator::GeneratePrivateMembers(io::Printer* printer) const {
|
||||
void MessageFieldGenerator::GenerateAccessorDeclarations(
|
||||
io::Printer* printer) const {
|
||||
Formatter format(printer, variables_);
|
||||
if (!IsFieldUsed(descriptor_, options_)) {
|
||||
format(
|
||||
"$deprecated_attr$const $type$& ${1$$name$$}$() const { "
|
||||
"__builtin_trap(); }\n"
|
||||
"$deprecated_attr$$type$* ${1$$release_name$$}$() { "
|
||||
"__builtin_trap(); }\n"
|
||||
"$deprecated_attr$$type$* ${1$mutable_$name$$}$() { "
|
||||
"__builtin_trap(); }\n"
|
||||
"$deprecated_attr$void ${1$set_allocated_$name$$}$"
|
||||
"($type$* $name$) { __builtin_trap(); }\n",
|
||||
descriptor_);
|
||||
if (SupportsArenas(descriptor_)) {
|
||||
format(
|
||||
"$deprecated_attr$void "
|
||||
"${1$unsafe_arena_set_allocated_$name$$}$(\n"
|
||||
" $type$* $name$) { __builtin_trap(); }\n"
|
||||
"$deprecated_attr$$type$* ${1$unsafe_arena_release_$name$$}$() { "
|
||||
"__builtin_trap(); }\n",
|
||||
descriptor_);
|
||||
}
|
||||
return;
|
||||
}
|
||||
format(
|
||||
"$deprecated_attr$const $type$& ${1$$name$$}$() const;\n"
|
||||
"$deprecated_attr$$type$* ${1$$release_name$$}$();\n"
|
||||
"$deprecated_attr$$type$* ${1$mutable_$name$$}$();\n"
|
||||
"$deprecated_attr$void ${1$set_allocated_$name$$}$"
|
||||
"($type$* $name$);\n"
|
||||
"private:\n"
|
||||
"const $type$& ${1$_internal_$name$$}$() const;\n"
|
||||
"$type$* ${1$_internal_mutable_$name$$}$();\n"
|
||||
"public:\n",
|
||||
"($type$* $name$);\n",
|
||||
descriptor_);
|
||||
if (IsFieldUsed(descriptor_, options_)) {
|
||||
format(
|
||||
"private:\n"
|
||||
"const $type$& ${1$_internal_$name$$}$() const;\n"
|
||||
"$type$* ${1$_internal_mutable_$name$$}$();\n"
|
||||
"public:\n",
|
||||
descriptor_);
|
||||
}
|
||||
if (SupportsArenas(descriptor_)) {
|
||||
format(
|
||||
"$deprecated_attr$void "
|
||||
@ -127,27 +153,6 @@ void MessageFieldGenerator::GenerateAccessorDeclarations(
|
||||
|
||||
void MessageFieldGenerator::GenerateNonInlineAccessorDefinitions(
|
||||
io::Printer* printer) const {
|
||||
Formatter format(printer, variables_);
|
||||
if (SupportsArenas(descriptor_)) {
|
||||
format(
|
||||
"void $classname$::unsafe_arena_set_allocated_$name$(\n"
|
||||
" $type$* $name$) {\n"
|
||||
"$annotate_accessor$"
|
||||
// If we're not on an arena, free whatever we were holding before.
|
||||
// (If we are on arena, we can just forget the earlier pointer.)
|
||||
" if (GetArenaNoVirtual() == nullptr) {\n"
|
||||
" delete $name$_;\n"
|
||||
" }\n"
|
||||
" $name$_ = $name$;\n"
|
||||
" if ($name$) {\n"
|
||||
" $set_hasbit$\n"
|
||||
" } else {\n"
|
||||
" $clear_hasbit$\n"
|
||||
" }\n"
|
||||
" // @@protoc_insertion_point(field_unsafe_arena_set_allocated"
|
||||
":$full_name$)\n"
|
||||
"}\n");
|
||||
}
|
||||
}
|
||||
|
||||
void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
@ -167,10 +172,35 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
"}\n");
|
||||
|
||||
if (SupportsArenas(descriptor_)) {
|
||||
format(
|
||||
"inline void $classname$::unsafe_arena_set_allocated_$name$(\n"
|
||||
" $type$* $name$) {\n"
|
||||
"$annotate_accessor$"
|
||||
// If we're not on an arena, free whatever we were holding before.
|
||||
// (If we are on arena, we can just forget the earlier pointer.)
|
||||
" if (GetArena() == nullptr) {\n"
|
||||
" delete reinterpret_cast<::$proto_ns$::MessageLite*>($name$_);\n"
|
||||
" }\n");
|
||||
if (implicit_weak_field_) {
|
||||
format(
|
||||
" $name$_ = "
|
||||
"reinterpret_cast<::$proto_ns$::MessageLite*>($name$);\n");
|
||||
} else {
|
||||
format(" $name$_ = $name$;\n");
|
||||
}
|
||||
format(
|
||||
" if ($name$) {\n"
|
||||
" $set_hasbit$\n"
|
||||
" } else {\n"
|
||||
" $clear_hasbit$\n"
|
||||
" }\n"
|
||||
" // @@protoc_insertion_point(field_unsafe_arena_set_allocated"
|
||||
":$full_name$)\n"
|
||||
"}\n");
|
||||
format(
|
||||
"inline $type$* $classname$::$release_name$() {\n"
|
||||
" auto temp = unsafe_arena_release_$name$();\n"
|
||||
" if (GetArenaNoVirtual() != nullptr) {\n"
|
||||
" if (GetArena() != nullptr) {\n"
|
||||
" temp = ::$proto_ns$::internal::DuplicateIfNonNull(temp);\n"
|
||||
" }\n"
|
||||
" return temp;\n"
|
||||
@ -194,7 +224,7 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
"$type_reference_function$"
|
||||
" $set_hasbit$\n"
|
||||
" if ($name$_ == nullptr) {\n"
|
||||
" auto* p = CreateMaybeMessage<$type$>(GetArenaNoVirtual());\n");
|
||||
" auto* p = CreateMaybeMessage<$type$>(GetArena());\n");
|
||||
if (implicit_weak_field_) {
|
||||
format(" $name$_ = reinterpret_cast<::$proto_ns$::MessageLite*>(p);\n");
|
||||
} else {
|
||||
@ -215,7 +245,7 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
format(
|
||||
"inline void $classname$::set_allocated_$name$($type$* $name$) {\n"
|
||||
"$annotate_accessor$"
|
||||
" ::$proto_ns$::Arena* message_arena = GetArenaNoVirtual();\n");
|
||||
" ::$proto_ns$::Arena* message_arena = GetArena();\n");
|
||||
format(" if (message_arena == nullptr) {\n");
|
||||
if (IsCrossFileMessage(descriptor_)) {
|
||||
format(
|
||||
@ -309,12 +339,11 @@ void MessageFieldGenerator::GenerateInternalAccessorDefinitions(
|
||||
" if ($type_default_instance_ptr$ == nullptr) {\n"
|
||||
" msg->$name$_ = ::$proto_ns$::Arena::CreateMessage<\n"
|
||||
" ::$proto_ns$::internal::ImplicitWeakMessage>(\n"
|
||||
" msg->GetArenaNoVirtual());\n"
|
||||
" msg->GetArena());\n"
|
||||
" } else {\n"
|
||||
" msg->$name$_ = reinterpret_cast<const "
|
||||
"::$proto_ns$::MessageLite*>(\n"
|
||||
" $type_default_instance_ptr$)->New("
|
||||
"msg->GetArenaNoVirtual());\n"
|
||||
" $type_default_instance_ptr$)->New(msg->GetArena());\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" return msg->$name$_;\n"
|
||||
@ -353,12 +382,14 @@ void MessageFieldGenerator::GenerateInternalAccessorDefinitions(
|
||||
}
|
||||
|
||||
void MessageFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
|
||||
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
|
||||
|
||||
Formatter format(printer, variables_);
|
||||
if (!HasFieldPresence(descriptor_->file())) {
|
||||
// If we don't have has-bits, message presence is indicated only by ptr !=
|
||||
// NULL. Thus on clear, we need to delete the object.
|
||||
format(
|
||||
"if (GetArenaNoVirtual() == nullptr && $name$_ != nullptr) {\n"
|
||||
"if (GetArena() == nullptr && $name$_ != nullptr) {\n"
|
||||
" delete $name$_;\n"
|
||||
"}\n"
|
||||
"$name$_ = nullptr;\n");
|
||||
@ -369,12 +400,14 @@ void MessageFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
|
||||
|
||||
void MessageFieldGenerator::GenerateMessageClearingCode(
|
||||
io::Printer* printer) const {
|
||||
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
|
||||
|
||||
Formatter format(printer, variables_);
|
||||
if (!HasFieldPresence(descriptor_->file())) {
|
||||
// If we don't have has-bits, message presence is indicated only by ptr !=
|
||||
// NULL. Thus on clear, we need to delete the object.
|
||||
format(
|
||||
"if (GetArenaNoVirtual() == nullptr && $name$_ != nullptr) {\n"
|
||||
"if (GetArena() == nullptr && $name$_ != nullptr) {\n"
|
||||
" delete $name$_;\n"
|
||||
"}\n"
|
||||
"$name$_ = nullptr;\n");
|
||||
@ -386,6 +419,8 @@ void MessageFieldGenerator::GenerateMessageClearingCode(
|
||||
}
|
||||
|
||||
void MessageFieldGenerator::GenerateMergingCode(io::Printer* printer) const {
|
||||
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
|
||||
|
||||
Formatter format(printer, variables_);
|
||||
if (implicit_weak_field_) {
|
||||
format(
|
||||
@ -399,11 +434,15 @@ void MessageFieldGenerator::GenerateMergingCode(io::Printer* printer) const {
|
||||
}
|
||||
|
||||
void MessageFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
|
||||
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
|
||||
|
||||
Formatter format(printer, variables_);
|
||||
format("swap($name$_, other->$name$_);\n");
|
||||
}
|
||||
|
||||
void MessageFieldGenerator::GenerateDestructorCode(io::Printer* printer) const {
|
||||
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
|
||||
|
||||
Formatter format(printer, variables_);
|
||||
if (options_.opensource_runtime) {
|
||||
// TODO(gerbens) Remove this when we don't need to destruct default
|
||||
@ -418,12 +457,16 @@ void MessageFieldGenerator::GenerateDestructorCode(io::Printer* printer) const {
|
||||
|
||||
void MessageFieldGenerator::GenerateConstructorCode(
|
||||
io::Printer* printer) const {
|
||||
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
|
||||
|
||||
Formatter format(printer, variables_);
|
||||
format("$name$_ = nullptr;\n");
|
||||
}
|
||||
|
||||
void MessageFieldGenerator::GenerateCopyConstructorCode(
|
||||
io::Printer* printer) const {
|
||||
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
|
||||
|
||||
Formatter format(printer, variables_);
|
||||
format(
|
||||
"if (from._internal_has_$name$()) {\n"
|
||||
@ -435,6 +478,8 @@ void MessageFieldGenerator::GenerateCopyConstructorCode(
|
||||
|
||||
void MessageFieldGenerator::GenerateSerializeWithCachedSizesToArray(
|
||||
io::Printer* printer) const {
|
||||
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
|
||||
|
||||
Formatter format(printer, variables_);
|
||||
format(
|
||||
"target = stream->EnsureSpace(target);\n"
|
||||
@ -444,6 +489,8 @@ void MessageFieldGenerator::GenerateSerializeWithCachedSizesToArray(
|
||||
}
|
||||
|
||||
void MessageFieldGenerator::GenerateByteSize(io::Printer* printer) const {
|
||||
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
|
||||
|
||||
Formatter format(printer, variables_);
|
||||
format(
|
||||
"total_size += $tag_size$ +\n"
|
||||
@ -468,7 +515,7 @@ void MessageOneofFieldGenerator::GenerateNonInlineAccessorDefinitions(
|
||||
format(
|
||||
"void $classname$::set_allocated_$name$($type$* $name$) {\n"
|
||||
"$annotate_accessor$"
|
||||
" ::$proto_ns$::Arena* message_arena = GetArenaNoVirtual();\n"
|
||||
" ::$proto_ns$::Arena* message_arena = GetArena();\n"
|
||||
" clear_$oneof_name$();\n"
|
||||
" if ($name$) {\n");
|
||||
if (SupportsArenas(descriptor_->message_type()) &&
|
||||
@ -510,7 +557,7 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
" $type$* temp = $field_member$;\n");
|
||||
if (SupportsArenas(descriptor_)) {
|
||||
format(
|
||||
" if (GetArenaNoVirtual() != nullptr) {\n"
|
||||
" if (GetArena() != nullptr) {\n"
|
||||
" temp = ::$proto_ns$::internal::DuplicateIfNonNull(temp);\n"
|
||||
" }\n");
|
||||
}
|
||||
@ -570,8 +617,7 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
" if (!_internal_has_$name$()) {\n"
|
||||
" clear_$oneof_name$();\n"
|
||||
" set_has_$name$();\n"
|
||||
" $field_member$ = CreateMaybeMessage< $type$ >(\n"
|
||||
" GetArenaNoVirtual());\n"
|
||||
" $field_member$ = CreateMaybeMessage< $type$ >(GetArena());\n"
|
||||
" }\n"
|
||||
" return $field_member$;\n"
|
||||
"}\n"
|
||||
@ -584,10 +630,12 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
|
||||
void MessageOneofFieldGenerator::GenerateClearingCode(
|
||||
io::Printer* printer) const {
|
||||
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
|
||||
|
||||
Formatter format(printer, variables_);
|
||||
if (SupportsArenas(descriptor_)) {
|
||||
format(
|
||||
"if (GetArenaNoVirtual() == nullptr) {\n"
|
||||
"if (GetArena() == nullptr) {\n"
|
||||
" delete $field_member$;\n"
|
||||
"}\n");
|
||||
} else {
|
||||
@ -643,14 +691,35 @@ void RepeatedMessageFieldGenerator::GeneratePrivateMembers(
|
||||
void RepeatedMessageFieldGenerator::GenerateAccessorDeclarations(
|
||||
io::Printer* printer) const {
|
||||
Formatter format(printer, variables_);
|
||||
if (!IsFieldUsed(descriptor_, options_)) {
|
||||
format(
|
||||
"$deprecated_attr$$type$* ${1$mutable_$name$$}$(int index) { "
|
||||
"__builtin_trap(); }\n"
|
||||
"$deprecated_attr$::$proto_ns$::RepeatedPtrField< $type$ >*\n"
|
||||
" ${1$mutable_$name$$}$() { __builtin_trap(); }\n"
|
||||
"$deprecated_attr$const $type$& ${1$$name$$}$(int index) const { "
|
||||
"__builtin_trap(); }\n"
|
||||
"$deprecated_attr$$type$* ${1$add_$name$$}$() { "
|
||||
"__builtin_trap(); }\n"
|
||||
"$deprecated_attr$const ::$proto_ns$::RepeatedPtrField< $type$ >&\n"
|
||||
" ${1$$name$$}$() const { __builtin_trap(); }\n",
|
||||
descriptor_);
|
||||
return;
|
||||
}
|
||||
format(
|
||||
"$deprecated_attr$$type$* ${1$mutable_$name$$}$(int index);\n"
|
||||
"$deprecated_attr$::$proto_ns$::RepeatedPtrField< $type$ >*\n"
|
||||
" ${1$mutable_$name$$}$();\n"
|
||||
"private:\n"
|
||||
"const $type$& ${1$_internal_$name$$}$(int index) const;\n"
|
||||
"$type$* ${1$_internal_add_$name$$}$();\n"
|
||||
"public:\n"
|
||||
" ${1$mutable_$name$$}$();\n",
|
||||
descriptor_);
|
||||
if (IsFieldUsed(descriptor_, options_)) {
|
||||
format(
|
||||
"private:\n"
|
||||
"const $type$& ${1$_internal_$name$$}$(int index) const;\n"
|
||||
"$type$* ${1$_internal_add_$name$$}$();\n"
|
||||
"public:\n",
|
||||
descriptor_);
|
||||
}
|
||||
format(
|
||||
"$deprecated_attr$const $type$& ${1$$name$$}$(int index) const;\n"
|
||||
"$deprecated_attr$$type$* ${1$add_$name$$}$();\n"
|
||||
"$deprecated_attr$const ::$proto_ns$::RepeatedPtrField< $type$ >&\n"
|
||||
@ -722,18 +791,24 @@ void RepeatedMessageFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
|
||||
void RepeatedMessageFieldGenerator::GenerateClearingCode(
|
||||
io::Printer* printer) const {
|
||||
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
|
||||
|
||||
Formatter format(printer, variables_);
|
||||
format("$name$_.Clear();\n");
|
||||
}
|
||||
|
||||
void RepeatedMessageFieldGenerator::GenerateMergingCode(
|
||||
io::Printer* printer) const {
|
||||
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
|
||||
|
||||
Formatter format(printer, variables_);
|
||||
format("$name$_.MergeFrom(from.$name$_);\n");
|
||||
}
|
||||
|
||||
void RepeatedMessageFieldGenerator::GenerateSwappingCode(
|
||||
io::Printer* printer) const {
|
||||
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
|
||||
|
||||
Formatter format(printer, variables_);
|
||||
format("$name$_.InternalSwap(&other->$name$_);\n");
|
||||
}
|
||||
@ -745,6 +820,8 @@ void RepeatedMessageFieldGenerator::GenerateConstructorCode(
|
||||
|
||||
void RepeatedMessageFieldGenerator::GenerateSerializeWithCachedSizesToArray(
|
||||
io::Printer* printer) const {
|
||||
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
|
||||
|
||||
Formatter format(printer, variables_);
|
||||
if (implicit_weak_field_) {
|
||||
format(
|
||||
@ -770,6 +847,8 @@ void RepeatedMessageFieldGenerator::GenerateSerializeWithCachedSizesToArray(
|
||||
|
||||
void RepeatedMessageFieldGenerator::GenerateByteSize(
|
||||
io::Printer* printer) const {
|
||||
GOOGLE_CHECK(IsFieldUsed(descriptor_, options_));
|
||||
|
||||
Formatter format(printer, variables_);
|
||||
format(
|
||||
"total_size += $tag_size$UL * this->_internal_$name$_size();\n"
|
||||
|
@ -44,7 +44,8 @@ namespace cpp {
|
||||
|
||||
enum class EnforceOptimizeMode {
|
||||
kNoEnforcement, // Use the runtime specified by the file specific options.
|
||||
kSpeed, // This is the full runtime.
|
||||
kSpeed, // Full runtime with a generated code implementation.
|
||||
kCodeSize, // Full runtime with a reflective implementation.
|
||||
kLiteRuntime,
|
||||
};
|
||||
|
||||
@ -62,6 +63,7 @@ struct Options {
|
||||
bool bootstrap = false;
|
||||
bool opensource_runtime = false;
|
||||
bool annotate_accessor = false;
|
||||
bool unused_field_stripping = false;
|
||||
std::string runtime_include_base;
|
||||
int num_cc_files = 0;
|
||||
std::string annotation_pragma_name;
|
||||
|
@ -237,13 +237,13 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
"inline void $classname$::_internal_set_$name$(const std::string& "
|
||||
"value) {\n"
|
||||
" $set_hasbit$\n"
|
||||
" $name$_.Set$lite$($default_variable$, value, GetArenaNoVirtual());\n"
|
||||
" $name$_.Set$lite$($default_variable$, value, GetArena());\n"
|
||||
"}\n"
|
||||
"inline void $classname$::set_$name$(std::string&& value) {\n"
|
||||
"$annotate_accessor$"
|
||||
" $set_hasbit$\n"
|
||||
" $name$_.Set$lite$(\n"
|
||||
" $default_variable$, ::std::move(value), GetArenaNoVirtual());\n"
|
||||
" $default_variable$, ::std::move(value), GetArena());\n"
|
||||
" // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n"
|
||||
"}\n"
|
||||
"inline void $classname$::set_$name$(const char* value) {\n"
|
||||
@ -251,7 +251,7 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
" $null_check$"
|
||||
" $set_hasbit$\n"
|
||||
" $name$_.Set$lite$($default_variable$, $string_piece$(value),\n"
|
||||
" GetArenaNoVirtual());\n"
|
||||
" GetArena());\n"
|
||||
" // @@protoc_insertion_point(field_set_char:$full_name$)\n"
|
||||
"}\n");
|
||||
if (!options_.opensource_runtime) {
|
||||
@ -259,8 +259,7 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
"inline void $classname$::set_$name$(::StringPiece value) {\n"
|
||||
"$annotate_accessor$"
|
||||
" $set_hasbit$\n"
|
||||
" $name$_.Set$lite$($default_variable$, value, "
|
||||
"GetArenaNoVirtual());\n"
|
||||
" $name$_.Set$lite$($default_variable$, value,GetArena());\n"
|
||||
" // @@protoc_insertion_point(field_set_string_piece:$full_name$)\n"
|
||||
"}\n");
|
||||
}
|
||||
@ -271,13 +270,12 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
"$annotate_accessor$"
|
||||
" $set_hasbit$\n"
|
||||
" $name$_.Set$lite$($default_variable$, $string_piece$(\n"
|
||||
" reinterpret_cast<const char*>(value), size), "
|
||||
"GetArenaNoVirtual());\n"
|
||||
" reinterpret_cast<const char*>(value), size), GetArena());\n"
|
||||
" // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
|
||||
"}\n"
|
||||
"inline std::string* $classname$::_internal_mutable_$name$() {\n"
|
||||
" $set_hasbit$\n"
|
||||
" return $name$_.Mutable($default_variable$, GetArenaNoVirtual());\n"
|
||||
" return $name$_.Mutable($default_variable$, GetArena());\n"
|
||||
"}\n"
|
||||
"inline std::string* $classname$::$release_name$() {\n"
|
||||
"$annotate_accessor$"
|
||||
@ -290,12 +288,11 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
" }\n"
|
||||
" $clear_hasbit$\n"
|
||||
" return $name$_.ReleaseNonDefault("
|
||||
"$default_variable$, GetArenaNoVirtual());\n");
|
||||
"$default_variable$, GetArena());\n");
|
||||
} else {
|
||||
format(
|
||||
" $clear_hasbit$\n"
|
||||
" return $name$_.Release($default_variable$, "
|
||||
"GetArenaNoVirtual());\n");
|
||||
" return $name$_.Release($default_variable$, GetArena());\n");
|
||||
}
|
||||
|
||||
format(
|
||||
@ -308,7 +305,7 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
" $clear_hasbit$\n"
|
||||
" }\n"
|
||||
" $name$_.SetAllocated($default_variable$, $name$,\n"
|
||||
" GetArenaNoVirtual());\n"
|
||||
" GetArena());\n"
|
||||
" // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
|
||||
"}\n");
|
||||
if (options_.opensource_runtime) {
|
||||
@ -317,22 +314,22 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
"$annotate_accessor$"
|
||||
" // "
|
||||
"@@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n"
|
||||
" $DCHK$(GetArenaNoVirtual() != nullptr);\n"
|
||||
" $DCHK$(GetArena() != nullptr);\n"
|
||||
" $clear_hasbit$\n"
|
||||
" return $name$_.UnsafeArenaRelease($default_variable$,\n"
|
||||
" GetArenaNoVirtual());\n"
|
||||
" GetArena());\n"
|
||||
"}\n"
|
||||
"inline void $classname$::unsafe_arena_set_allocated_$name$(\n"
|
||||
"$annotate_accessor$"
|
||||
" std::string* $name$) {\n"
|
||||
" $DCHK$(GetArenaNoVirtual() != nullptr);\n"
|
||||
" $DCHK$(GetArena() != nullptr);\n"
|
||||
" if ($name$ != nullptr) {\n"
|
||||
" $set_hasbit$\n"
|
||||
" } else {\n"
|
||||
" $clear_hasbit$\n"
|
||||
" }\n"
|
||||
" $name$_.UnsafeArenaSetAllocated($default_variable$,\n"
|
||||
" $name$, GetArenaNoVirtual());\n"
|
||||
" $name$, GetArena());\n"
|
||||
" // @@protoc_insertion_point(field_unsafe_arena_set_allocated:"
|
||||
"$full_name$)\n"
|
||||
"}\n");
|
||||
@ -436,11 +433,9 @@ void StringFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
|
||||
// below methods are inlined one-liners)!
|
||||
if (SupportsArenas(descriptor_)) {
|
||||
if (descriptor_->default_value_string().empty()) {
|
||||
format(
|
||||
"$name$_.ClearToEmpty($default_variable$, GetArenaNoVirtual());\n");
|
||||
format("$name$_.ClearToEmpty($default_variable$, GetArena());\n");
|
||||
} else {
|
||||
format(
|
||||
"$name$_.ClearToDefault($default_variable$, GetArenaNoVirtual());\n");
|
||||
format("$name$_.ClearToDefault($default_variable$, GetArena());\n");
|
||||
}
|
||||
} else {
|
||||
if (descriptor_->default_value_string().empty()) {
|
||||
@ -481,14 +476,12 @@ void StringFieldGenerator::GenerateMessageClearingCode(
|
||||
if (must_be_present) {
|
||||
format("$name$_.ClearNonDefaultToEmpty();\n");
|
||||
} else {
|
||||
format(
|
||||
"$name$_.ClearToEmpty($default_variable$, GetArenaNoVirtual());\n");
|
||||
format("$name$_.ClearToEmpty($default_variable$, GetArena());\n");
|
||||
}
|
||||
} else {
|
||||
// Clear to a non-empty default is more involved, as we try to use the
|
||||
// Arena if one is present and may need to reallocate the string.
|
||||
format(
|
||||
"$name$_.ClearToDefault($default_variable$, GetArenaNoVirtual());\n");
|
||||
format("$name$_.ClearToDefault($default_variable$, GetArena());\n");
|
||||
}
|
||||
} else if (must_be_present) {
|
||||
// When Arenas are disabled and field presence has been checked, we can
|
||||
@ -524,9 +517,7 @@ void StringFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
|
||||
if (inlined_) {
|
||||
format("$name$_.Swap(&other->$name$_);\n");
|
||||
} else {
|
||||
format(
|
||||
"$name$_.Swap(&other->$name$_, $default_variable$,\n"
|
||||
" GetArenaNoVirtual());\n");
|
||||
format("$name$_.Swap(&other->$name$_, $default_variable$, GetArena());\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -559,7 +550,7 @@ void StringFieldGenerator::GenerateCopyConstructorCode(
|
||||
// TODO(gpike): improve this
|
||||
format(
|
||||
"$name$_.Set$lite$($default_variable$, from._internal_$name$(),\n"
|
||||
" GetArenaNoVirtual());\n");
|
||||
" GetArena());\n");
|
||||
} else {
|
||||
format("$name$_.AssignWithDefault($default_variable$, from.$name$_);\n");
|
||||
}
|
||||
@ -682,8 +673,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
" set_has_$name$();\n"
|
||||
" $field_member$.UnsafeSetDefault($default_variable$);\n"
|
||||
" }\n"
|
||||
" $field_member$.Set$lite$($default_variable$, value,\n"
|
||||
" GetArenaNoVirtual());\n"
|
||||
" $field_member$.Set$lite$($default_variable$, value, GetArena());\n"
|
||||
"}\n"
|
||||
"inline void $classname$::set_$name$(std::string&& value) {\n"
|
||||
"$annotate_accessor$"
|
||||
@ -694,7 +684,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
" $field_member$.UnsafeSetDefault($default_variable$);\n"
|
||||
" }\n"
|
||||
" $field_member$.Set$lite$(\n"
|
||||
" $default_variable$, ::std::move(value), GetArenaNoVirtual());\n"
|
||||
" $default_variable$, ::std::move(value), GetArena());\n"
|
||||
" // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n"
|
||||
"}\n"
|
||||
"inline void $classname$::set_$name$(const char* value) {\n"
|
||||
@ -706,7 +696,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
" $field_member$.UnsafeSetDefault($default_variable$);\n"
|
||||
" }\n"
|
||||
" $field_member$.Set$lite$($default_variable$,\n"
|
||||
" $string_piece$(value), GetArenaNoVirtual());\n"
|
||||
" $string_piece$(value), GetArena());\n"
|
||||
" // @@protoc_insertion_point(field_set_char:$full_name$)\n"
|
||||
"}\n");
|
||||
if (!options_.opensource_runtime) {
|
||||
@ -719,7 +709,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
" $field_member$.UnsafeSetDefault($default_variable$);\n"
|
||||
" }\n"
|
||||
" $field_member$.Set$lite$($default_variable$, value,\n"
|
||||
" GetArenaNoVirtual());\n"
|
||||
" GetArena());\n"
|
||||
" // @@protoc_insertion_point(field_set_string_piece:$full_name$)\n"
|
||||
"}\n");
|
||||
}
|
||||
@ -736,7 +726,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
" $field_member$.Set$lite$(\n"
|
||||
" $default_variable$, $string_piece$(\n"
|
||||
" reinterpret_cast<const char*>(value), size),\n"
|
||||
" GetArenaNoVirtual());\n"
|
||||
" GetArena());\n"
|
||||
" // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
|
||||
"}\n"
|
||||
"inline std::string* $classname$::_internal_mutable_$name$() {\n"
|
||||
@ -745,16 +735,14 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
" set_has_$name$();\n"
|
||||
" $field_member$.UnsafeSetDefault($default_variable$);\n"
|
||||
" }\n"
|
||||
" return $field_member$.Mutable($default_variable$,\n"
|
||||
" GetArenaNoVirtual());\n"
|
||||
" return $field_member$.Mutable($default_variable$, GetArena());\n"
|
||||
"}\n"
|
||||
"inline std::string* $classname$::$release_name$() {\n"
|
||||
"$annotate_accessor$"
|
||||
" // @@protoc_insertion_point(field_release:$full_name$)\n"
|
||||
" if (_internal_has_$name$()) {\n"
|
||||
" clear_has_$oneof_name$();\n"
|
||||
" return $field_member$.Release($default_variable$,\n"
|
||||
" GetArenaNoVirtual());\n"
|
||||
" return $field_member$.Release($default_variable$, GetArena());\n"
|
||||
" } else {\n"
|
||||
" return nullptr;\n"
|
||||
" }\n"
|
||||
@ -776,11 +764,11 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
"$annotate_accessor$"
|
||||
" // "
|
||||
"@@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n"
|
||||
" $DCHK$(GetArenaNoVirtual() != nullptr);\n"
|
||||
" $DCHK$(GetArena() != nullptr);\n"
|
||||
" if (_internal_has_$name$()) {\n"
|
||||
" clear_has_$oneof_name$();\n"
|
||||
" return $field_member$.UnsafeArenaRelease(\n"
|
||||
" $default_variable$, GetArenaNoVirtual());\n"
|
||||
" $default_variable$, GetArena());\n"
|
||||
" } else {\n"
|
||||
" return nullptr;\n"
|
||||
" }\n"
|
||||
@ -788,7 +776,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
"inline void $classname$::unsafe_arena_set_allocated_$name$("
|
||||
"std::string* $name$) {\n"
|
||||
"$annotate_accessor$"
|
||||
" $DCHK$(GetArenaNoVirtual() != nullptr);\n"
|
||||
" $DCHK$(GetArena() != nullptr);\n"
|
||||
" if (!_internal_has_$name$()) {\n"
|
||||
" $field_member$.UnsafeSetDefault($default_variable$);\n"
|
||||
" }\n"
|
||||
@ -796,7 +784,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
|
||||
" if ($name$) {\n"
|
||||
" set_has_$name$();\n"
|
||||
" $field_member$.UnsafeArenaSetAllocated($default_variable$, "
|
||||
"$name$, GetArenaNoVirtual());\n"
|
||||
"$name$, GetArena());\n"
|
||||
" }\n"
|
||||
" // @@protoc_insertion_point(field_unsafe_arena_set_allocated:"
|
||||
"$full_name$)\n"
|
||||
@ -906,9 +894,7 @@ void StringOneofFieldGenerator::GenerateClearingCode(
|
||||
io::Printer* printer) const {
|
||||
Formatter format(printer, variables_);
|
||||
if (SupportsArenas(descriptor_)) {
|
||||
format(
|
||||
"$field_member$.Destroy($default_variable$,\n"
|
||||
" GetArenaNoVirtual());\n");
|
||||
format("$field_member$.Destroy($default_variable$, GetArena());\n");
|
||||
} else {
|
||||
format("$field_member$.DestroyNoArena($default_variable$);\n");
|
||||
}
|
||||
|
@ -100,8 +100,8 @@ class MockErrorCollector : public MultiFileErrorCollector {
|
||||
// implements ErrorCollector ---------------------------------------
|
||||
void AddError(const std::string& filename, int line, int column,
|
||||
const std::string& message) {
|
||||
strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n",
|
||||
filename, line, column, message);
|
||||
strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column,
|
||||
message);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -231,8 +231,9 @@ const FileDescriptor* Importer::Import(const std::string& filename) {
|
||||
return pool_.FindFileByName(filename);
|
||||
}
|
||||
|
||||
void Importer::AddUnusedImportTrackFile(const std::string& file_name) {
|
||||
pool_.AddUnusedImportTrackFile(file_name);
|
||||
void Importer::AddUnusedImportTrackFile(const std::string& file_name,
|
||||
bool is_error) {
|
||||
pool_.AddUnusedImportTrackFile(file_name, is_error);
|
||||
}
|
||||
|
||||
void Importer::ClearUnusedImportTrackFiles() {
|
||||
|
@ -178,7 +178,8 @@ class PROTOBUF_EXPORT Importer {
|
||||
// contents are stored.
|
||||
inline const DescriptorPool* pool() const { return &pool_; }
|
||||
|
||||
void AddUnusedImportTrackFile(const std::string& file_name);
|
||||
void AddUnusedImportTrackFile(const std::string& file_name,
|
||||
bool is_error = false);
|
||||
void ClearUnusedImportTrackFiles();
|
||||
|
||||
|
||||
|
@ -74,14 +74,14 @@ class MockErrorCollector : public MultiFileErrorCollector {
|
||||
// implements ErrorCollector ---------------------------------------
|
||||
void AddError(const std::string& filename, int line, int column,
|
||||
const std::string& message) {
|
||||
strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line,
|
||||
column, message);
|
||||
strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column,
|
||||
message);
|
||||
}
|
||||
|
||||
void AddWarning(const std::string& filename, int line, int column,
|
||||
const std::string& message) {
|
||||
strings::SubstituteAndAppend(&warning_text_, "$0:$1:$2: $3\n", filename,
|
||||
line, column, message);
|
||||
strings::SubstituteAndAppend(&warning_text_, "$0:$1:$2: $3\n", filename, line,
|
||||
column, message);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -228,7 +228,25 @@ void EnumGenerator::Generate(io::Printer* printer) {
|
||||
if (HasDescriptorMethods(descriptor_, context_->EnforceLite())) {
|
||||
printer->Print(
|
||||
"public final com.google.protobuf.Descriptors.EnumValueDescriptor\n"
|
||||
" getValueDescriptor() {\n"
|
||||
" getValueDescriptor() {\n");
|
||||
if (SupportUnknownEnumValue(descriptor_->file())) {
|
||||
if (ordinal_is_index) {
|
||||
printer->Print(
|
||||
" if (this == UNRECOGNIZED) {\n"
|
||||
" throw new java.lang.IllegalStateException(\n"
|
||||
" \"Can't get the descriptor of an unrecognized enum "
|
||||
"value.\");\n"
|
||||
" }\n");
|
||||
} else {
|
||||
printer->Print(
|
||||
" if (index == -1) {\n"
|
||||
" throw new java.lang.IllegalStateException(\n"
|
||||
" \"Can't get the descriptor of an unrecognized enum "
|
||||
"value.\");\n"
|
||||
" }\n");
|
||||
}
|
||||
}
|
||||
printer->Print(
|
||||
" return getDescriptor().getValues().get($index_text$);\n"
|
||||
"}\n"
|
||||
"public final com.google.protobuf.Descriptors.EnumDescriptor\n"
|
||||
@ -279,15 +297,22 @@ void EnumGenerator::Generate(io::Printer* printer) {
|
||||
// for every enum.
|
||||
printer->Print("values();\n");
|
||||
} else {
|
||||
printer->Print("getStaticValuesArray();\n");
|
||||
printer->Print("private static $classname$[] getStaticValuesArray() {\n",
|
||||
"classname", descriptor_->name());
|
||||
printer->Indent();
|
||||
printer->Print(
|
||||
"{\n"
|
||||
" ");
|
||||
"return new $classname$[] {\n"
|
||||
" ",
|
||||
"classname", descriptor_->name());
|
||||
for (int i = 0; i < descriptor_->value_count(); i++) {
|
||||
printer->Print("$name$, ", "name", descriptor_->value(i)->name());
|
||||
}
|
||||
printer->Print(
|
||||
"\n"
|
||||
"};\n");
|
||||
printer->Outdent();
|
||||
printer->Print("}");
|
||||
}
|
||||
|
||||
printer->Print(
|
||||
|
@ -81,7 +81,7 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
|
||||
// with v2.5.0/v2.6.1, and remove the @SuppressWarnings annotations.
|
||||
(*variables)["for_number"] = "valueOf";
|
||||
|
||||
if (SupportFieldPresence(descriptor->file())) {
|
||||
if (SupportFieldPresence(descriptor)) {
|
||||
// For singular messages and builders, one bit is used for the hasField bit.
|
||||
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);
|
||||
(*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex);
|
||||
@ -145,7 +145,7 @@ ImmutableEnumFieldGenerator::ImmutableEnumFieldGenerator(
|
||||
ImmutableEnumFieldGenerator::~ImmutableEnumFieldGenerator() {}
|
||||
|
||||
int ImmutableEnumFieldGenerator::GetNumBitsForMessage() const {
|
||||
return SupportFieldPresence(descriptor_->file()) ? 1 : 0;
|
||||
return SupportFieldPresence(descriptor_) ? 1 : 0;
|
||||
}
|
||||
|
||||
int ImmutableEnumFieldGenerator::GetNumBitsForBuilder() const {
|
||||
@ -154,7 +154,7 @@ int ImmutableEnumFieldGenerator::GetNumBitsForBuilder() const {
|
||||
|
||||
void ImmutableEnumFieldGenerator::GenerateInterfaceMembers(
|
||||
io::Printer* printer) const {
|
||||
if (SupportFieldPresence(descriptor_->file())) {
|
||||
if (SupportFieldPresence(descriptor_)) {
|
||||
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
|
||||
printer->Print(variables_,
|
||||
"$deprecation$boolean has$capitalized_name$();\n");
|
||||
@ -171,27 +171,28 @@ void ImmutableEnumFieldGenerator::GenerateInterfaceMembers(
|
||||
void ImmutableEnumFieldGenerator::GenerateMembers(io::Printer* printer) const {
|
||||
printer->Print(variables_, "private int $name$_;\n");
|
||||
PrintExtraFieldInfo(variables_, printer);
|
||||
if (SupportFieldPresence(descriptor_->file())) {
|
||||
if (SupportFieldPresence(descriptor_)) {
|
||||
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
|
||||
printer->Print(
|
||||
variables_,
|
||||
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
|
||||
" return $get_has_field_bit_message$;\n"
|
||||
"}\n");
|
||||
printer->Print(variables_,
|
||||
"@java.lang.Override $deprecation$public boolean "
|
||||
"${$has$capitalized_name$$}$() {\n"
|
||||
" return $get_has_field_bit_message$;\n"
|
||||
"}\n");
|
||||
printer->Annotate("{", "}", descriptor_);
|
||||
}
|
||||
if (SupportUnknownEnumValue(descriptor_->file())) {
|
||||
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER);
|
||||
printer->Print(
|
||||
variables_,
|
||||
"$deprecation$public int ${$get$capitalized_name$Value$}$() {\n"
|
||||
" return $name$_;\n"
|
||||
"}\n");
|
||||
printer->Print(variables_,
|
||||
"@java.lang.Override $deprecation$public int "
|
||||
"${$get$capitalized_name$Value$}$() {\n"
|
||||
" return $name$_;\n"
|
||||
"}\n");
|
||||
printer->Annotate("{", "}", descriptor_);
|
||||
}
|
||||
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
|
||||
printer->Print(variables_,
|
||||
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
|
||||
"@java.lang.Override $deprecation$public $type$ "
|
||||
"${$get$capitalized_name$$}$() {\n"
|
||||
" @SuppressWarnings(\"deprecation\")\n"
|
||||
" $type$ result = $type$.$for_number$($name$_);\n"
|
||||
" return result == null ? $unknown$ : result;\n"
|
||||
@ -202,22 +203,22 @@ void ImmutableEnumFieldGenerator::GenerateMembers(io::Printer* printer) const {
|
||||
void ImmutableEnumFieldGenerator::GenerateBuilderMembers(
|
||||
io::Printer* printer) const {
|
||||
printer->Print(variables_, "private int $name$_ = $default_number$;\n");
|
||||
if (SupportFieldPresence(descriptor_->file())) {
|
||||
if (SupportFieldPresence(descriptor_)) {
|
||||
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
|
||||
printer->Print(
|
||||
variables_,
|
||||
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
|
||||
" return $get_has_field_bit_builder$;\n"
|
||||
"}\n");
|
||||
printer->Print(variables_,
|
||||
"@java.lang.Override $deprecation$public boolean "
|
||||
"${$has$capitalized_name$$}$() {\n"
|
||||
" return $get_has_field_bit_builder$;\n"
|
||||
"}\n");
|
||||
printer->Annotate("{", "}", descriptor_);
|
||||
}
|
||||
if (SupportUnknownEnumValue(descriptor_->file())) {
|
||||
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER);
|
||||
printer->Print(
|
||||
variables_,
|
||||
"$deprecation$public int ${$get$capitalized_name$Value$}$() {\n"
|
||||
" return $name$_;\n"
|
||||
"}\n");
|
||||
printer->Print(variables_,
|
||||
"@java.lang.Override $deprecation$public int "
|
||||
"${$get$capitalized_name$Value$}$() {\n"
|
||||
" return $name$_;\n"
|
||||
"}\n");
|
||||
printer->Annotate("{", "}", descriptor_);
|
||||
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, SETTER,
|
||||
/* builder */ true);
|
||||
@ -232,6 +233,7 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers(
|
||||
}
|
||||
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
|
||||
printer->Print(variables_,
|
||||
"@java.lang.Override\n"
|
||||
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
|
||||
" @SuppressWarnings(\"deprecation\")\n"
|
||||
" $type$ result = $type$.$for_number$($name$_);\n"
|
||||
@ -284,7 +286,7 @@ void ImmutableEnumFieldGenerator::GenerateBuilderClearCode(
|
||||
|
||||
void ImmutableEnumFieldGenerator::GenerateMergingCode(
|
||||
io::Printer* printer) const {
|
||||
if (SupportFieldPresence(descriptor_->file())) {
|
||||
if (SupportFieldPresence(descriptor_)) {
|
||||
printer->Print(variables_,
|
||||
"if (other.has$capitalized_name$()) {\n"
|
||||
" set$capitalized_name$(other.get$capitalized_name$());\n"
|
||||
@ -302,7 +304,7 @@ void ImmutableEnumFieldGenerator::GenerateMergingCode(
|
||||
|
||||
void ImmutableEnumFieldGenerator::GenerateBuildingCode(
|
||||
io::Printer* printer) const {
|
||||
if (SupportFieldPresence(descriptor_->file())) {
|
||||
if (SupportFieldPresence(descriptor_)) {
|
||||
printer->Print(variables_,
|
||||
"if ($get_has_field_bit_from_local$) {\n"
|
||||
" $set_has_field_bit_to_local$;\n"
|
||||
@ -386,7 +388,7 @@ ImmutableEnumOneofFieldGenerator::~ImmutableEnumOneofFieldGenerator() {}
|
||||
void ImmutableEnumOneofFieldGenerator::GenerateMembers(
|
||||
io::Printer* printer) const {
|
||||
PrintExtraFieldInfo(variables_, printer);
|
||||
if (SupportFieldPresence(descriptor_->file())) {
|
||||
if (SupportFieldPresence(descriptor_)) {
|
||||
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
|
||||
printer->Print(
|
||||
variables_,
|
||||
@ -423,10 +425,11 @@ void ImmutableEnumOneofFieldGenerator::GenerateMembers(
|
||||
|
||||
void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers(
|
||||
io::Printer* printer) const {
|
||||
if (SupportFieldPresence(descriptor_->file())) {
|
||||
if (SupportFieldPresence(descriptor_)) {
|
||||
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
|
||||
printer->Print(
|
||||
variables_,
|
||||
"@java.lang.Override\n"
|
||||
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
|
||||
" return $has_oneof_case_message$;\n"
|
||||
"}\n");
|
||||
@ -436,6 +439,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers(
|
||||
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER);
|
||||
printer->Print(
|
||||
variables_,
|
||||
"@java.lang.Override\n"
|
||||
"$deprecation$public int ${$get$capitalized_name$Value$}$() {\n"
|
||||
" if ($has_oneof_case_message$) {\n"
|
||||
" return ((java.lang.Integer) $oneof_name$_).intValue();\n"
|
||||
@ -457,6 +461,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers(
|
||||
}
|
||||
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
|
||||
printer->Print(variables_,
|
||||
"@java.lang.Override\n"
|
||||
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
|
||||
" if ($has_oneof_case_message$) {\n"
|
||||
" @SuppressWarnings(\"deprecation\")\n"
|
||||
@ -650,6 +655,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMembers(
|
||||
WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER);
|
||||
printer->Print(
|
||||
variables_,
|
||||
"@java.lang.Override\n"
|
||||
"$deprecation$public java.util.List<$type$> "
|
||||
"${$get$capitalized_name$List$}$() {\n"
|
||||
" return new com.google.protobuf.Internal.ListAdapter<\n"
|
||||
@ -659,6 +665,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMembers(
|
||||
WriteFieldAccessorDocComment(printer, descriptor_, LIST_COUNT);
|
||||
printer->Print(
|
||||
variables_,
|
||||
"@java.lang.Override\n"
|
||||
"$deprecation$public int ${$get$capitalized_name$Count$}$() {\n"
|
||||
" return $name$_.size();\n"
|
||||
"}\n");
|
||||
@ -666,6 +673,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMembers(
|
||||
WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER);
|
||||
printer->Print(
|
||||
variables_,
|
||||
"@java.lang.Override\n"
|
||||
"$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n"
|
||||
" return $name$_converter_.convert($name$_.get(index));\n"
|
||||
"}\n");
|
||||
@ -673,6 +681,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMembers(
|
||||
if (SupportUnknownEnumValue(descriptor_->file())) {
|
||||
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER);
|
||||
printer->Print(variables_,
|
||||
"@java.lang.Override\n"
|
||||
"$deprecation$public java.util.List<java.lang.Integer>\n"
|
||||
"${$get$capitalized_name$ValueList$}$() {\n"
|
||||
" return $name$_;\n"
|
||||
@ -681,6 +690,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateMembers(
|
||||
WriteFieldEnumValueAccessorDocComment(printer, descriptor_,
|
||||
LIST_INDEXED_GETTER);
|
||||
printer->Print(variables_,
|
||||
"@java.lang.Override\n"
|
||||
"$deprecation$public int "
|
||||
"${$get$capitalized_name$Value$}$(int index) {\n"
|
||||
" return $name$_.get(index);\n"
|
||||
|
@ -83,7 +83,7 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
|
||||
descriptor->options().deprecated() ? "@java.lang.Deprecated " : "";
|
||||
(*variables)["required"] = descriptor->is_required() ? "true" : "false";
|
||||
|
||||
if (SupportFieldPresence(descriptor->file())) {
|
||||
if (SupportFieldPresence(descriptor)) {
|
||||
// For singular messages and builders, one bit is used for the hasField bit.
|
||||
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);
|
||||
|
||||
@ -140,12 +140,12 @@ ImmutableEnumFieldLiteGenerator::ImmutableEnumFieldLiteGenerator(
|
||||
ImmutableEnumFieldLiteGenerator::~ImmutableEnumFieldLiteGenerator() {}
|
||||
|
||||
int ImmutableEnumFieldLiteGenerator::GetNumBitsForMessage() const {
|
||||
return SupportFieldPresence(descriptor_->file()) ? 1 : 0;
|
||||
return SupportFieldPresence(descriptor_) ? 1 : 0;
|
||||
}
|
||||
|
||||
void ImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers(
|
||||
io::Printer* printer) const {
|
||||
if (SupportFieldPresence(descriptor_->file())) {
|
||||
if (SupportFieldPresence(descriptor_)) {
|
||||
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
|
||||
printer->Print(variables_,
|
||||
"$deprecation$boolean has$capitalized_name$();\n");
|
||||
@ -163,7 +163,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateMembers(
|
||||
io::Printer* printer) const {
|
||||
printer->Print(variables_, "private int $name$_;\n");
|
||||
PrintExtraFieldInfo(variables_, printer);
|
||||
if (SupportFieldPresence(descriptor_->file())) {
|
||||
if (SupportFieldPresence(descriptor_)) {
|
||||
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
|
||||
printer->Print(
|
||||
variables_,
|
||||
@ -217,7 +217,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateMembers(
|
||||
|
||||
void ImmutableEnumFieldLiteGenerator::GenerateBuilderMembers(
|
||||
io::Printer* printer) const {
|
||||
if (SupportFieldPresence(descriptor_->file())) {
|
||||
if (SupportFieldPresence(descriptor_)) {
|
||||
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
|
||||
printer->Print(
|
||||
variables_,
|
||||
@ -288,11 +288,11 @@ void ImmutableEnumFieldLiteGenerator::GenerateFieldInfo(
|
||||
WriteIntToUtf16CharSequence(descriptor_->number(), output);
|
||||
WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_),
|
||||
output);
|
||||
if (SupportFieldPresence(descriptor_->file())) {
|
||||
if (HasHasbit(descriptor_)) {
|
||||
WriteIntToUtf16CharSequence(messageBitIndex_, output);
|
||||
}
|
||||
printer->Print(variables_, "\"$name$_\",\n");
|
||||
if (SupportFieldPresence(descriptor_->file())) {
|
||||
if (!SupportUnknownEnumValue((descriptor_))) {
|
||||
PrintEnumVerifierLogic(printer, descriptor_, variables_,
|
||||
/*var_name=*/"$type$",
|
||||
/*terminating_string=*/",\n",
|
||||
@ -319,7 +319,7 @@ ImmutableEnumOneofFieldLiteGenerator::~ImmutableEnumOneofFieldLiteGenerator() {}
|
||||
void ImmutableEnumOneofFieldLiteGenerator::GenerateMembers(
|
||||
io::Printer* printer) const {
|
||||
PrintExtraFieldInfo(variables_, printer);
|
||||
if (SupportFieldPresence(descriptor_->file())) {
|
||||
if (SupportFieldPresence(descriptor_)) {
|
||||
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
|
||||
printer->Print(
|
||||
variables_,
|
||||
@ -386,7 +386,7 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateFieldInfo(
|
||||
WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_),
|
||||
output);
|
||||
WriteIntToUtf16CharSequence(descriptor_->containing_oneof()->index(), output);
|
||||
if (SupportFieldPresence(descriptor_->file())) {
|
||||
if (!SupportUnknownEnumValue(descriptor_)) {
|
||||
PrintEnumVerifierLogic(printer, descriptor_, variables_,
|
||||
/*var_name=*/"$type$",
|
||||
/*terminating_string=*/",\n",
|
||||
@ -396,7 +396,7 @@ void ImmutableEnumOneofFieldLiteGenerator::GenerateFieldInfo(
|
||||
|
||||
void ImmutableEnumOneofFieldLiteGenerator::GenerateBuilderMembers(
|
||||
io::Printer* printer) const {
|
||||
if (SupportFieldPresence(descriptor_->file())) {
|
||||
if (SupportFieldPresence(descriptor_)) {
|
||||
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
|
||||
printer->Print(
|
||||
variables_,
|
||||
@ -640,7 +640,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateFieldInfo(
|
||||
WriteIntToUtf16CharSequence(GetExperimentalJavaFieldType(descriptor_),
|
||||
output);
|
||||
printer->Print(variables_, "\"$name$_\",\n");
|
||||
if (SupportFieldPresence(descriptor_->file())) {
|
||||
if (!SupportUnknownEnumValue(descriptor_->file())) {
|
||||
PrintEnumVerifierLogic(printer, descriptor_, variables_,
|
||||
/*var_name=*/"$type$",
|
||||
/*terminating_string=*/",\n",
|
||||
|
@ -87,7 +87,7 @@ ImmutableFieldGenerator* MakeImmutableGenerator(const FieldDescriptor* field,
|
||||
field, messageBitIndex, builderBitIndex, context);
|
||||
}
|
||||
} else {
|
||||
if (field->containing_oneof()) {
|
||||
if (IsRealOneof(field)) {
|
||||
switch (GetJavaType(field)) {
|
||||
case JAVATYPE_MESSAGE:
|
||||
return new ImmutableMessageOneofFieldGenerator(
|
||||
@ -144,7 +144,7 @@ ImmutableFieldLiteGenerator* MakeImmutableLiteGenerator(
|
||||
field, messageBitIndex, context);
|
||||
}
|
||||
} else {
|
||||
if (field->containing_oneof()) {
|
||||
if (IsRealOneof(field)) {
|
||||
switch (GetJavaType(field)) {
|
||||
case JAVATYPE_MESSAGE:
|
||||
return new ImmutableMessageOneofFieldLiteGenerator(
|
||||
|
@ -76,6 +76,7 @@ struct FieldDescriptorCompare {
|
||||
typedef std::set<const FieldDescriptor*, FieldDescriptorCompare>
|
||||
FieldDescriptorSet;
|
||||
|
||||
|
||||
// Recursively searches the given message to collect extensions.
|
||||
// Returns true if all the extensions can be recognized. The extensions will be
|
||||
// appended in to the extensions parameter.
|
||||
@ -85,7 +86,9 @@ bool CollectExtensions(const Message& message, FieldDescriptorSet* extensions) {
|
||||
const Reflection* reflection = message.GetReflection();
|
||||
|
||||
// There are unknown fields that could be extensions, thus this call fails.
|
||||
if (reflection->GetUnknownFields(message).field_count() > 0) return false;
|
||||
UnknownFieldSet unknown_fields;
|
||||
unknown_fields.MergeFrom(reflection->GetUnknownFields(message));
|
||||
if (unknown_fields.field_count() > 0) return false;
|
||||
|
||||
std::vector<const FieldDescriptor*> fields;
|
||||
reflection->ListFields(message, &fields);
|
||||
|
@ -58,6 +58,10 @@ namespace java {
|
||||
JavaGenerator::JavaGenerator() {}
|
||||
JavaGenerator::~JavaGenerator() {}
|
||||
|
||||
uint64 JavaGenerator::GetSupportedFeatures() const {
|
||||
return CodeGenerator::Feature::FEATURE_PROTO3_OPTIONAL;
|
||||
}
|
||||
|
||||
bool JavaGenerator::Generate(const FileDescriptor* file,
|
||||
const std::string& parameter,
|
||||
GeneratorContext* context,
|
||||
|
@ -60,6 +60,8 @@ class PROTOC_EXPORT JavaGenerator : public CodeGenerator {
|
||||
bool Generate(const FileDescriptor* file, const std::string& parameter,
|
||||
GeneratorContext* context, std::string* error) const;
|
||||
|
||||
uint64 GetSupportedFeatures() const override;
|
||||
|
||||
private:
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(JavaGenerator);
|
||||
};
|
||||
|
@ -963,6 +963,7 @@ int GetExperimentalJavaFieldType(const FieldDescriptor* field) {
|
||||
static const int kUtf8CheckBit = 0x200;
|
||||
static const int kCheckInitialized = 0x400;
|
||||
static const int kMapWithProto2EnumValue = 0x800;
|
||||
static const int kHasHasBit = 0x1000;
|
||||
int extra_bits = field->is_required() ? kRequiredBit : 0;
|
||||
if (field->type() == FieldDescriptor::TYPE_STRING && CheckUtf8(field)) {
|
||||
extra_bits |= kUtf8CheckBit;
|
||||
@ -971,9 +972,12 @@ int GetExperimentalJavaFieldType(const FieldDescriptor* field) {
|
||||
HasRequiredFields(field->message_type()))) {
|
||||
extra_bits |= kCheckInitialized;
|
||||
}
|
||||
if (HasHasbit(field)) {
|
||||
extra_bits |= kHasHasBit;
|
||||
}
|
||||
|
||||
if (field->is_map()) {
|
||||
if (SupportFieldPresence(field->file())) {
|
||||
if (!SupportUnknownEnumValue(field)) {
|
||||
const FieldDescriptor* value =
|
||||
field->message_type()->FindFieldByName("value");
|
||||
if (GetJavaType(value) == JAVATYPE_ENUM) {
|
||||
@ -985,7 +989,7 @@ int GetExperimentalJavaFieldType(const FieldDescriptor* field) {
|
||||
return GetExperimentalJavaFieldTypeForPacked(field);
|
||||
} else if (field->is_repeated()) {
|
||||
return GetExperimentalJavaFieldTypeForRepeated(field) | extra_bits;
|
||||
} else if (field->containing_oneof() != NULL) {
|
||||
} else if (IsRealOneof(field)) {
|
||||
return (GetExperimentalJavaFieldTypeForSingular(field) +
|
||||
kOneofFieldTypeOffset) |
|
||||
extra_bits;
|
||||
|
@ -188,9 +188,11 @@ template <typename Descriptor>
|
||||
void MaybePrintGeneratedAnnotation(Context* context, io::Printer* printer,
|
||||
Descriptor* descriptor, bool immutable,
|
||||
const std::string& suffix = "") {
|
||||
if (context->options().annotate_code && IsOwnFile(descriptor, immutable)) {
|
||||
if (IsOwnFile(descriptor, immutable)) {
|
||||
PrintGeneratedAnnotation(printer, '$',
|
||||
AnnotationFileName(descriptor, suffix));
|
||||
context->options().annotate_code
|
||||
? AnnotationFileName(descriptor, suffix)
|
||||
: "");
|
||||
}
|
||||
}
|
||||
|
||||
@ -352,9 +354,30 @@ inline bool HasPackedFields(const Descriptor* descriptor) {
|
||||
// them has a required field. Return true if a required field is found.
|
||||
bool HasRequiredFields(const Descriptor* descriptor);
|
||||
|
||||
// Whether a .proto file supports field presence test for non-message types.
|
||||
inline bool SupportFieldPresence(const FileDescriptor* descriptor) {
|
||||
return descriptor->syntax() != FileDescriptor::SYNTAX_PROTO3;
|
||||
inline bool IsProto2(const FileDescriptor* descriptor) {
|
||||
return descriptor->syntax() == FileDescriptor::SYNTAX_PROTO2;
|
||||
}
|
||||
|
||||
inline bool SupportFieldPresence(const FieldDescriptor* descriptor) {
|
||||
// Note that while proto3 oneofs do conceptually support present, we return
|
||||
// false for them because they do not offer a public hazzer. Therefore this
|
||||
// method could be named HasHazzer().
|
||||
return !descriptor->is_repeated() &&
|
||||
(descriptor->message_type() || descriptor->has_optional_keyword() ||
|
||||
IsProto2(descriptor->file()));
|
||||
}
|
||||
|
||||
inline bool IsRealOneof(const FieldDescriptor* descriptor) {
|
||||
return descriptor->containing_oneof() &&
|
||||
!descriptor->containing_oneof()->is_synthetic();
|
||||
}
|
||||
|
||||
inline bool HasHasbit(const FieldDescriptor* descriptor) {
|
||||
// Note that currently message fields inside oneofs have hasbits. This is
|
||||
// surprising, as the oneof case should avoid any need for a hasbit. But if
|
||||
// you change this method to remove hasbits for oneofs, a few tests fail.
|
||||
return !descriptor->is_repeated() &&
|
||||
(descriptor->has_optional_keyword() || IsProto2(descriptor->file()));
|
||||
}
|
||||
|
||||
// Whether generate classes expose public PARSER instances.
|
||||
@ -370,6 +393,10 @@ inline bool SupportUnknownEnumValue(const FileDescriptor* descriptor) {
|
||||
return descriptor->syntax() == FileDescriptor::SYNTAX_PROTO3;
|
||||
}
|
||||
|
||||
inline bool SupportUnknownEnumValue(const FieldDescriptor* field) {
|
||||
return field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3;
|
||||
}
|
||||
|
||||
// Check whether a message has repeated fields.
|
||||
bool HasRepeatedFields(const Descriptor* descriptor);
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user