Mercurial > public > bitcaviar-plus
diff src/helpers.py @ 0:2327b9eda10f
first commit
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Thu, 14 Oct 2021 21:42:10 +0200 |
parents | |
children | 5b16e6df6a59 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/helpers.py Thu Oct 14 21:42:10 2021 +0200 @@ -0,0 +1,18 @@ +def read_bytes(file, number_of_bytes, bytes_order='backward'): + """ + Read bytes from buffer + :param file: <class '_io.BufferedReader'>, required + :param number_of_bytes: int, required + :param bytes_order: string, 'backward' or 'forward', required + :return: string + """ + + # More info about bytes order: https://en.wikipedia.org/wiki/Endianness + + b = file.read(number_of_bytes) + if bytes_order == 'backward': + b = b[::-1] + + b = b.hex().upper() + + return b