@@ -220,17 +220,22 @@ def write_bigint(self, value: int) -> None:
220220 """Write tagged 8 byte number (c_ulonglong).
221221 """
222222 self .write_number (value , 8 )
223- def write_string (self , value : str , * , encoding = 'ascii' ) -> None :
223+ def write_string (self , value : str , * , encoding : str = 'ascii' , errors : str = 'strict ' ) -> None :
224224 """Write zero-terminated string.
225225 """
226- self .write (value .encode (encoding ))
226+ self .write (value .encode (encoding , errors ))
227227 self .write_byte (0 )
228- def write_pascal_string (self , value : str , * , encoding = 'ascii' ) -> None :
228+ def write_pascal_string (self , value : str , * , encoding : str = 'ascii' , errors : str = 'strict ' ) -> None :
229229 """Write tagged Pascal string (2 byte length followed by data).
230230 """
231- value = value .encode (encoding )
232- size = len (value )
233- self .write_byte (size )
231+ value = value .encode (encoding , errors )
232+ self .write_byte (len (value ))
233+ self .write (value )
234+ def write_sized_string (self , value : str , * , encoding : str = 'ascii' , errors : str = 'strict' ) -> None :
235+ """Write string (2 byte length followed by data).
236+ """
237+ value = value .encode (encoding , errors )
238+ self .write_short (len (value ))
234239 self .write (value )
235240 def read (self , size : int = - 1 ) -> bytes :
236241 """Reads specified number of bytes, or all remaining data.
@@ -248,43 +253,43 @@ def read_number(self, size: int, *, signed=False) -> int:
248253 result = (0 ).from_bytes (self .raw [self .pos : self .pos + size ], self .byteorder .value , signed = signed )
249254 self .pos += size
250255 return result
251- def read_byte (self , * , signed = False ) -> int :
256+ def read_byte (self , * , signed : bool = False ) -> int :
252257 """Read 1 byte number (c_ubyte).
253258 """
254259 return self .read_number (1 , signed = signed )
255- def read_short (self , * , signed = False ) -> int :
260+ def read_short (self , * , signed : bool = False ) -> int :
256261 """Read 2 byte number (c_ushort).
257262 """
258263 return self .read_number (2 , signed = signed )
259- def read_int (self , * , signed = False ) -> int :
264+ def read_int (self , * , signed : bool = False ) -> int :
260265 """Read 4 byte number (c_uint).
261266 """
262267 return self .read_number (4 , signed = signed )
263- def read_bigint (self , * , signed = False ) -> int :
268+ def read_bigint (self , * , signed : bool = False ) -> int :
264269 """Read 8 byte number (c_ulonglong).
265270 """
266271 return self .read_number (8 , signed = signed )
267- def read_sized_int (self , * , signed = False ) -> int :
272+ def read_sized_int (self , * , signed : bool = False ) -> int :
268273 """Read number cluster (2 byte length followed by data).
269274 """
270275 return self .read_number (self .read_short (), signed = signed )
271- def read_string (self , * , encoding = 'ascii' ) -> str :
276+ def read_string (self , * , encoding : str = 'ascii' , errors : str = 'strict ' ) -> str :
272277 """Read null-terminated string.
273278 """
274279 i = self .pos
275280 while i < self .buffer_size and safe_ord (self .raw [i ]) != 0 :
276281 i += 1
277- result = self .read (i - self .pos ).decode (encoding )
282+ result = self .read (i - self .pos ).decode (encoding , errors )
278283 self .pos += 1
279284 return result
280- def read_pascal_string (self , * , encoding = 'ascii' ) -> str :
285+ def read_pascal_string (self , * , encoding : str = 'ascii' , errors : str = 'strict ' ) -> str :
281286 """Read Pascal string (1 byte length followed by string data).
282287 """
283- return self .read (self .read_byte ()).decode (encoding )
284- def read_sized_string (self , * , encoding = 'ascii' ) -> str :
288+ return self .read (self .read_byte ()).decode (encoding , errors )
289+ def read_sized_string (self , * , encoding : str = 'ascii' , errors : str = 'strict ' ) -> str :
285290 """Read string (2 byte length followed by data).
286291 """
287- return self .read (self .read_short ()).decode (encoding )
292+ return self .read (self .read_short ()).decode (encoding , errors )
288293 def read_bytes (self ) -> bytes :
289294 """Read content of binary cluster (2 bytes data length followed by data).
290295 """
0 commit comments