ethereum.utils.byte

Utility Functions For Byte Strings ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. contents:: Table of Contents :backlinks: none :local:

Introduction

Byte specific utility functions used in this specification.

left_pad_zero_bytes

Left pad zeroes to value if its 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: ethereum.base_types.Bytes left padded byte string of given size.

def left_pad_zero_bytes(value: Bytes, ​​size: Union[int, FixedUnsigned, Uint]) -> Bytes:
23
    """
24
    Left pad zeroes to `value` if its length is less than the given `size`.
25
26
    Parameters
27
    ----------
28
    value :
29
        The byte string that needs to be padded.
30
    size :
31
        The number of bytes that need that need to be padded.
32
33
    Returns
34
    -------
35
    left_padded_value: `ethereum.base_types.Bytes`
36
        left padded byte string of given `size`.
37
    """
38
    return value.rjust(int(size), b"\x00")

right_pad_zero_bytes

Right pad zeroes to value if its 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: ethereum.base_types.Bytes right padded byte string of given size.

def right_pad_zero_bytes(value: Bytes, ​​size: Union[int, FixedUnsigned, Uint]) -> Bytes:
44
    """
45
    Right pad zeroes to `value` if its length is less than the given `size`.
46
47
    Parameters
48
    ----------
49
    value :
50
        The byte string that needs to be padded.
51
    size :
52
        The number of bytes that need that need to be padded.
53
54
    Returns
55
    -------
56
    right_padded_value: `ethereum.base_types.Bytes`
57
        right padded byte string of given `size`.
58
    """
59
    return value.ljust(int(size), b"\x00")