ethereum.utils.byte
Utility Functions For Byte Strings ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. contents:: Table of Contents :backlinks: none :local:
Introduction
Byte specific utility functions used in this specification.
1""" 2Utility Functions For Byte Strings 3^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4 5.. contents:: Table of Contents 6 :backlinks: none 7 :local: 8 9Introduction 10------------ 11 12Byte specific utility functions used in this specification. 13""" 14from ethereum.base_types import Bytes 15 16 17def 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") 34 35 36def 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")
def
left_pad_zero_bytes(value: bytes, size: int) -> bytes:
18def left_pad_zero_bytes(value: Bytes, size: int) -> Bytes: 19 """ 20 Left pad zeroes to `value` if it's length is less than the given `size`. 21 22 Parameters 23 ---------- 24 value : 25 The byte string that needs to be padded. 26 size : 27 The number of bytes that need that need to be padded. 28 29 Returns 30 ------- 31 left_padded_value: `ethereum.base_types.Bytes` 32 left padded byte string of given `size`. 33 """ 34 return value.rjust(size, b"\x00")
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
right_pad_zero_bytes(value: bytes, size: int) -> bytes:
37def right_pad_zero_bytes(value: Bytes, size: int) -> Bytes: 38 """ 39 Right pad zeroes to `value` if it's length is less than the given `size`. 40 41 Parameters 42 ---------- 43 value : 44 The byte string that needs to be padded. 45 size : 46 The number of bytes that need that need to be padded. 47 48 Returns 49 ------- 50 right_padded_value: `ethereum.base_types.Bytes` 51 right padded byte string of given `size`. 52 """ 53 return value.ljust(size, b"\x00")
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
.