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 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: ethereum.base_types.Bytes left padded byte string of given size.

def left_pad_zero_bytes(value: Bytes, ​​size: int) -> Bytes:
18
    """
19
    Left pad zeroes to `value` if it's length is less than the given `size`.
20
21
    Parameters
22
    ----------
23
    value :
24
        The byte string that needs to be padded.
25
    size :
26
        The number of bytes that need that need to be padded.
27
28
    Returns
29
    -------
30
    left_padded_value: `ethereum.base_types.Bytes`
31
        left padded byte string of given `size`.
32
    """
33
    return value.rjust(size, b"\x00")

right_pad_zero_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: ethereum.base_types.Bytes right padded byte string of given size.

def right_pad_zero_bytes(value: Bytes, ​​size: int) -> Bytes:
37
    """
38
    Right pad zeroes to `value` if it's length is less than the given `size`.
39
40
    Parameters
41
    ----------
42
    value :
43
        The byte string that needs to be padded.
44
    size :
45
        The number of bytes that need that need to be padded.
46
47
    Returns
48
    -------
49
    right_padded_value: `ethereum.base_types.Bytes`
50
        right padded byte string of given `size`.
51
    """
52
    return value.ljust(size, b"\x00")