Utility Functions For Byte Strings
Table of Contents
Introduction
Byte specific utility functions used in this specification.
Module Contents
Functions
Left pad zeroes to value if it’s length is less than the given size. |
|
Right pad zeroes to value if it’s length is less than the given size. |
Module Details
left_pad_zero_bytes
- left_pad_zero_bytes(value: ethereum.base_types.Bytes, size: int) → ethereum.base_types.Bytes
Left pad zeroes to value if it’s length is less than the given size.
- Parameters
value – The byte string that needs to be padded.
size – The number of bytes that need that need to be padded.
- Returns
left_padded_value – left padded byte string of given size.
- Return type
ethereum.base_types.Bytes
def left_pad_zero_bytes(value: Bytes, size: int) -> Bytes:
return value.rjust(size, b"\x00")
right_pad_zero_bytes
- right_pad_zero_bytes(value: ethereum.base_types.Bytes, size: int) → ethereum.base_types.Bytes
Right pad zeroes to value if it’s length is less than the given size.
- Parameters
value – The byte string that needs to be padded.
size – The number of bytes that need that need to be padded.
- Returns
right_padded_value – right padded byte string of given size.
- Return type
ethereum.base_types.Bytes
def right_pad_zero_bytes(value: Bytes, size: int) -> Bytes:
return value.ljust(size, b"\x00")