1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
/*
 * Copyright (2024) Volcengine
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
extern crate proc_macro;

use proc_macro::TokenStream;

use quote::quote;
use syn::DeriveInput;
use syn::parse_macro_input;

#[proc_macro_derive(RequestInfo)]
pub fn derive_request_info(input: TokenStream) -> TokenStream {
    let DeriveInput { ident, .. } = parse_macro_input!(input);

    let output = quote! {
        impl #ident{
            pub fn request_id(&self) -> &str {
                &self.request_info.request_id
            }

            pub fn id2(&self) -> &str {
                &self.request_info.id2
            }

            pub fn status_code(&self) -> isize {
                self.request_info.status_code
            }

            pub fn header(&self) -> &std::collections::HashMap<String, String> {
                &self.request_info.header
            }
        }

        impl crate::common::RequestInfoTrait for #ident{
            fn request_id(&self) -> &str {
                &self.request_info.request_id
            }

            fn id2(&self) -> &str {
                &self.request_info.id2
            }

            fn status_code(&self) -> isize {
                self.request_info.status_code
            }

            fn header(&self) -> &std::collections::HashMap<String, String> {
                &self.request_info.header
            }
        }
    };
    output.into()
}

#[proc_macro_derive(FromRefAndDisplay)]
pub fn derive_from_ref(input: TokenStream) -> TokenStream {
    let DeriveInput { ident, .. } = parse_macro_input!(input);
    let output = quote! {
         impl std::fmt::Display for #ident{
            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
                write!(f, "{}", self.as_str())
            }
         }

         impl From<&#ident> for #ident{
            fn from(value: &#ident) -> Self {
                value.to_owned()
            }
         }

    };
    output.into()
}


#[proc_macro_derive(AclHeader, attributes(enable_grant_write, handle_stream, use_inner, handle_async))]
pub fn derive_acl_header(input: TokenStream) -> TokenStream {
    let DeriveInput { ident, attrs, .. } = parse_macro_input!(input);
    let mut visable = quote! {pub(crate) };
    let mut impl_stream = quote! {impl};
    let mut stream_bound = quote! {};
    let mut self_ptr = quote! {self};
    for attr in attrs.iter() {
        if attr.path().is_ident("handle_stream") {
            impl_stream = quote! {impl<B>};
            stream_bound = quote! {<B> where B: std::io::Read + Send + 'static};
        } else if attr.path().is_ident("handle_async") {
            impl_stream = quote! {impl<B>};
            stream_bound = quote! {<B> where B: Stream<Item=Result<bytes::Bytes, crate::error::CommonError>> + Send + Unpin};
        } else if attr.path().is_ident("enable_grant_write") {
            visable = quote! {pub };
        } else if attr.path().is_ident("use_inner") {
            self_ptr = quote! {self.inner};
        }
    }

    let output = quote! {
        #impl_stream #ident #stream_bound{
            pub fn acl(&self) -> &Option<crate::enumeration::ACLType> {
                &#self_ptr.acl
            }
            pub fn grant_full_control(&self) -> &str {
                &#self_ptr.grant_full_control
            }
            pub fn grant_read(&self) -> &str {
                &#self_ptr.grant_read
            }
            pub fn grant_read_acp(&self) -> &str {
                &#self_ptr.grant_read_acp
            }
            #visable fn grant_write(&self) -> &str {
                &#self_ptr.grant_write
            }
            pub fn grant_write_acp(&self) -> &str {
                &#self_ptr.grant_write_acp
            }
            pub fn set_acl(&mut self, acl: impl Into<crate::enumeration::ACLType>) {
                #self_ptr.acl = Some(acl.into());
            }
            pub fn set_grant_full_control(&mut self, grant_full_control: impl Into<String>) {
                #self_ptr.grant_full_control = grant_full_control.into();
            }
            pub fn set_grant_read(&mut self, grant_read: impl Into<String>) {
                #self_ptr.grant_read = grant_read.into();
            }
            pub fn set_grant_read_acp(&mut self, grant_read_acp: impl Into<String>) {
                #self_ptr.grant_read_acp = grant_read_acp.into();
            }
            #visable fn set_grant_write(&mut self, grant_write: impl Into<String>) {
                #self_ptr.grant_write = grant_write.into();
            }
            pub fn set_grant_write_acp(&mut self, grant_write_acp: impl Into<String>) {
                #self_ptr.grant_write_acp = grant_write_acp.into();
            }
        }

        #impl_stream crate::internal::AclHeader for #ident #stream_bound{
            fn acl(&self) -> &Option<crate::enumeration::ACLType> {
                &#self_ptr.acl
            }
            fn grant_full_control(&self) -> &str {
                &#self_ptr.grant_full_control
            }
            fn grant_read(&self) -> &str {
                &#self_ptr.grant_read
            }
            fn grant_read_acp(&self) -> &str {
                &#self_ptr.grant_read_acp
            }
            fn grant_write(&self) -> &str {
                &#self_ptr.grant_write
            }
            fn grant_write_acp(&self) -> &str {
                &#self_ptr.grant_write_acp
            }
        }
    };
    output.into()
}

#[proc_macro_derive(HttpBasicHeader, attributes(enable_content_length, handle_stream, use_inner, handle_async))]
pub fn derive_http_basic_header(input: TokenStream) -> TokenStream {
    let DeriveInput { ident, attrs, .. } = parse_macro_input!(input);
    let mut visable = quote! {pub(crate) };
    let mut content_length = quote! {-1};
    let mut impl_stream = quote! {impl};
    let mut stream_bound = quote! {};
    let mut self_ptr = quote! {self};
    for attr in attrs.iter() {
        if attr.path().is_ident("handle_stream") {
            impl_stream = quote! {impl<B>};
            stream_bound = quote! {<B> where B: std::io::Read + Send + 'static};
        } else if attr.path().is_ident("handle_async") {
            impl_stream = quote! {impl<B>};
            stream_bound = quote! {<B> where B: Stream<Item=Result<bytes::Bytes, crate::error::CommonError>> + Send + Unpin};
        } else if attr.path().is_ident("enable_content_length") {
            visable = quote! {pub };
            content_length = quote! { #self_ptr.content_length };
        } else if attr.path().is_ident("use_inner") {
            self_ptr = quote! {self.inner};
            content_length = quote! { #self_ptr.content_length };
        }
    }

    let output = quote! {
        #impl_stream #ident #stream_bound{
            #visable fn content_length(&self) -> i64{
                #content_length
            }
            pub fn cache_control(&self) -> &str {
                &#self_ptr.cache_control
            }
            pub fn content_disposition(&self) -> &str {
                &#self_ptr.content_disposition
            }
            pub fn content_encoding(&self) -> &str {
                &#self_ptr.content_encoding
            }
            pub fn content_language(&self) -> &str {
                &#self_ptr.content_language
            }
            pub fn content_type(&self) -> &str {
                &#self_ptr.content_type
            }
            pub fn expires(&self) -> Option<DateTime<Utc>> {
                #self_ptr.expires
            }
            #visable fn set_content_length(&mut self, content_length: i64){
                #self_ptr.content_length = content_length;
            }
            pub fn set_cache_control(&mut self, cache_control: impl Into<String>) {
                #self_ptr.cache_control = cache_control.into();
            }
            pub fn set_content_disposition(&mut self, content_disposition: impl Into<String>) {
                #self_ptr.content_disposition = content_disposition.into();
            }
            pub fn set_content_encoding(&mut self, content_encoding: impl Into<String>) {
                #self_ptr.content_encoding = content_encoding.into();
            }
            pub fn set_content_language(&mut self, content_language: impl Into<String>) {
                #self_ptr.content_language = content_language.into();
            }
            pub fn set_content_type(&mut self, content_type: impl Into<String>) {
                #self_ptr.content_type = content_type.into();
            }
            pub fn set_expires(&mut self, expires: impl Into<DateTime<Utc>>) {
                #self_ptr.expires = Some(expires.into());
            }
        }

        #impl_stream crate::internal::HttpBasicHeader for #ident #stream_bound{
            fn content_length(&self) -> i64{
                #content_length
            }
            fn cache_control(&self) -> &str {
                 &#self_ptr.cache_control
            }
            fn content_disposition(&self) -> &str {
                &#self_ptr.content_disposition
            }
            fn content_encoding(&self) -> &str {
                &#self_ptr.content_encoding
            }
            fn content_language(&self) -> &str {
                &#self_ptr.content_language
            }
            fn content_type(&self) -> &str {
                &#self_ptr.content_type
            }
            fn expires(&self) -> Option<DateTime<Utc>> {
                #self_ptr.expires
            }
        }
    };
    output.into()
}

#[proc_macro_derive(MiscHeader, attributes(handle_stream, use_inner, hanle_async))]
pub fn derive_misc_header(input: TokenStream) -> TokenStream {
    let DeriveInput { ident, attrs, .. } = parse_macro_input!(input);
    let mut impl_stream = quote! {impl};
    let mut stream_bound = quote! {};
    let mut self_ptr = quote! {self};
    for attr in attrs.iter() {
        if attr.path().is_ident("handle_stream") {
            impl_stream = quote! {impl<B>};
            stream_bound = quote! {<B> where B: std::io::Read + Send + 'static};
        } else if attr.path().is_ident("handle_async") {
            impl_stream = quote! {impl<B>};
            stream_bound = quote! {<B> where B: Stream<Item=Result<bytes::Bytes, crate::error::CommonError>> + Send + Unpin};
        } else if attr.path().is_ident("use_inner") {
            self_ptr = quote! {self.inner};
        }
    }
    let output = quote! {
        #impl_stream #ident #stream_bound{
            pub fn website_redirect_location(&self) -> &str{
                &#self_ptr.website_redirect_location
            }
            pub fn storage_class(&self) -> &Option<crate::enumeration::StorageClassType>{
                &#self_ptr.storage_class
            }
            pub fn set_website_redirect_location(&mut self, website_redirect_location: impl Into<String>){
                #self_ptr.website_redirect_location = website_redirect_location.into();
            }
            pub fn set_storage_class(&mut self, storage_class: impl Into<crate::enumeration::StorageClassType>){
                #self_ptr.storage_class = Some(storage_class.into());
            }
        }

        #impl_stream crate::internal::MiscHeader for #ident #stream_bound{
            fn website_redirect_location(&self) -> &str{
                &#self_ptr.website_redirect_location
            }
            fn storage_class(&self) -> &Option<crate::enumeration::StorageClassType>{
                &#self_ptr.storage_class
            }
        }
    };
    output.into()
}

#[proc_macro_derive(SseHeader, attributes(handle_stream, use_inner, hanle_async))]
pub fn derive_sse_header(input: TokenStream) -> TokenStream {
    let DeriveInput { ident, attrs, .. } = parse_macro_input!(input);
    let mut impl_stream = quote! {impl};
    let mut stream_bound = quote! {};
    let mut self_ptr = quote! {self};
    for attr in attrs.iter() {
        if attr.path().is_ident("handle_stream") {
            impl_stream = quote! {impl<B>};
            stream_bound = quote! {<B> where B: std::io::Read + Send + 'static};
        } else if attr.path().is_ident("handle_async") {
            impl_stream = quote! {impl<B>};
            stream_bound = quote! {<B> where B: Stream<Item=Result<bytes::Bytes, crate::error::CommonError>> + Send + Unpin};
        } else if attr.path().is_ident("use_inner") {
            self_ptr = quote! {self.inner};
        }
    }
    let output = quote! {
        #impl_stream #ident #stream_bound{
            pub fn server_side_encryption(&self) -> &str{
                &#self_ptr.server_side_encryption
            }
            pub fn server_side_encryption_key_id(&self) -> &str{
                &#self_ptr.server_side_encryption_key_id
            }
            pub fn set_server_side_encryption(&mut self, server_side_encryption: impl Into<String>){
                #self_ptr.server_side_encryption = server_side_encryption.into();
            }
            pub fn set_server_side_encryption_key_id(&mut self, server_side_encryption_key_id: impl Into<String>){
                #self_ptr.server_side_encryption_key_id = server_side_encryption_key_id.into();
            }
        }

        #impl_stream crate::internal::SseHeader for #ident #stream_bound{
            fn server_side_encryption(&self) -> &str{
                &#self_ptr.server_side_encryption
            }
            fn server_side_encryption_key_id(&self) -> &str{
                &#self_ptr.server_side_encryption_key_id
            }
        }

    };
    output.into()
}

#[proc_macro_derive(SsecHeader, attributes(handle_stream, use_inner, handle_async))]
pub fn derive_ssec_header(input: TokenStream) -> TokenStream {
    let DeriveInput { ident, attrs, .. } = parse_macro_input!(input);
    let mut impl_stream = quote! {impl};
    let mut stream_bound = quote! {};
    let mut self_ptr = quote! {self};
    for attr in attrs.iter() {
        if attr.path().is_ident("handle_stream") {
            impl_stream = quote! {impl<B>};
            stream_bound = quote! {<B> where B: std::io::Read + Send + 'static};
        } else if attr.path().is_ident("handle_async") {
            impl_stream = quote! {impl<B>};
            stream_bound = quote! {<B> where B: Stream<Item=Result<bytes::Bytes, crate::error::CommonError>> + Send + Unpin};
        } else if attr.path().is_ident("use_inner") {
            self_ptr = quote! {self.inner};
        }
    }
    let output = quote! {
        #impl_stream #ident #stream_bound{
            pub fn ssec_algorithm(&self) -> &str{
                &#self_ptr.ssec_algorithm
            }
            pub fn ssec_key(&self) -> &str{
                &#self_ptr.ssec_key
            }
            pub fn ssec_key_md5(&self) -> &str{
                &#self_ptr.ssec_key_md5
            }
            pub fn set_ssec_algorithm(&mut self, ssec_algorithm: impl Into<String>){
                #self_ptr.ssec_algorithm = ssec_algorithm.into();
            }
            pub fn set_ssec_key(&mut self, ssec_key: impl Into<String>){
                #self_ptr.ssec_key = ssec_key.into();
            }
            pub fn set_ssec_key_md5(&mut self, ssec_key_md5: impl Into<String>){
                #self_ptr.ssec_key_md5 = ssec_key_md5.into();
            }
        }

        #impl_stream crate::internal::SsecHeader for #ident #stream_bound{
            fn ssec_algorithm(&self) -> &str{
                &#self_ptr.ssec_algorithm
            }
            fn ssec_key(&self) -> &str{
                &#self_ptr.ssec_key
            }
            fn ssec_key_md5(&self) -> &str{
                &#self_ptr.ssec_key_md5
            }
        }

    };
    output.into()
}


#[proc_macro_derive(CopySourceHeader)]
pub fn derive_copy_source_header(input: TokenStream) -> TokenStream {
    let DeriveInput { ident, .. } = parse_macro_input!(input);
    let output = quote! {
        impl #ident{
            pub fn src_bucket(&self) -> &str{
                &self.src_bucket
            }
            pub fn src_key(&self) -> &str{
                &self.src_key
            }
            pub fn src_version_id(&self) -> &str{
                &self.src_version_id
            }
            pub fn set_src_bucket(&mut self, src_bucket: impl Into<String>) {
                self.src_bucket = src_bucket.into();
            }
            pub fn set_src_key(&mut self, src_key: impl Into<String>) {
                self.src_key = src_key.into();
            }
            pub fn set_src_version_id(&mut self, src_version_id: impl Into<String>) {
                self.src_version_id = src_version_id.into();
            }
        }

        impl crate::internal::CopySourceHeader for #ident{
            fn src_bucket(&self) -> &str{
                &self.src_bucket
            }
            fn src_key(&self) -> &str{
                &self.src_key
            }
            fn src_version_id(&self) -> &str{
                &self.src_version_id
            }
        }

    };
    output.into()
}

#[proc_macro_derive(CopySourceSSecHeader)]
pub fn derive_copy_source_ssec_header(input: TokenStream) -> TokenStream {
    let DeriveInput { ident, .. } = parse_macro_input!(input);
    let output = quote! {
        impl #ident{
            pub fn copy_source_ssec_algorithm(&self) -> &str{
                &self.copy_source_ssec_algorithm
            }
            pub fn copy_source_ssec_key(&self) -> &str{
                &self.copy_source_ssec_key
            }
            pub fn copy_source_ssec_key_md5(&self) -> &str{
                &self.copy_source_ssec_key_md5
            }
            pub fn set_copy_source_ssec_algorithm(&mut self, copy_source_ssec_algorithm: impl Into<String>){
                self.copy_source_ssec_algorithm = copy_source_ssec_algorithm.into();
            }
            pub fn set_copy_source_ssec_key(&mut self, copy_source_ssec_key: impl Into<String>){
                self.copy_source_ssec_key = copy_source_ssec_key.into();
            }
            pub fn set_copy_source_ssec_key_md5(&mut self, copy_source_ssec_key_md5: impl Into<String>){
                self.copy_source_ssec_key_md5 = copy_source_ssec_key_md5.into();
            }
        }

        impl crate::internal::CopySourceSSecHeader for #ident{
            fn copy_source_ssec_algorithm(&self) -> &str{
                &self.copy_source_ssec_algorithm
            }
            fn copy_source_ssec_key(&self) -> &str{
                &self.copy_source_ssec_key
            }
            fn copy_source_ssec_key_md5(&self) -> &str{
                &self.copy_source_ssec_key_md5
            }
        }
    };
    output.into()
}

#[proc_macro_derive(IfConditionHeader)]
pub fn derive_if_condition_header(input: TokenStream) -> TokenStream {
    let DeriveInput { ident, .. } = parse_macro_input!(input);
    let output = quote! {
        impl #ident{
            pub fn if_match(&self) -> &str{
                &self.if_match
            }
            pub fn if_modified_since(&self) -> Option<DateTime<Utc>>{
                self.if_modified_since
            }
            pub fn if_none_match(&self) -> &str{
                &self.if_none_match
            }
            pub fn if_unmodified_since(&self) -> Option<DateTime<Utc>>{
                self.if_unmodified_since
            }
            pub fn set_if_match(&mut self, if_match: impl Into<String>){
                self.if_match = if_match.into();
            }
            pub fn set_if_modified_since(&mut self, if_modified_since: impl Into<DateTime<Utc>>){
                self.if_modified_since = Some(if_modified_since.into());
            }
            pub fn set_if_none_match(&mut self, if_none_match: impl Into<String>){
                self.if_none_match = if_none_match.into();
            }
            pub fn set_if_unmodified_since(&mut self, if_unmodified_since: impl Into<DateTime<Utc>>){
                self.if_unmodified_since = Some(if_unmodified_since.into())
            }
        }

        impl crate::internal::IfConditionHeader for #ident{
            fn if_match(&self) -> &str{
                &self.if_match
            }
            fn if_modified_since(&self) -> Option<DateTime<Utc>>{
                self.if_modified_since
            }
            fn if_none_match(&self) -> &str{
                &self.if_none_match
            }
            fn if_unmodified_since(&self) -> Option<DateTime<Utc>>{
                self.if_unmodified_since
            }
        }
    };
    output.into()
}

#[proc_macro_derive(CopySourceIfConditionHeader)]
pub fn derive_copy_source_if_condition_header(input: TokenStream) -> TokenStream {
    let DeriveInput { ident, .. } = parse_macro_input!(input);
    let output = quote! {
        impl #ident{
            pub fn copy_source_if_match(&self) -> &str{
                &self.copy_source_if_match
            }
            pub fn copy_source_if_modified_since(&self) -> Option<DateTime<Utc>>{
                self.copy_source_if_modified_since
            }
            pub fn copy_source_if_none_match(&self) -> &str{
                &self.copy_source_if_none_match
            }
            pub fn copy_source_if_unmodified_since(&self) -> Option<DateTime<Utc>>{
                self.copy_source_if_unmodified_since
            }
            pub fn set_copy_source_if_match(&mut self, copy_source_if_match: impl Into<String>){
                self.copy_source_if_match = copy_source_if_match.into();
            }
            pub fn set_copy_source_if_modified_since(&mut self, copy_source_if_modified_since: impl Into<DateTime<Utc>>){
                self.copy_source_if_modified_since = Some(copy_source_if_modified_since.into());
            }
            pub fn set_copy_source_if_none_match(&mut self, copy_source_if_none_match: impl Into<String>){
                self.copy_source_if_none_match = copy_source_if_none_match.into();
            }
            pub fn set_copy_source_if_unmodified_since(&mut self, copy_source_if_unmodified_since: impl Into<DateTime<Utc>>){
                self.copy_source_if_unmodified_since = Some(copy_source_if_unmodified_since.into())
            }
        }

        impl crate::internal::CopySourceIfConditionHeader for #ident{
            fn copy_source_if_match(&self) -> &str{
                &self.copy_source_if_match
            }
            fn copy_source_if_modified_since(&self) -> Option<DateTime<Utc>>{
                self.copy_source_if_modified_since
            }
            fn copy_source_if_none_match(&self) -> &str{
                &self.copy_source_if_none_match
            }
            fn copy_source_if_unmodified_since(&self) -> Option<DateTime<Utc>>{
                self.copy_source_if_unmodified_since
            }
        }
    };
    output.into()
}

#[proc_macro_derive(CallbackHeader, attributes(handle_stream, use_inner, handle_async))]
pub fn derive_callback_header(input: TokenStream) -> TokenStream {
    let DeriveInput { ident, attrs, .. } = parse_macro_input!(input);
    let mut impl_stream = quote! {impl};
    let mut stream_bound = quote! {};
    let mut self_ptr = quote! {self};
    for attr in attrs.iter() {
        if attr.path().is_ident("handle_stream") {
            impl_stream = quote! {impl<B>};
            stream_bound = quote! {<B> where B: std::io::Read + Send + 'static};
        } else if attr.path().is_ident("handle_async") {
            impl_stream = quote! {impl<B>};
            stream_bound = quote! {<B> where B: Stream<Item=Result<bytes::Bytes, crate::error::CommonError>> + Send + Unpin};
        } else if attr.path().is_ident("use_inner") {
            self_ptr = quote! {self.inner};
        }
    }
    let output = quote! {
        #impl_stream #ident #stream_bound{
            pub fn callback(&self) -> &str {
                &#self_ptr.callback
            }
            pub fn callback_var(&self) -> &str {
                &#self_ptr.callback_var
            }
            pub fn set_callback(&mut self, callback: impl Into<String>) {
                #self_ptr.callback = callback.into();
            }
            pub fn set_callback_var(&mut self, callback_var: impl Into<String>) {
                #self_ptr.callback_var = callback_var.into();
            }
        }

        #impl_stream crate::internal::CallbackHeader for #ident #stream_bound{
            fn callback(&self) -> &str {
                &#self_ptr.callback
            }
            fn callback_var(&self) -> &str {
                &#self_ptr.callback_var
            }
        }
    };
    output.into()
}

#[proc_macro_derive(ListCommonQuery)]
pub fn derive_list_common_query(input: TokenStream) -> TokenStream {
    let DeriveInput { ident, .. } = parse_macro_input!(input);
    let output = quote! {
        impl #ident{
            pub fn prefix(&self) -> &str {
                &self.prefix
            }
            pub fn delimiter(&self) -> &str {
                &self.delimiter
            }
            pub fn encoding_type(&self) -> &str {
                &self.encoding_type
            }
            pub fn set_prefix(&mut self, prefix: impl Into<String>) {
                self.prefix = prefix.into();
            }
            pub fn set_delimiter(&mut self, delimiter: impl Into<String>) {
                self.delimiter = delimiter.into();
            }
            pub fn set_encoding_type(&mut self, encoding_type: impl Into<String>) {
                self.encoding_type = encoding_type.into();
            }
        }

        impl crate::internal::ListCommonQuery for #ident{
            fn prefix(&self) -> &str {
                &self.prefix
            }
            fn delimiter(&self) -> &str {
                &self.delimiter
            }
            fn encoding_type(&self) -> &str {
                &self.encoding_type
            }
        }
    };
    output.into()
}

#[proc_macro_derive(MultipartUploadQuery, attributes(handle_stream, use_inner, handle_async))]
pub fn derive_multipart_upload_query(input: TokenStream) -> TokenStream {
    let DeriveInput { ident, attrs, .. } = parse_macro_input!(input);
    let mut impl_stream = quote! {impl};
    let mut stream_bound = quote! {};
    let mut self_ptr = quote! {self};
    for attr in attrs.iter() {
        if attr.path().is_ident("handle_stream") {
            impl_stream = quote! {impl<B>};
            stream_bound = quote! {<B> where B: std::io::Read + Send + 'static};
        } else if attr.path().is_ident("handle_async") {
            impl_stream = quote! {impl<B>};
            stream_bound = quote! {<B> where B: Stream<Item=Result<bytes::Bytes, crate::error::TosError>> + Send + Unpin};
        } else if attr.path().is_ident("use_inner") {
            self_ptr = quote! {self.inner};
        }
    }
    let output = quote! {
        #impl_stream #ident #stream_bound{
            pub fn upload_id(&self) -> &str{
                &#self_ptr.upload_id
            }
            pub fn part_number(&self) -> isize{
                #self_ptr.part_number
            }
            pub fn set_upload_id(&mut self, upload_id: impl Into<String>){
                #self_ptr.upload_id = upload_id.into();
            }
            pub fn set_part_number(&mut self, part_number: isize) {
                #self_ptr.part_number = part_number;
            }
        }

         #impl_stream crate::internal::MultipartUploadQuery for #ident #stream_bound{
            fn upload_id(&self) -> &str{
                &#self_ptr.upload_id
            }
            fn part_number(&self) -> isize{
                #self_ptr.part_number
            }
        }
    };
    output.into()
}