Add int to bytes conversion method

pull/8/head
Nicolas Jouanin 2015-05-31 07:59:42 +02:00
rodzic 4dab5674e1
commit 05dc5bd97e
1 zmienionych plików z 11 dodań i 1 usunięć

Wyświetl plik

@ -15,12 +15,22 @@ def bytes_to_hex_str(data):
def bytes_to_int(data):
"""
converts a seauence of bytes to an integer using big endian byte ordering
convert a sequence of bytes to an integer using big endian byte ordering
:param data: byte sequence
:return: integer value
"""
return int.from_bytes(data, byteorder='big')
def int_to_bytes(int_value:int, length) -> bytes:
"""
convert an integer to a sequence of bytes using big endian byte ordering
:param int_value: integer value to convert
:param length: byte sequence length
:return: byte sequence
"""
int_value.to_bytes(length, byteorder='big')
@asyncio.coroutine
def read_or_raise(reader, n=-1):
"""