@@ -97,42 +97,48 @@ def __str__(self) -> str:
97
97
98
98
99
99
class Encoder :
100
- def encodes (self , obj : Any ) -> bytes :
100
+ def encodes (self , obj : Any , py_type : type = None ) -> bytes :
101
101
"""
102
102
Encode an object into bytes.
103
103
104
104
:param obj: the object to encode
105
+ :param py_type: the type of the object. needed by some encoders that don't have implicit type knowledge.
105
106
:return: the encoded object
106
107
"""
107
108
b = io .BytesIO ()
108
109
self .encode (obj , b )
109
110
return b .getvalue ()
110
111
111
- def encode (self , obj : Any , file : IO [bytes ]):
112
+ def encode (self , obj : Any , file : IO [bytes ], py_type : type = None ):
112
113
"""
113
114
Encode an object into bytes.
114
115
115
116
:param obj: the object to encode
117
+ :param py_type: the type of the object. needed by some encoders that don't have implicit type knowledge.
116
118
:param file: the file to write the encoded data into
117
119
"""
118
120
raise NotImplementedError
119
121
120
122
121
123
class Decoder :
122
- def decodes (self , data : bytes ) -> Any :
124
+ def decodes (self , data : bytes , py_type : type = None ) -> Any :
123
125
"""
124
126
Decode a previously encoded object.
125
127
126
128
:param data: the encoded object to decode
129
+ :param py_type: the type that is expected as return type. Needed by some decoders that don't have implicit
130
+ type knowledge.
127
131
:return: the decoded object
128
132
"""
129
- return self .decode (io .BytesIO (data ))
133
+ return self .decode (io .BytesIO (data ), py_type )
130
134
131
- def decode (self , file : IO [bytes ]) -> Any :
135
+ def decode (self , file : IO [bytes ], py_type : type = None ) -> Any :
132
136
"""
133
137
Decode a previously encoded object.
134
138
135
139
:param file: the io object containing the object to decode
140
+ :param py_type: the type that is expected as return type. Needed by some decoders that don't have implicit
141
+ type knowledge.
136
142
:return: the decoded object
137
143
"""
138
144
raise NotImplementedError
0 commit comments