5252from typing_extensions import TypeAlias as _TypeAlias
5353
5454from librt .internal import (
55- Buffer as Buffer ,
55+ ReadBuffer as ReadBuffer ,
56+ WriteBuffer as WriteBuffer ,
5657 read_bool as read_bool ,
5758 read_bytes as read_bytes_bare ,
5859 read_float as read_float_bare ,
@@ -165,7 +166,7 @@ def deserialize(cls, meta: dict[str, Any], data_file: str) -> CacheMeta | None:
165166 except (KeyError , ValueError ):
166167 return None
167168
168- def write (self , data : Buffer ) -> None :
169+ def write (self , data : WriteBuffer ) -> None :
169170 write_str (data , self .id )
170171 write_str (data , self .path )
171172 write_int (data , self .mtime )
@@ -187,7 +188,7 @@ def write(self, data: Buffer) -> None:
187188 write_json_value (data , self .plugin_data )
188189
189190 @classmethod
190- def read (cls , data : Buffer , data_file : str ) -> CacheMeta | None :
191+ def read (cls , data : ReadBuffer , data_file : str ) -> CacheMeta | None :
191192 try :
192193 return CacheMeta (
193194 id = read_str (data ),
@@ -240,7 +241,7 @@ def read(cls, data: Buffer, data_file: str) -> CacheMeta | None:
240241END_TAG : Final [Tag ] = 255
241242
242243
243- def read_literal (data : Buffer , tag : Tag ) -> int | str | bool | float :
244+ def read_literal (data : ReadBuffer , tag : Tag ) -> int | str | bool | float :
244245 if tag == LITERAL_INT :
245246 return read_int_bare (data )
246247 elif tag == LITERAL_STR :
@@ -256,7 +257,7 @@ def read_literal(data: Buffer, tag: Tag) -> int | str | bool | float:
256257
257258# There is an intentional asymmetry between read and write for literals because
258259# None and/or complex values are only allowed in some contexts but not in others.
259- def write_literal (data : Buffer , value : int | str | bool | float | complex | None ) -> None :
260+ def write_literal (data : WriteBuffer , value : int | str | bool | float | complex | None ) -> None :
260261 if isinstance (value , bool ):
261262 write_bool (data , value )
262263 elif isinstance (value , int ):
@@ -276,114 +277,114 @@ def write_literal(data: Buffer, value: int | str | bool | float | complex | None
276277 write_tag (data , LITERAL_NONE )
277278
278279
279- def read_int (data : Buffer ) -> int :
280+ def read_int (data : ReadBuffer ) -> int :
280281 assert read_tag (data ) == LITERAL_INT
281282 return read_int_bare (data )
282283
283284
284- def write_int (data : Buffer , value : int ) -> None :
285+ def write_int (data : WriteBuffer , value : int ) -> None :
285286 write_tag (data , LITERAL_INT )
286287 write_int_bare (data , value )
287288
288289
289- def read_str (data : Buffer ) -> str :
290+ def read_str (data : ReadBuffer ) -> str :
290291 assert read_tag (data ) == LITERAL_STR
291292 return read_str_bare (data )
292293
293294
294- def write_str (data : Buffer , value : str ) -> None :
295+ def write_str (data : WriteBuffer , value : str ) -> None :
295296 write_tag (data , LITERAL_STR )
296297 write_str_bare (data , value )
297298
298299
299- def read_bytes (data : Buffer ) -> bytes :
300+ def read_bytes (data : ReadBuffer ) -> bytes :
300301 assert read_tag (data ) == LITERAL_BYTES
301302 return read_bytes_bare (data )
302303
303304
304- def write_bytes (data : Buffer , value : bytes ) -> None :
305+ def write_bytes (data : WriteBuffer , value : bytes ) -> None :
305306 write_tag (data , LITERAL_BYTES )
306307 write_bytes_bare (data , value )
307308
308309
309- def read_int_opt (data : Buffer ) -> int | None :
310+ def read_int_opt (data : ReadBuffer ) -> int | None :
310311 tag = read_tag (data )
311312 if tag == LITERAL_NONE :
312313 return None
313314 assert tag == LITERAL_INT
314315 return read_int_bare (data )
315316
316317
317- def write_int_opt (data : Buffer , value : int | None ) -> None :
318+ def write_int_opt (data : WriteBuffer , value : int | None ) -> None :
318319 if value is not None :
319320 write_tag (data , LITERAL_INT )
320321 write_int_bare (data , value )
321322 else :
322323 write_tag (data , LITERAL_NONE )
323324
324325
325- def read_str_opt (data : Buffer ) -> str | None :
326+ def read_str_opt (data : ReadBuffer ) -> str | None :
326327 tag = read_tag (data )
327328 if tag == LITERAL_NONE :
328329 return None
329330 assert tag == LITERAL_STR
330331 return read_str_bare (data )
331332
332333
333- def write_str_opt (data : Buffer , value : str | None ) -> None :
334+ def write_str_opt (data : WriteBuffer , value : str | None ) -> None :
334335 if value is not None :
335336 write_tag (data , LITERAL_STR )
336337 write_str_bare (data , value )
337338 else :
338339 write_tag (data , LITERAL_NONE )
339340
340341
341- def read_int_list (data : Buffer ) -> list [int ]:
342+ def read_int_list (data : ReadBuffer ) -> list [int ]:
342343 assert read_tag (data ) == LIST_INT
343344 size = read_int_bare (data )
344345 return [read_int_bare (data ) for _ in range (size )]
345346
346347
347- def write_int_list (data : Buffer , value : list [int ]) -> None :
348+ def write_int_list (data : WriteBuffer , value : list [int ]) -> None :
348349 write_tag (data , LIST_INT )
349350 write_int_bare (data , len (value ))
350351 for item in value :
351352 write_int_bare (data , item )
352353
353354
354- def read_str_list (data : Buffer ) -> list [str ]:
355+ def read_str_list (data : ReadBuffer ) -> list [str ]:
355356 assert read_tag (data ) == LIST_STR
356357 size = read_int_bare (data )
357358 return [read_str_bare (data ) for _ in range (size )]
358359
359360
360- def write_str_list (data : Buffer , value : Sequence [str ]) -> None :
361+ def write_str_list (data : WriteBuffer , value : Sequence [str ]) -> None :
361362 write_tag (data , LIST_STR )
362363 write_int_bare (data , len (value ))
363364 for item in value :
364365 write_str_bare (data , item )
365366
366367
367- def read_bytes_list (data : Buffer ) -> list [bytes ]:
368+ def read_bytes_list (data : ReadBuffer ) -> list [bytes ]:
368369 assert read_tag (data ) == LIST_BYTES
369370 size = read_int_bare (data )
370371 return [read_bytes_bare (data ) for _ in range (size )]
371372
372373
373- def write_bytes_list (data : Buffer , value : Sequence [bytes ]) -> None :
374+ def write_bytes_list (data : WriteBuffer , value : Sequence [bytes ]) -> None :
374375 write_tag (data , LIST_BYTES )
375376 write_int_bare (data , len (value ))
376377 for item in value :
377378 write_bytes_bare (data , item )
378379
379380
380- def read_str_opt_list (data : Buffer ) -> list [str | None ]:
381+ def read_str_opt_list (data : ReadBuffer ) -> list [str | None ]:
381382 assert read_tag (data ) == LIST_GEN
382383 size = read_int_bare (data )
383384 return [read_str_opt (data ) for _ in range (size )]
384385
385386
386- def write_str_opt_list (data : Buffer , value : list [str | None ]) -> None :
387+ def write_str_opt_list (data : WriteBuffer , value : list [str | None ]) -> None :
387388 write_tag (data , LIST_GEN )
388389 write_int_bare (data , len (value ))
389390 for item in value :
@@ -393,7 +394,7 @@ def write_str_opt_list(data: Buffer, value: list[str | None]) -> None:
393394JsonValue : _TypeAlias = Union [None , int , str , bool , list ["JsonValue" ], dict [str , "JsonValue" ]]
394395
395396
396- def read_json_value (data : Buffer ) -> JsonValue :
397+ def read_json_value (data : ReadBuffer ) -> JsonValue :
397398 tag = read_tag (data )
398399 if tag == LITERAL_NONE :
399400 return None
@@ -416,7 +417,7 @@ def read_json_value(data: Buffer) -> JsonValue:
416417
417418# Currently tuples are used by mypyc plugin. They will be normalized to
418419# JSON lists after a roundtrip.
419- def write_json_value (data : Buffer , value : JsonValue | tuple [JsonValue , ...]) -> None :
420+ def write_json_value (data : WriteBuffer , value : JsonValue | tuple [JsonValue , ...]) -> None :
420421 if value is None :
421422 write_tag (data , LITERAL_NONE )
422423 elif isinstance (value , bool ):
@@ -444,13 +445,13 @@ def write_json_value(data: Buffer, value: JsonValue | tuple[JsonValue, ...]) ->
444445
445446# These are functions for JSON *dictionaries* specifically. Unfortunately, we
446447# must use imprecise types here, because the callers use imprecise types.
447- def read_json (data : Buffer ) -> dict [str , Any ]:
448+ def read_json (data : ReadBuffer ) -> dict [str , Any ]:
448449 assert read_tag (data ) == DICT_STR_GEN
449450 size = read_int_bare (data )
450451 return {read_str_bare (data ): read_json_value (data ) for _ in range (size )}
451452
452453
453- def write_json (data : Buffer , value : dict [str , Any ]) -> None :
454+ def write_json (data : WriteBuffer , value : dict [str , Any ]) -> None :
454455 write_tag (data , DICT_STR_GEN )
455456 write_int_bare (data , len (value ))
456457 for key in sorted (value ):
0 commit comments