Skip to content

Commit 647f590

Browse files
authored
feat(generator/rust): use I32 formatter (#2340)
1 parent a109d91 commit 647f590

File tree

178 files changed

+2222
-47
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+2222
-47
lines changed

generator/internal/rust/annotate_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ func TestOneOfAnnotations(t *testing.T) {
473473
BranchName: "OneofFieldMap",
474474
FQMessageName: "crate::model::Message",
475475
DocLines: nil,
476-
Attributes: []string{`#[serde_as(as = "std::collections::HashMap<_, wkt::internal::F32>")]`},
476+
Attributes: []string{`#[serde_as(as = "std::collections::HashMap<wkt::internal::I32, wkt::internal::F32>")]`},
477477
FieldType: "std::collections::HashMap<i32,f32>",
478478
PrimitiveFieldType: "std::collections::HashMap<i32,f32>",
479479
AddQueryParameter: `let builder = req.oneof_field_map().map(|p| serde_json::to_value(p).map_err(Error::serde) ).transpose()?.into_iter().fold(builder, |builder, p| { use gaxi::query_parameter::QueryParameter; p.add(builder, "oneofFieldMap") });`,
@@ -818,6 +818,7 @@ func TestJsonNameAnnotations(t *testing.T) {
818818
DocLines: nil,
819819
Attributes: []string{
820820
`#[serde(skip_serializing_if = "wkt::internal::is_default")]`,
821+
`#[serde_as(as = "wkt::internal::I32")]`,
821822
},
822823
FieldType: "i32",
823824
PrimitiveFieldType: "i32",
@@ -836,6 +837,7 @@ func TestJsonNameAnnotations(t *testing.T) {
836837
DocLines: nil,
837838
Attributes: []string{
838839
`#[serde(skip_serializing_if = "std::option::Option::is_none")]`,
840+
`#[serde_as(as = "std::option::Option<wkt::internal::I32>")]`,
839841
},
840842
FieldType: "std::option::Option<i32>",
841843
PrimitiveFieldType: "i32",
@@ -854,6 +856,7 @@ func TestJsonNameAnnotations(t *testing.T) {
854856
DocLines: nil,
855857
Attributes: []string{
856858
`#[serde(skip_serializing_if = "std::vec::Vec::is_empty")]`,
859+
`#[serde_as(as = "std::vec::Vec<wkt::internal::I32>")]`,
857860
},
858861
FieldType: "std::vec::Vec<i32>",
859862
PrimitiveFieldType: "i32",
@@ -1046,7 +1049,7 @@ func TestFieldAnnotations(t *testing.T) {
10461049
FQMessageName: "crate::model::TestMessage",
10471050
Attributes: []string{
10481051
`#[serde(skip_serializing_if = "std::collections::HashMap::is_empty")]`,
1049-
`#[serde_as(as = "std::collections::HashMap<_, serde_with::DisplayFromStr>")]`,
1052+
`#[serde_as(as = "std::collections::HashMap<wkt::internal::I32, serde_with::DisplayFromStr>")]`,
10501053
},
10511054
FieldType: "std::collections::HashMap<i32,i64>",
10521055
PrimitiveFieldType: "std::collections::HashMap<i32,i64>",

generator/internal/rust/codec.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ func fieldFormatter(typez api.Typez) string {
415415
api.SFIXED64_TYPE,
416416
api.SINT64_TYPE:
417417
return "serde_with::DisplayFromStr"
418+
case api.INT32_TYPE, api.SINT32_TYPE, api.SFIXED32_TYPE:
419+
return "wkt::internal::I32"
418420
case api.FLOAT_TYPE:
419421
return "wkt::internal::F32"
420422
case api.DOUBLE_TYPE:
@@ -488,6 +490,10 @@ func wrapperFieldAttributes(f *api.Field, attributes []string) []string {
488490
formatter = fieldFormatter(api.UINT64_TYPE)
489491
case ".google.protobuf.Int64Value":
490492
formatter = fieldFormatter(api.INT64_TYPE)
493+
case ".google.protobuf.UInt32Value":
494+
formatter = fieldFormatter(api.UINT32_TYPE)
495+
case ".google.protobuf.Int32Value":
496+
formatter = fieldFormatter(api.INT32_TYPE)
491497
case ".google.protobuf.FloatValue":
492498
formatter = fieldFormatter(api.FLOAT_TYPE)
493499
case ".google.protobuf.DoubleValue":
@@ -536,18 +542,18 @@ func fieldAttributes(f *api.Field, state *api.APIState) []string {
536542
}
537543
attributes := fieldBaseAttributes(f)
538544
switch f.Typez {
539-
case api.INT32_TYPE,
540-
api.FIXED32_TYPE,
545+
case api.FIXED32_TYPE,
541546
api.BOOL_TYPE,
542547
api.STRING_TYPE,
543548
api.UINT32_TYPE,
544-
api.SFIXED32_TYPE,
545-
api.SINT32_TYPE,
546549
api.ENUM_TYPE,
547550
api.GROUP_TYPE:
548551
return append(attributes, fieldSkipAttributes(f)...)
549552

550-
case api.INT64_TYPE,
553+
case api.INT32_TYPE,
554+
api.SFIXED32_TYPE,
555+
api.SINT32_TYPE,
556+
api.INT64_TYPE,
551557
api.UINT64_TYPE,
552558
api.FIXED64_TYPE,
553559
api.SFIXED64_TYPE,

src/firestore/src/generated/gapic/model.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub struct BitSequence {
9696
/// If the length of `bitmap` is zero, then this value must be `0`.
9797
/// Otherwise, this value must be between 0 and 7, inclusive.
9898
#[serde(skip_serializing_if = "wkt::internal::is_default")]
99+
#[serde_as(as = "wkt::internal::I32")]
99100
pub padding: i32,
100101

101102
#[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
@@ -152,6 +153,7 @@ pub struct BloomFilter {
152153

153154
/// The number of hashes used by the algorithm.
154155
#[serde(skip_serializing_if = "wkt::internal::is_default")]
156+
#[serde_as(as = "wkt::internal::I32")]
155157
pub hash_count: i32,
156158

157159
#[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
@@ -1453,6 +1455,7 @@ pub struct ListDocumentsRequest {
14531455
///
14541456
/// Firestore may return fewer than this value.
14551457
#[serde(skip_serializing_if = "wkt::internal::is_default")]
1458+
#[serde_as(as = "wkt::internal::I32")]
14561459
pub page_size: i32,
14571460

14581461
/// Optional. A page token, received from a previous `ListDocuments` response.
@@ -3025,6 +3028,7 @@ pub struct RunQueryResponse {
30253028
/// The number of results that have been skipped due to an offset between
30263029
/// the last response and the current response.
30273030
#[serde(skip_serializing_if = "wkt::internal::is_default")]
3031+
#[serde_as(as = "wkt::internal::I32")]
30283032
pub skipped_results: i32,
30293033

30303034
/// Query explain metrics. This is only present when the
@@ -3651,6 +3655,7 @@ pub struct PartitionQueryRequest {
36513655
/// if more results exist. A second call to PartitionQuery will return up to
36523656
/// 2 partitions, to complete the total of 10 specified in `partition_count`.
36533657
#[serde(skip_serializing_if = "wkt::internal::is_default")]
3658+
#[serde_as(as = "wkt::internal::I32")]
36543659
pub page_size: i32,
36553660

36563661
/// The query to partition.
@@ -4266,7 +4271,7 @@ pub mod listen_request {
42664271
/// A target to add to this stream.
42674272
AddTarget(std::boxed::Box<crate::model::Target>),
42684273
/// The ID of a target to remove from this stream.
4269-
RemoveTarget(i32),
4274+
RemoveTarget(#[serde_as(as = "wkt::internal::I32")] i32),
42704275
}
42714276

42724277
impl TargetChange {
@@ -4567,6 +4572,7 @@ pub struct Target {
45674572
/// If `target_id` is non-zero, there must not be an existing active target on
45684573
/// this stream with the same ID.
45694574
#[serde(skip_serializing_if = "wkt::internal::is_default")]
4575+
#[serde_as(as = "wkt::internal::I32")]
45704576
pub target_id: i32,
45714577

45724578
/// If the target should be removed once it is current and consistent.
@@ -4580,6 +4586,7 @@ pub struct Target {
45804586
/// being present and greater than zero signals that the client wants
45814587
/// `ExistenceFilter.unchanged_names` to be included in the response.
45824588
#[serde(skip_serializing_if = "std::option::Option::is_none")]
4589+
#[serde_as(as = "std::option::Option<wkt::internal::I32>")]
45834590
pub expected_count: std::option::Option<wkt::Int32Value>,
45844591

45854592
/// The type of target to listen to.
@@ -5008,6 +5015,7 @@ pub struct TargetChange {
50085015
///
50095016
/// The order of the target IDs is not defined.
50105017
#[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
5018+
#[serde_as(as = "std::vec::Vec<wkt::internal::I32>")]
50115019
pub target_ids: std::vec::Vec<i32>,
50125020

50135021
/// The error that resulted in this change, if applicable.
@@ -5296,6 +5304,7 @@ pub struct ListCollectionIdsRequest {
52965304

52975305
/// The maximum number of results to return.
52985306
#[serde(skip_serializing_if = "wkt::internal::is_default")]
5307+
#[serde_as(as = "wkt::internal::I32")]
52995308
pub page_size: i32,
53005309

53015310
/// A page token. Must be a value from
@@ -5714,6 +5723,7 @@ pub struct StructuredQuery {
57145723
///
57155724
/// * The value must be greater than or equal to zero if specified.
57165725
#[serde(skip_serializing_if = "wkt::internal::is_default")]
5726+
#[serde_as(as = "wkt::internal::I32")]
57175727
pub offset: i32,
57185728

57195729
/// The maximum number of results to return.
@@ -5724,6 +5734,7 @@ pub struct StructuredQuery {
57245734
///
57255735
/// * The value must be greater than or equal to zero if specified.
57265736
#[serde(skip_serializing_if = "std::option::Option::is_none")]
5737+
#[serde_as(as = "std::option::Option<wkt::internal::I32>")]
57275738
pub limit: std::option::Option<wkt::Int32Value>,
57285739

57295740
/// Optional. A potential nearest neighbors search.
@@ -7085,6 +7096,7 @@ pub mod structured_query {
70857096
/// Required. The number of nearest neighbors to return. Must be a positive
70867097
/// integer of no more than 1000.
70877098
#[serde(skip_serializing_if = "std::option::Option::is_none")]
7099+
#[serde_as(as = "std::option::Option<wkt::internal::I32>")]
70887100
pub limit: std::option::Option<wkt::Int32Value>,
70897101

70907102
/// Optional. Optional name of the field to output the result of the vector
@@ -9229,10 +9241,12 @@ pub struct DocumentChange {
92299241

92309242
/// A set of target IDs of targets that match this document.
92319243
#[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
9244+
#[serde_as(as = "std::vec::Vec<wkt::internal::I32>")]
92329245
pub target_ids: std::vec::Vec<i32>,
92339246

92349247
/// A set of target IDs for targets that no longer match this document.
92359248
#[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
9249+
#[serde_as(as = "std::vec::Vec<wkt::internal::I32>")]
92369250
pub removed_target_ids: std::vec::Vec<i32>,
92379251

92389252
#[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
@@ -9317,6 +9331,7 @@ pub struct DocumentDelete {
93179331

93189332
/// A set of target IDs for targets that previously matched this entity.
93199333
#[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
9334+
#[serde_as(as = "std::vec::Vec<wkt::internal::I32>")]
93209335
pub removed_target_ids: std::vec::Vec<i32>,
93219336

93229337
/// The read timestamp at which the delete was observed.
@@ -9403,6 +9418,7 @@ pub struct DocumentRemove {
94039418

94049419
/// A set of target IDs for targets that previously matched this document.
94059420
#[serde(skip_serializing_if = "std::vec::Vec::is_empty")]
9421+
#[serde_as(as = "std::vec::Vec<wkt::internal::I32>")]
94069422
pub removed_target_ids: std::vec::Vec<i32>,
94079423

94089424
/// The read timestamp at which the remove was observed.
@@ -9470,6 +9486,7 @@ impl wkt::message::Message for DocumentRemove {
94709486
pub struct ExistenceFilter {
94719487
/// The target ID to which this filter applies.
94729488
#[serde(skip_serializing_if = "wkt::internal::is_default")]
9489+
#[serde_as(as = "wkt::internal::I32")]
94739490
pub target_id: i32,
94749491

94759492
/// The total count of documents that match
@@ -9485,6 +9502,7 @@ pub struct ExistenceFilter {
94859502
///
94869503
/// [google.firestore.v1.ExistenceFilter.target_id]: crate::model::ExistenceFilter::target_id
94879504
#[serde(skip_serializing_if = "wkt::internal::is_default")]
9505+
#[serde_as(as = "wkt::internal::I32")]
94889506
pub count: i32,
94899507

94909508
/// A bloom filter that, despite its name, contains the UTF-8 byte encodings of

src/generated/api/apikeys/v2/src/model.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub struct ListKeysRequest {
118118

119119
/// Optional. Specifies the maximum number of results to be returned at a time.
120120
#[serde(skip_serializing_if = "wkt::internal::is_default")]
121+
#[serde_as(as = "wkt::internal::I32")]
121122
pub page_size: i32,
122123

123124
/// Optional. Requests a specific page of results.

src/generated/api/cloudquotas/v1/src/model.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub struct ListQuotaInfosRequest {
5050
/// Optional. Requested page size. Server may return fewer items than
5151
/// requested. If unspecified, server will pick an appropriate default.
5252
#[serde(skip_serializing_if = "wkt::internal::is_default")]
53+
#[serde_as(as = "wkt::internal::I32")]
5354
pub page_size: i32,
5455

5556
/// Optional. A token identifying a page of results the server should return.
@@ -209,6 +210,7 @@ pub struct ListQuotaPreferencesRequest {
209210
/// Optional. Requested page size. Server may return fewer items than
210211
/// requested. If unspecified, server will pick an appropriate default.
211212
#[serde(skip_serializing_if = "wkt::internal::is_default")]
213+
#[serde_as(as = "wkt::internal::I32")]
212214
pub page_size: i32,
213215

214216
/// Optional. A token identifying a page of results the server should return.

src/generated/api/servicecontrol/v1/src/model.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ pub mod distribution {
681681
/// the total number of buckets is `num_finite_buckets` + 2.
682682
/// See comments on `bucket_options` for details.
683683
#[serde(skip_serializing_if = "wkt::internal::is_default")]
684+
#[serde_as(as = "wkt::internal::I32")]
684685
pub num_finite_buckets: i32,
685686

686687
/// The i'th linear bucket covers the interval
@@ -742,6 +743,7 @@ pub mod distribution {
742743
/// the total number of buckets is `num_finite_buckets` + 2.
743744
/// See comments on `bucket_options` for details.
744745
#[serde(skip_serializing_if = "wkt::internal::is_default")]
746+
#[serde_as(as = "wkt::internal::I32")]
745747
pub num_finite_buckets: i32,
746748

747749
/// The i'th exponential bucket covers the interval
@@ -910,6 +912,7 @@ pub struct HttpRequest {
910912
/// The response code indicating the status of the response.
911913
/// Examples: 200, 404.
912914
#[serde(skip_serializing_if = "wkt::internal::is_default")]
915+
#[serde_as(as = "wkt::internal::I32")]
913916
pub status: i32,
914917

915918
/// The size of the HTTP response message sent back to the client, in bytes,

src/generated/api/servicemanagement/v1/src/model.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub struct OperationMetadata {
9999

100100
/// Percentage of completion of this operation, ranging from 0 to 100.
101101
#[serde(skip_serializing_if = "wkt::internal::is_default")]
102+
#[serde_as(as = "wkt::internal::I32")]
102103
pub progress_percentage: i32,
103104

104105
/// The start time of the operation.
@@ -1386,6 +1387,7 @@ pub struct ListServicesRequest {
13861387
/// The max number of items to include in the response list. Page size is 50
13871388
/// if not specified. Maximum value is 500.
13881389
#[serde(skip_serializing_if = "wkt::internal::is_default")]
1390+
#[serde_as(as = "wkt::internal::I32")]
13891391
pub page_size: i32,
13901392

13911393
/// Token identifying which result to start with; returned by a previous list
@@ -1910,6 +1912,7 @@ pub struct ListServiceConfigsRequest {
19101912
/// The max number of items to include in the response list. Page size is 50
19111913
/// if not specified. Maximum value is 100.
19121914
#[serde(skip_serializing_if = "wkt::internal::is_default")]
1915+
#[serde_as(as = "wkt::internal::I32")]
19131916
pub page_size: i32,
19141917

19151918
#[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
@@ -2250,6 +2253,7 @@ pub struct ListServiceRolloutsRequest {
22502253
/// The max number of items to include in the response list. Page size is 50
22512254
/// if not specified. Maximum value is 100.
22522255
#[serde(skip_serializing_if = "wkt::internal::is_default")]
2256+
#[serde_as(as = "wkt::internal::I32")]
22532257
pub page_size: i32,
22542258

22552259
/// Required. Use `filter` to return subset of rollouts.

src/generated/api/serviceusage/v1/src/model.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ pub struct ListServicesRequest {
759759
/// Requested page size cannot exceed 200.
760760
/// If not set, the default page size is 50.
761761
#[serde(skip_serializing_if = "wkt::internal::is_default")]
762+
#[serde_as(as = "wkt::internal::I32")]
762763
pub page_size: i32,
763764

764765
/// Token identifying which result to start with, which is returned by a

src/generated/api/types/src/model.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3661,6 +3661,7 @@ pub mod distribution {
36613661
pub struct Linear {
36623662
/// Must be greater than 0.
36633663
#[serde(skip_serializing_if = "wkt::internal::is_default")]
3664+
#[serde_as(as = "wkt::internal::I32")]
36643665
pub num_finite_buckets: i32,
36653666

36663667
/// Must be greater than 0.
@@ -3724,6 +3725,7 @@ pub mod distribution {
37243725
pub struct Exponential {
37253726
/// Must be greater than 0.
37263727
#[serde(skip_serializing_if = "wkt::internal::is_default")]
3728+
#[serde_as(as = "wkt::internal::I32")]
37273729
pub num_finite_buckets: i32,
37283730

37293731
/// Must be greater than 1.
@@ -8939,6 +8941,7 @@ pub struct Service {
89398941
/// This field has no semantic meaning. The service config compiler always
89408942
/// sets this field to `3`.
89418943
#[serde(skip_serializing_if = "std::option::Option::is_none")]
8944+
#[serde_as(as = "std::option::Option<_>")]
89428945
pub config_version: std::option::Option<wkt::UInt32Value>,
89438946

89448947
#[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]

0 commit comments

Comments
 (0)