File tree 5 files changed +45
-31
lines changed
rabbitmq_amqp_python_client
5 files changed +45
-31
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ def __init__(self):
36
36
self ._count = 0
37
37
38
38
def on_message (self , event : Event ):
39
- print ("received message: " + str (event .message .body ))
39
+ print ("received message: " + Converter . bytes_to_string (event .message .body ))
40
40
41
41
# accepting
42
42
self .delivery_context .accept (event )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 86
86
from ._endpoints import Link
87
87
from ._exceptions import (
88
88
EXCEPTIONS ,
89
- ArgumentOutOfRangeException ,
90
89
MessageException ,
91
90
)
92
91
93
92
if TYPE_CHECKING :
94
- from proton ._data import Described , PythonAMQPData
93
+ from proton ._data import PythonAMQPData
95
94
from proton ._delivery import Delivery
96
95
from proton ._endpoints import Receiver , Sender
97
96
Original file line number Diff line number Diff line change @@ -7,3 +7,45 @@ def validate_annotations(annotations: []) -> bool: # type: ignore
7
7
validated = False
8
8
return validated
9
9
return validated
10
+
11
+
12
+ def string_to_bytes (body : str ) -> bytes :
13
+ """
14
+ Convert a string to the body of a message.
15
+
16
+ Args:
17
+ body: The string to convert
18
+
19
+ Returns:
20
+ bytes: The byte representation of the string
21
+ """
22
+ return str .encode (body )
23
+
24
+
25
+ class Converter :
26
+
27
+ @staticmethod
28
+ def bytes_to_string (body : bytes ) -> str :
29
+ """
30
+ Convert the body of a message to a string.
31
+
32
+ Args:
33
+ body: The body of the message
34
+
35
+ Returns:
36
+ str: The string representation of the body
37
+ """
38
+ return "" .join (map (chr , body ))
39
+
40
+ @staticmethod
41
+ def string_to_bytes (body : str ) -> bytes :
42
+ """
43
+ Convert a string to the body of a message.
44
+
45
+ Args:
46
+ body: The string to convert
47
+
48
+ Returns:
49
+ bytes: The byte representation of the string
50
+ """
51
+ return str .encode (body )
Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ def test_publish_to_invalid_destination(connection: Connection) -> None:
131
131
publisher = None
132
132
try :
133
133
publisher = connection .publisher ("/invalid-destination/" + queue_name )
134
- publisher .publish (Message (body = string_to_bytes ("test" )))
134
+ publisher .publish (Message (body = Converter . string_to_bytes ("test" )))
135
135
except ArgumentOutOfRangeException :
136
136
raised = True
137
137
except Exception :
You can’t perform that action at this time.
0 commit comments