@@ -67,19 +67,7 @@ impl Message {
67
67
. content ( |content|{
68
68
match self {
69
69
Message :: QueryMessage ( msg) => {
70
- match msg {
71
- QueryMessage :: ListQuery => {
72
- content. element (
73
- QUERY_PDU_LIST . into_unqualified ( )
74
- ) ?;
75
- } ,
76
- QueryMessage :: Delta ( delta) => {
77
- for el in & delta. 0 {
78
- el. write_xml ( content) ?;
79
-
80
- }
81
- }
82
- }
70
+ msg. write_xml ( content) ?;
83
71
}
84
72
Message :: ReplyMessage ( msg) => {
85
73
msg. write_xml ( content) ?;
@@ -239,6 +227,31 @@ impl QueryMessage {
239
227
}
240
228
241
229
230
+ /// # Encoding to XML
231
+ ///
232
+ impl QueryMessage {
233
+ fn write_xml < W : io:: Write > (
234
+ & self ,
235
+ content : & mut encode:: Content < W >
236
+ ) -> Result < ( ) , io:: Error > {
237
+ match self {
238
+ QueryMessage :: ListQuery => {
239
+ content. element (
240
+ QUERY_PDU_LIST . into_unqualified ( )
241
+ ) ?;
242
+ } ,
243
+ QueryMessage :: Delta ( delta) => {
244
+ for el in & delta. 0 {
245
+ el. write_xml ( content) ?;
246
+ }
247
+ }
248
+ }
249
+
250
+ Ok ( ( ) )
251
+ }
252
+ }
253
+
254
+
242
255
//------------ QueryPduType --------------------------------------------------
243
256
244
257
#[ derive( Clone , Debug , Eq , PartialEq ) ]
@@ -437,40 +450,15 @@ impl PublishDeltaElement {
437
450
) -> Result < ( ) , io:: Error > {
438
451
match self {
439
452
PublishDeltaElement :: Publish ( p) => {
440
- content. element (
441
- QUERY_PDU_PUBLISH
442
- . into_unqualified ( )
443
- ) ?
444
- . attr ( "tag" , p. tag_for_xml ( ) ) ?
445
- . attr ( "uri" , & p. uri ) ?
446
- . content ( |content| {
447
- content. raw ( & p. content )
448
- } ) ?;
453
+ p. write_xml ( content)
449
454
} ,
450
455
PublishDeltaElement :: Update ( u) => {
451
- content. element (
452
- QUERY_PDU_PUBLISH
453
- . into_unqualified ( )
454
- ) ?
455
- . attr ( "tag" , u. tag_for_xml ( ) ) ?
456
- . attr ( "uri" , & u. uri ) ?
457
- . attr ( "hash" , & u. hash ) ?
458
- . content ( |content| {
459
- content. raw ( & u. content )
460
- } ) ?;
456
+ u. write_xml ( content)
461
457
} ,
462
458
PublishDeltaElement :: Withdraw ( w) => {
463
- content. element (
464
- QUERY_PDU_WITHDRAW
465
- . into_unqualified ( )
466
- ) ?
467
- . attr ( "tag" , w. tag_for_xml ( ) ) ?
468
- . attr ( "uri" , & w. uri ) ?
469
- . attr ( "hash" , & w. hash ) ?;
459
+ w. write_xml ( content)
470
460
}
471
461
}
472
-
473
- Ok ( ( ) )
474
462
}
475
463
}
476
464
@@ -485,7 +473,22 @@ pub struct Publish {
485
473
content : Base64 ,
486
474
}
487
475
476
+ /// # Encode to XML
477
+ ///
488
478
impl Publish {
479
+ fn write_xml < W : io:: Write > (
480
+ & self ,
481
+ content : & mut encode:: Content < W >
482
+ ) -> Result < ( ) , io:: Error > {
483
+ content
484
+ . element ( QUERY_PDU_PUBLISH . into_unqualified ( ) ) ?
485
+ . attr ( "tag" , self . tag_for_xml ( ) ) ?
486
+ . attr ( "uri" , & self . uri ) ?
487
+ . content ( |content| content. raw ( & self . content ) ) ?;
488
+
489
+ Ok ( ( ) )
490
+ }
491
+
489
492
fn tag_for_xml ( & self ) -> & str {
490
493
self . tag . as_deref ( ) . unwrap_or ( "" )
491
494
}
@@ -504,7 +507,23 @@ pub struct Update {
504
507
hash : rrdp:: Hash ,
505
508
}
506
509
510
+ /// # Encode to XML
511
+ ///
507
512
impl Update {
513
+ fn write_xml < W : io:: Write > (
514
+ & self ,
515
+ content : & mut encode:: Content < W >
516
+ ) -> Result < ( ) , io:: Error > {
517
+ content
518
+ . element ( QUERY_PDU_PUBLISH . into_unqualified ( ) ) ?
519
+ . attr ( "tag" , self . tag_for_xml ( ) ) ?
520
+ . attr ( "uri" , & self . uri ) ?
521
+ . attr ( "hash" , & self . hash ) ?
522
+ . content ( |content| content. raw ( & self . content ) ) ?;
523
+
524
+ Ok ( ( ) )
525
+ }
526
+
508
527
fn tag_for_xml ( & self ) -> & str {
509
528
self . tag . as_deref ( ) . unwrap_or ( "" )
510
529
}
@@ -522,7 +541,22 @@ pub struct Withdraw {
522
541
hash : rrdp:: Hash ,
523
542
}
524
543
544
+ /// # Encode to XML
545
+ ///
525
546
impl Withdraw {
547
+ fn write_xml < W : io:: Write > (
548
+ & self ,
549
+ content : & mut encode:: Content < W >
550
+ ) -> Result < ( ) , io:: Error > {
551
+ content. element ( QUERY_PDU_WITHDRAW . into_unqualified ( ) ) ?
552
+ . attr ( "tag" , self . tag_for_xml ( ) ) ?
553
+ . attr ( "uri" , & self . uri ) ?
554
+ . attr ( "hash" , & self . hash ) ?;
555
+
556
+ Ok ( ( ) )
557
+ }
558
+
559
+
526
560
fn tag_for_xml ( & self ) -> & str {
527
561
self . tag . as_deref ( ) . unwrap_or ( "" )
528
562
}
@@ -776,11 +810,7 @@ impl ReplyMessage {
776
810
match self {
777
811
ReplyMessage :: ListReply ( list) => {
778
812
for el in & list. elements {
779
- content. element (
780
- REPLY_PDU_LIST . into_unqualified ( )
781
- ) ?
782
- . attr ( "uri" , & el. uri ) ?
783
- . attr ( "hash" , & el. hash ) ?;
813
+ el. write_xml ( content) ?;
784
814
}
785
815
}
786
816
ReplyMessage :: Success => {
@@ -790,31 +820,7 @@ impl ReplyMessage {
790
820
}
791
821
ReplyMessage :: ErrorReply ( errors) => {
792
822
for err in & errors. errors {
793
- content. element (
794
- REPLY_PDU_ERROR . into_unqualified ( )
795
- ) ?
796
- . attr ( "error_code" , & err. error_code ) ?
797
- . attr ( "tag" , err. tag_for_xml ( ) ) ?
798
- . content ( |content| {
799
- content. element (
800
- REPLY_PDU_ERROR_TEXT . into_unqualified ( )
801
- ) ?
802
- . content ( |error_text_content|
803
- error_text_content. raw ( err. error_text_or_default ( ) )
804
- ) ?;
805
-
806
- content. opt_element (
807
- err. failed_pdu . as_ref ( ) ,
808
- REPLY_PDU_ERROR_PDU . into_unqualified ( ) ,
809
- |pdu, element| {
810
- element. content ( |content|
811
- pdu. write_xml ( content)
812
- ) ?;
813
- Ok ( ( ) )
814
- }
815
- ) ?;
816
- Ok ( ( ) )
817
- } ) ?;
823
+ err. write_xml ( content) ?;
818
824
}
819
825
}
820
826
}
@@ -872,6 +878,21 @@ pub struct ListElement {
872
878
hash : rrdp:: Hash ,
873
879
}
874
880
881
+ /// # Encoding to XML
882
+ ///
883
+ impl ListElement {
884
+ fn write_xml < W : io:: Write > (
885
+ & self ,
886
+ content : & mut encode:: Content < W >
887
+ ) -> Result < ( ) , io:: Error > {
888
+ content. element (
889
+ REPLY_PDU_LIST . into_unqualified ( )
890
+ ) ?
891
+ . attr ( "uri" , & self . uri ) ?
892
+ . attr ( "hash" , & self . hash ) ?;
893
+ Ok ( ( ) )
894
+ }
895
+ }
875
896
876
897
//------------ ErrorReply ----------------------------------------------------
877
898
@@ -893,6 +914,43 @@ pub struct ReportError {
893
914
failed_pdu : Option < QueryPdu > ,
894
915
}
895
916
917
+ /// # Encode to XML
918
+ ///
919
+ impl ReportError {
920
+ fn write_xml < W : io:: Write > (
921
+ & self ,
922
+ content : & mut encode:: Content < W >
923
+ ) -> Result < ( ) , io:: Error > {
924
+ content. element (
925
+ REPLY_PDU_ERROR . into_unqualified ( )
926
+ ) ?
927
+ . attr ( "error_code" , & self . error_code ) ?
928
+ . attr ( "tag" , self . tag_for_xml ( ) ) ?
929
+ . content ( |content| {
930
+ content. element (
931
+ REPLY_PDU_ERROR_TEXT . into_unqualified ( )
932
+ ) ?
933
+ . content ( |error_text_content|
934
+ error_text_content. raw ( self . error_text_or_default ( ) )
935
+ ) ?;
936
+
937
+ content. opt_element (
938
+ self . failed_pdu . as_ref ( ) ,
939
+ REPLY_PDU_ERROR_PDU . into_unqualified ( ) ,
940
+ |pdu, element| {
941
+ element. content ( |content|
942
+ pdu. write_xml ( content)
943
+ ) ?;
944
+ Ok ( ( ) )
945
+ }
946
+ ) ?;
947
+ Ok ( ( ) )
948
+ } ) ?;
949
+
950
+ Ok ( ( ) )
951
+ }
952
+ }
953
+
896
954
impl ReportError {
897
955
fn tag_for_xml ( & self ) -> & str {
898
956
self . tag . as_deref ( ) . unwrap_or ( "" )
0 commit comments