11import struct
2+ from typing import Any
3+
24from ..codecs import CodecBase
35from ..exceptions import BinaryParseError
46
57SIZE = 64
68IS_PATH = False
79
10+
811class Codec (CodecBase ):
912 SIZE = SIZE
1013 IS_PATH = IS_PATH
11-
12- def to_bytes (self , proto , string : str ) -> bytes :
13- # Parse as unsigned 64-bit int
14- value = int (string , 10 )
15- if value < 0 or value > 0xFFFFFFFFFFFFFFFF :
16- raise ValueError ("Value out of range for uint64" )
17- return struct .pack (">Q" , value ) # big-endian uint64
1814
19- def to_string (self , proto , buf : bytes ) -> str :
15+ def to_bytes (self , proto : Any , string : str ) -> bytes :
16+ # Parse as unsigned 64-bit int
17+ value = int (string , 10 )
18+ if value < 0 or value > 0xFFFFFFFFFFFFFFFF :
19+ raise ValueError ("Value out of range for uint64" )
20+ return struct .pack (">Q" , value ) # big-endian uint64
21+
22+ def to_string (self , proto : Any , buf : bytes ) -> str :
2023 if len (buf ) != 8 :
2124 raise BinaryParseError ("Expected 8 bytes for uint64" , buf , "memory" )
2225 value = struct .unpack (">Q" , buf )[0 ]
2326 return str (value )
24-
27+
2528 def memory_validate (self , b : bytes ) -> None :
2629 if len (b ) != 8 :
2730 raise ValueError (f"Invalid length: must be exactly 8 bytes, got { len (b )} " )
28-
0 commit comments