1
- use fe2o3_amqp_types:: messaging :: { Data as AmqpData , Properties , ApplicationProperties } ;
2
- use fe2o3_amqp_types:: primitives :: { Binary , SimpleValue , Symbol } ;
1
+ use fe2o3_amqp_types:: primitives :: { SimpleValue , Symbol , Binary } ;
2
+ use fe2o3_amqp_types:: messaging :: { Data as AmqpData } ;
3
3
4
- use crate :: binding:: header_prefix;
5
4
use crate :: message:: StructuredSerializer ;
6
- use crate :: {
7
- event:: SpecVersion ,
8
- message:: { BinarySerializer , Error , MessageAttributeValue } ,
9
- } ;
5
+ use crate :: { message:: { BinarySerializer , MessageAttributeValue , Error } , event:: SpecVersion } ;
10
6
11
7
use super :: constants:: DATACONTENTTYPE ;
12
- use super :: { AmqpBody , AmqpMessage , ATTRIBUTE_PREFIX } ;
8
+ use super :: { AmqpCloudEvent , ATTRIBUTE_PREFIX , AmqpBody } ;
13
9
14
- impl BinarySerializer < AmqpMessage > for AmqpMessage {
10
+ impl BinarySerializer < AmqpCloudEvent > for AmqpCloudEvent {
15
11
fn set_spec_version ( mut self , spec_version : SpecVersion ) -> crate :: message:: Result < Self > {
16
12
let key = String :: from ( "cloudEvents:specversion" ) ;
17
13
let value = String :: from ( spec_version. as_str ( ) ) ;
18
- self . application_properties
19
- . get_or_insert ( ApplicationProperties :: default ( ) )
20
- . insert ( key, SimpleValue :: from ( value) ) ;
14
+ self . application_properties . insert ( key, SimpleValue :: from ( value) ) ;
21
15
Ok ( self )
22
16
}
23
17
24
- fn set_attribute (
25
- mut self ,
26
- name : & str ,
27
- value : MessageAttributeValue ,
28
- ) -> crate :: message:: Result < Self > {
18
+ fn set_attribute ( mut self , name : & str , value : MessageAttributeValue ) -> crate :: message:: Result < Self > {
29
19
// For the binary mode, the AMQP content-type property field value maps directly to the
30
20
// CloudEvents datacontenttype attribute.
31
- //
21
+ //
32
22
// All CloudEvents attributes with exception of datacontenttype MUST be individually mapped
33
23
// to and from the AMQP application-properties section.
34
24
if name == DATACONTENTTYPE {
35
- self . properties
36
- . get_or_insert ( Properties :: default ( ) )
37
- . content_type = match value {
25
+ self . content_type = match value {
38
26
MessageAttributeValue :: String ( s) => Some ( Symbol :: from ( s) ) ,
39
- _ => return Err ( Error :: WrongEncoding { } ) ,
27
+ _ => return Err ( Error :: WrongEncoding { } )
40
28
}
41
29
} else {
42
30
// CloudEvent attributes are prefixed with "cloudEvents:" for use in the
43
31
// application-properties section
44
- let key = header_prefix ( ATTRIBUTE_PREFIX , name) ;
32
+ let key = format ! ( "{}:{}" , ATTRIBUTE_PREFIX , name) ;
45
33
let value = SimpleValue :: from ( value) ;
46
- self . application_properties
47
- . get_or_insert ( ApplicationProperties :: default ( ) )
48
- . insert ( key, value) ;
34
+ self . application_properties . insert ( key, value) ;
49
35
}
50
36
51
37
Ok ( self )
@@ -57,16 +43,10 @@ impl BinarySerializer<AmqpMessage> for AmqpMessage {
57
43
// systems that also process the message. Extension specifications that do this SHOULD specify
58
44
// how receivers are to interpret messages if the copied values differ from the cloud-event
59
45
// serialized values.
60
- fn set_extension (
61
- mut self ,
62
- name : & str ,
63
- value : MessageAttributeValue ,
64
- ) -> crate :: message:: Result < Self > {
65
- let key = header_prefix ( ATTRIBUTE_PREFIX , name) ;
46
+ fn set_extension ( mut self , name : & str , value : MessageAttributeValue ) -> crate :: message:: Result < Self > {
47
+ let key = format ! ( "{}:{}" , ATTRIBUTE_PREFIX , name) ;
66
48
let value = SimpleValue :: from ( value) ;
67
- self . application_properties
68
- . get_or_insert ( ApplicationProperties :: default ( ) )
69
- . insert ( key, value) ;
49
+ self . application_properties . insert ( key, value) ;
70
50
Ok ( self )
71
51
}
72
52
@@ -81,11 +61,9 @@ impl BinarySerializer<AmqpMessage> for AmqpMessage {
81
61
}
82
62
}
83
63
84
- impl StructuredSerializer < AmqpMessage > for AmqpMessage {
64
+ impl StructuredSerializer < AmqpCloudEvent > for AmqpCloudEvent {
85
65
fn set_structured_event ( mut self , bytes : Vec < u8 > ) -> crate :: message:: Result < Self > {
86
- self . properties
87
- . get_or_insert ( Properties :: default ( ) )
88
- . content_type = Some ( Symbol :: from ( "application/cloudevents+json; charset=utf-8" ) ) ;
66
+ self . content_type = Some ( Symbol :: from ( "application/cloudevents+json; charset=utf-8" ) ) ;
89
67
self . body = AmqpBody :: Data ( AmqpData ( Binary :: from ( bytes) ) ) ;
90
68
Ok ( self )
91
69
}
0 commit comments