From 197a644bf7066ff856135b8e9370f9909f98cb9a Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 8 Dec 2020 01:46:49 -0800 Subject: [PATCH] fix: lower protobuf hash order of magnitude for PHP (#16) --- .../proto3/Message.java | 8 +- .../cloud/compute/v1/compute.proto.baseline | 124 +++++++++--------- .../cloud/compute/v1/compute.proto.ignorelist | 30 ++--- 3 files changed, 82 insertions(+), 80 deletions(-) diff --git a/src/main/java/com/google/cloud/discotoproto3converter/proto3/Message.java b/src/main/java/com/google/cloud/discotoproto3converter/proto3/Message.java index 3c768a2..b8a64f2 100644 --- a/src/main/java/com/google/cloud/discotoproto3converter/proto3/Message.java +++ b/src/main/java/com/google/cloud/discotoproto3converter/proto3/Message.java @@ -92,16 +92,18 @@ public Map getFieldsWithNumbers() { // All the "magic numbers" come from the proto3 spec: // https://developers.google.com/protocol-buffers/docs/proto3#assigning_field_numbers private int getFieldNumber(String fieldName) { - int fieldNumber = (fieldName.hashCode() << 3) >>> 3; + // TODO: Use 2^29 instead of 2^28 once the following is fixed: + // https://github.com/protocolbuffers/protobuf/issues/8114 + int fieldNumber = (fieldName.hashCode() << 4) >>> 4; if (fieldNumber == 0 || (fieldNumber >= 19000 && fieldNumber <= 19999)) { - fieldNumber = 20000 + ((fieldNumber % 19000) + 1) * 536314; + fieldNumber = 20000 + ((fieldNumber % 19000) + 1) * 268147; } return fieldNumber; } private int incrementFieldNumber(int fieldNumber) { int incrementedFieldNumber = fieldNumber + 1; - if ((fieldNumber >= 19000 && fieldNumber <= 19999) || fieldNumber >= (1 << 29)) { + if ((fieldNumber >= 19000 && fieldNumber <= 19999) || fieldNumber >= (1 << 28)) { incrementedFieldNumber = 20000; } return incrementedFieldNumber; diff --git a/src/test/resources/google/cloud/compute/v1/compute.proto.baseline b/src/test/resources/google/cloud/compute/v1/compute.proto.baseline index 72c7b00..4620b7b 100644 --- a/src/test/resources/google/cloud/compute/v1/compute.proto.baseline +++ b/src/test/resources/google/cloud/compute/v1/compute.proto.baseline @@ -49,17 +49,17 @@ message Errors { string code = 3059181; // [Output Only] Indicates the field in the request that caused the error. This property is optional. - string location = 290430901; + string location = 21995445; // [Output Only] An optional, human-readable error message. - string message = 418054151; + string message = 149618695; } // [Output Only] If errors are generated during processing of the operation, this field will be populated. message Error { // [Output Only] The array of errors encountered while processing this operation. - repeated Errors errors = 315977579; + repeated Errors errors = 47542123; } @@ -82,31 +82,31 @@ message Warnings { CLEANUP_FAILED = 150308440; - DEPRECATED_RESOURCE_USED = 391835586; + DEPRECATED_RESOURCE_USED = 123400130; - DEPRECATED_TYPE_USED = 346526230; + DEPRECATED_TYPE_USED = 78090774; - DISK_SIZE_LARGER_THAN_IMAGE_SIZE = 369442967; + DISK_SIZE_LARGER_THAN_IMAGE_SIZE = 101007511; - EXPERIMENTAL_TYPE_USED = 451954443; + EXPERIMENTAL_TYPE_USED = 183518987; EXTERNAL_API_WARNING = 175546307; - FIELD_VALUE_OVERRIDEN = 329669423; + FIELD_VALUE_OVERRIDEN = 61233967; - INJECTED_KERNELS_DEPRECATED = 417377419; + INJECTED_KERNELS_DEPRECATED = 148941963; - MISSING_TYPE_DEPENDENCY = 344505463; + MISSING_TYPE_DEPENDENCY = 76070007; - NEXT_HOP_ADDRESS_NOT_ASSIGNED = 324964999; + NEXT_HOP_ADDRESS_NOT_ASSIGNED = 56529543; - NEXT_HOP_CANNOT_IP_FORWARD = 383382887; + NEXT_HOP_CANNOT_IP_FORWARD = 114947431; - NEXT_HOP_INSTANCE_NOT_FOUND = 464250446; + NEXT_HOP_INSTANCE_NOT_FOUND = 195814990; NEXT_HOP_INSTANCE_NOT_ON_NETWORK = 243758146; - NEXT_HOP_NOT_RUNNING = 417081265; + NEXT_HOP_NOT_RUNNING = 148645809; NOT_CRITICAL_ERROR = 105763924; @@ -114,15 +114,15 @@ message Warnings { REQUIRED_TOS_AGREEMENT = 3745539; - RESOURCE_IN_USE_BY_OTHER_RESOURCE_WARNING = 496728641; + RESOURCE_IN_USE_BY_OTHER_RESOURCE_WARNING = 228293185; RESOURCE_NOT_DELETED = 168598460; - SCHEMA_VALIDATION_IGNORED = 275245642; + SCHEMA_VALIDATION_IGNORED = 6810186; SINGLE_INSTANCE_PROPERTY_TEMPLATE = 268305617; - UNDECLARED_PROPERTIES = 390513439; + UNDECLARED_PROPERTIES = 122077983; UNREACHABLE = 13328052; @@ -136,7 +136,7 @@ message Warnings { repeated Data data = 3076010; // [Output Only] A human-readable description of the warning code. - string message = 418054151; + string message = 149618695; } @@ -169,13 +169,13 @@ message Operation { } // [Output Only] The value of `requestId` if you provided it in the request. Not present otherwise. - string client_operation_id = 297240295; + string client_operation_id = 28804839; // [Deprecated] This field is deprecated. string creation_timestamp = 30525366; // [Output Only] A textual description of the operation, which is set when the operation is created. - string description = 422937596; + string description = 154502140; // [Output Only] The time that this operation was completed. This value is in RFC3339 text format. string end_time = 114938801; @@ -187,13 +187,13 @@ message Operation { string http_error_message = 202521945; // [Output Only] If the operation fails, this field contains the HTTP error status code that was returned. For example, a 404 means the resource was not found. - int32 http_error_status_code = 312345196; + int32 http_error_status_code = 43909740; // [Output Only] The unique identifier for the operation. This identifier is defined by the server. string id = 3355; // [Output Only] The time that this operation was requested. This value is in RFC3339 text format. - string insert_time = 433722515; + string insert_time = 165287059; // [Output Only] Type of the resource. Always compute#operation for Operation resources. string kind = 3292052; @@ -211,7 +211,7 @@ message Operation { string region = 138946292; // [Output Only] Server-defined URL for the resource. - string self_link = 456214797; + string self_link = 187779341; // [Output Only] The time that this operation was started by the server. This value is in RFC3339 text format. string start_time = 37467274; @@ -220,7 +220,7 @@ message Operation { Status status = 181260274; // [Output Only] An optional textual description of the current status of the operation. - string status_message = 297428154; + string status_message = 28992698; // [Output Only] The unique target ID, which identifies a specific incarnation of the target resource. string target_id = 258165385; @@ -232,7 +232,7 @@ message Operation { string user = 3599307; // [Output Only] If warning messages are generated during processing of the operation, this field will be populated. - repeated Warnings warnings = 498091095; + repeated Warnings warnings = 229655639; // [Output Only] The URL of the zone where the operation resides. Only applicable when performing per-zone operations. string zone = 3744684; @@ -262,7 +262,7 @@ message Address { EXTERNAL = 35607499; - INTERNAL = 279295677; + INTERNAL = 10860221; UNSPECIFIED_TYPE = 53933922; @@ -288,9 +288,9 @@ message Address { // A value indicating that the enum field is not set. UNDEFINED_NETWORK_TIER = 0; - PREMIUM = 399530551; + PREMIUM = 131095095; - STANDARD = 484642493; + STANDARD = 216207037; } @@ -303,13 +303,13 @@ message Address { // A value indicating that the enum field is not set. UNDEFINED_PURPOSE = 0; - DNS_RESOLVER = 476114556; + DNS_RESOLVER = 207679100; GCE_ENDPOINT = 230515243; NAT_AUTO = 163666477; - VPC_PEERING = 400800170; + VPC_PEERING = 132364714; } @@ -320,14 +320,14 @@ message Address { IN_USE = 17393485; - RESERVED = 432241448; + RESERVED = 163805992; - RESERVING = 514587225; + RESERVING = 246151769; } // The static IP address represented by this resource. - string address = 462920692; + string address = 194485236; // The type of address to reserve, either INTERNAL or EXTERNAL. If unspecified, defaults to EXTERNAL. AddressType address_type = 264307877; @@ -336,13 +336,13 @@ message Address { string creation_timestamp = 30525366; // An optional description of this resource. Provide this field when you create the resource. - string description = 422937596; + string description = 154502140; // [Output Only] The unique identifier for the resource. This identifier is defined by the server. string id = 3355; // The IP version that will be used by this address. Valid options are IPV4 or IPV6. This can only be specified for a global address. - IpVersion ip_version = 294959552; + IpVersion ip_version = 26524096; // [Output Only] Type of the resource. Always compute#address for addresses. string kind = 3292052; @@ -356,29 +356,29 @@ message Address { // This signifies the networking tier used for configuring this address and can only take the following values: PREMIUM or STANDARD. Global forwarding rules can only be Premium Tier. Regional forwarding rules can be either Premium or Standard Tier. Standard Tier addresses applied to regional forwarding rules can be used with any external load balancer. Regional forwarding rules in Premium Tier can only be used with a network load balancer. // // If this field is not specified, it is assumed to be PREMIUM. - NetworkTier network_tier = 517397843; + NetworkTier network_tier = 248962387; // The prefix length if the resource reprensents an IP range. - int32 prefix_length = 453565747; + int32 prefix_length = 185130291; // The purpose of this resource, which can be one of the following values: // - `GCE_ENDPOINT` for addresses that are used by VM instances, alias IP ranges, internal load balancers, and similar resources. // - `DNS_RESOLVER` for a DNS resolver address in a subnetwork // - `VPC_PEERING` for addresses that are reserved for VPC peer networks. // - `NAT_AUTO` for addresses that are external IP addresses automatically reserved for Cloud NAT. - Purpose purpose = 316407070; + Purpose purpose = 47971614; // [Output Only] The URL of the region where the regional address resides. This field is not applicable to global addresses. You must specify this field as part of the HTTP request URL. string region = 138946292; // [Output Only] Server-defined URL for the resource. - string self_link = 456214797; + string self_link = 187779341; // [Output Only] The status of the address, which can be one of RESERVING, RESERVED, or IN_USE. An address that is RESERVING is currently in the process of being reserved. A RESERVED address is currently reserved and available to use. An IN_USE address is currently being used by another resource and is not available. Status status = 181260274; // The URL of the subnetwork in which to reserve the address. If an IP address is specified, it must be within the subnetwork's IP range. This field can only be used with INTERNAL type with a GCE_ENDPOINT or DNS_RESOLVER purpose. - string subnetwork = 307827694; + string subnetwork = 39392238; // [Output Only] The URLs of the resources that are using this address. repeated string users = 111578632; @@ -388,7 +388,7 @@ message Address { // message AddressesScopedList { // [Output Only] A list of addresses contained in this scope. - repeated Address addresses = 337673122; + repeated Address addresses = 69237666; // [Output Only] Informational warning which replaces the list of addresses when the list is empty. Warning warning = 50704284; @@ -404,31 +404,31 @@ message Warning { CLEANUP_FAILED = 150308440; - DEPRECATED_RESOURCE_USED = 391835586; + DEPRECATED_RESOURCE_USED = 123400130; - DEPRECATED_TYPE_USED = 346526230; + DEPRECATED_TYPE_USED = 78090774; - DISK_SIZE_LARGER_THAN_IMAGE_SIZE = 369442967; + DISK_SIZE_LARGER_THAN_IMAGE_SIZE = 101007511; - EXPERIMENTAL_TYPE_USED = 451954443; + EXPERIMENTAL_TYPE_USED = 183518987; EXTERNAL_API_WARNING = 175546307; - FIELD_VALUE_OVERRIDEN = 329669423; + FIELD_VALUE_OVERRIDEN = 61233967; - INJECTED_KERNELS_DEPRECATED = 417377419; + INJECTED_KERNELS_DEPRECATED = 148941963; - MISSING_TYPE_DEPENDENCY = 344505463; + MISSING_TYPE_DEPENDENCY = 76070007; - NEXT_HOP_ADDRESS_NOT_ASSIGNED = 324964999; + NEXT_HOP_ADDRESS_NOT_ASSIGNED = 56529543; - NEXT_HOP_CANNOT_IP_FORWARD = 383382887; + NEXT_HOP_CANNOT_IP_FORWARD = 114947431; - NEXT_HOP_INSTANCE_NOT_FOUND = 464250446; + NEXT_HOP_INSTANCE_NOT_FOUND = 195814990; NEXT_HOP_INSTANCE_NOT_ON_NETWORK = 243758146; - NEXT_HOP_NOT_RUNNING = 417081265; + NEXT_HOP_NOT_RUNNING = 148645809; NOT_CRITICAL_ERROR = 105763924; @@ -436,15 +436,15 @@ message Warning { REQUIRED_TOS_AGREEMENT = 3745539; - RESOURCE_IN_USE_BY_OTHER_RESOURCE_WARNING = 496728641; + RESOURCE_IN_USE_BY_OTHER_RESOURCE_WARNING = 228293185; RESOURCE_NOT_DELETED = 168598460; - SCHEMA_VALIDATION_IGNORED = 275245642; + SCHEMA_VALIDATION_IGNORED = 6810186; SINGLE_INSTANCE_PROPERTY_TEMPLATE = 268305617; - UNDECLARED_PROPERTIES = 390513439; + UNDECLARED_PROPERTIES = 122077983; UNREACHABLE = 13328052; @@ -458,7 +458,7 @@ message Warning { repeated Data data = 3076010; // [Output Only] A human-readable description of the warning code. - string message = 418054151; + string message = 149618695; } @@ -477,7 +477,7 @@ message AddressAggregatedList { string next_page_token = 79797525; // [Output Only] Server-defined URL for this resource. - string self_link = 456214797; + string self_link = 187779341; // [Output Only] Informational warning message. Warning warning = 50704284; @@ -499,7 +499,7 @@ message AddressList { string next_page_token = 79797525; // [Output Only] Server-defined URL for this resource. - string self_link = 456214797; + string self_link = 187779341; // [Output Only] Informational warning message. Warning warning = 50704284; @@ -515,10 +515,10 @@ message AggregatedListAddressesRequest { // You can also filter nested fields. For example, you could specify `scheduling.automaticRestart = false` to include instances only if they are not scheduled for automatic restarts. You can use filtering on nested fields to filter based on resource labels. // // To filter on multiple expressions, provide each separate expression within parentheses. For example: ``` (scheduling.automaticRestart = true) (cpuPlatform = "Intel Skylake") ``` By default, each expression is an `AND` expression. However, you can include `AND` and `OR` expressions explicitly. For example: ``` (cpuPlatform = "Intel Skylake") OR (cpuPlatform = "Intel Broadwell") AND (scheduling.automaticRestart = true) ``` - string filter = 336120696; + string filter = 67685240; // Indicates whether every visible scope for each scope type (zone, region, global) should be included in the response. For new resource types added after this field, the flag has no effect as new resource types will always include every visible scope for each scope type in response. For resource types which predate this field, if this flag is omitted or false, only scopes of the scope types where the resource type is expected to be found will be included. - bool include_all_scopes = 391327988; + bool include_all_scopes = 122892532; // The maximum number of results per page that should be returned. If the number of available results is larger than `maxResults`, Compute Engine returns a `nextPageToken` that can be used to get the next page of results in subsequent list requests. Acceptable values are `0` to `500`, inclusive. (Default: `500`) uint32 max_results = 54715419; @@ -540,7 +540,7 @@ message AggregatedListAddressesRequest { // A request message for Addresses.Insert. See the method description for details. message InsertAddressRequest { - Address address_resource = 483888121; + Address address_resource = 215452665; // Project ID for this request. string project = 227560217 [(google.api.field_behavior) = REQUIRED]; @@ -566,7 +566,7 @@ message ListAddressesRequest { // You can also filter nested fields. For example, you could specify scheduling.automaticRestart = false to include instances only if they are not scheduled for automatic restarts. You can use filtering on nested fields to filter based on resource labels. // // To filter on multiple expressions, provide each separate expression within parentheses. For example, (scheduling.automaticRestart = true) (cpuPlatform = "Intel Skylake"). By default, each expression is an AND expression. However, you can include AND and OR expressions explicitly. For example, (cpuPlatform = "Intel Skylake") OR (cpuPlatform = "Intel Broadwell") AND (scheduling.automaticRestart = true). - string filter = 336120696; + string filter = 67685240; // The maximum number of results per page that should be returned. If the number of available results is larger than maxResults, Compute Engine returns a nextPageToken that can be used to get the next page of results in subsequent list requests. Acceptable values are 0 to 500, inclusive. (Default: 500) uint32 max_results = 54715419; diff --git a/src/test/resources/google/cloud/compute/v1/compute.proto.ignorelist b/src/test/resources/google/cloud/compute/v1/compute.proto.ignorelist index b8d5abf..d0f1624 100644 --- a/src/test/resources/google/cloud/compute/v1/compute.proto.ignorelist +++ b/src/test/resources/google/cloud/compute/v1/compute.proto.ignorelist @@ -66,7 +66,7 @@ message Address { EXTERNAL = 35607499; - INTERNAL = 279295677; + INTERNAL = 10860221; UNSPECIFIED_TYPE = 53933922; @@ -92,9 +92,9 @@ message Address { // A value indicating that the enum field is not set. UNDEFINED_NETWORK_TIER = 0; - PREMIUM = 399530551; + PREMIUM = 131095095; - STANDARD = 484642493; + STANDARD = 216207037; } @@ -107,13 +107,13 @@ message Address { // A value indicating that the enum field is not set. UNDEFINED_PURPOSE = 0; - DNS_RESOLVER = 476114556; + DNS_RESOLVER = 207679100; GCE_ENDPOINT = 230515243; NAT_AUTO = 163666477; - VPC_PEERING = 400800170; + VPC_PEERING = 132364714; } @@ -124,14 +124,14 @@ message Address { IN_USE = 17393485; - RESERVED = 432241448; + RESERVED = 163805992; - RESERVING = 514587225; + RESERVING = 246151769; } // The static IP address represented by this resource. - string address = 462920692; + string address = 194485236; // The type of address to reserve, either INTERNAL or EXTERNAL. If unspecified, defaults to EXTERNAL. AddressType address_type = 264307877; @@ -140,13 +140,13 @@ message Address { string creation_timestamp = 30525366; // An optional description of this resource. Provide this field when you create the resource. - string description = 422937596; + string description = 154502140; // [Output Only] The unique identifier for the resource. This identifier is defined by the server. string id = 3355; // The IP version that will be used by this address. Valid options are IPV4 or IPV6. This can only be specified for a global address. - IpVersion ip_version = 294959552; + IpVersion ip_version = 26524096; // [Output Only] Type of the resource. Always compute#address for addresses. string kind = 3292052; @@ -160,29 +160,29 @@ message Address { // This signifies the networking tier used for configuring this address and can only take the following values: PREMIUM or STANDARD. Global forwarding rules can only be Premium Tier. Regional forwarding rules can be either Premium or Standard Tier. Standard Tier addresses applied to regional forwarding rules can be used with any external load balancer. Regional forwarding rules in Premium Tier can only be used with a network load balancer. // // If this field is not specified, it is assumed to be PREMIUM. - NetworkTier network_tier = 517397843; + NetworkTier network_tier = 248962387; // The prefix length if the resource reprensents an IP range. - int32 prefix_length = 453565747; + int32 prefix_length = 185130291; // The purpose of this resource, which can be one of the following values: // - `GCE_ENDPOINT` for addresses that are used by VM instances, alias IP ranges, internal load balancers, and similar resources. // - `DNS_RESOLVER` for a DNS resolver address in a subnetwork // - `VPC_PEERING` for addresses that are reserved for VPC peer networks. // - `NAT_AUTO` for addresses that are external IP addresses automatically reserved for Cloud NAT. - Purpose purpose = 316407070; + Purpose purpose = 47971614; // [Output Only] The URL of the region where the regional address resides. This field is not applicable to global addresses. You must specify this field as part of the HTTP request URL. string region = 138946292; // [Output Only] Server-defined URL for the resource. - string self_link = 456214797; + string self_link = 187779341; // [Output Only] The status of the address, which can be one of RESERVING, RESERVED, or IN_USE. An address that is RESERVING is currently in the process of being reserved. A RESERVED address is currently reserved and available to use. An IN_USE address is currently being used by another resource and is not available. Status status = 181260274; // The URL of the subnetwork in which to reserve the address. If an IP address is specified, it must be within the subnetwork's IP range. This field can only be used with INTERNAL type with a GCE_ENDPOINT or DNS_RESOLVER purpose. - string subnetwork = 307827694; + string subnetwork = 39392238; // [Output Only] The URLs of the resources that are using this address. repeated string users = 111578632;