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 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 | FixedUnsigned | Uint) -> Bytes:
21 | """ |
---|---|
22 | Left pad zeroes to `value` if its length is less than the given `size`. |
23 |
|
24 | Parameters |
25 | ---------- |
26 | value : |
27 | The byte string that needs to be padded. |
28 | size : |
29 | The number of bytes that need to be padded. |
30 |
|
31 | Returns |
32 | ------- |
33 | left_padded_value: `ethereum.base_types.Bytes` |
34 | left padded byte string of given `size`. |
35 |
|
36 | """ |
37 | 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 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 | FixedUnsigned | Uint) -> Bytes:
43 | """ |
---|---|
44 | Right pad zeroes to `value` if its length is less than the given `size`. |
45 |
|
46 | Parameters |
47 | ---------- |
48 | value : |
49 | The byte string that needs to be padded. |
50 | size : |
51 | The number of bytes that need to be padded. |
52 |
|
53 | Returns |
54 | ------- |
55 | right_padded_value: `ethereum.base_types.Bytes` |
56 | right padded byte string of given `size`. |
57 |
|
58 | """ |
59 | return value.ljust(int(size), b"\x00") |