:mod:`ethereum.rlp` =================== .. py:module:: ethereum.rlp Recursive Length Prefix (RLP) Encoding ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. contents:: Table of Contents :backlinks: none :local: Introduction ------------ Defines the serialization and deserialization format used throughout Ethereum. Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: :nosignatures: ethereum.rlp.encode ethereum.rlp.encode_bytes ethereum.rlp.encode_sequence ethereum.rlp.get_joined_encodings ethereum.rlp.decode ethereum.rlp.decode_to_bytes ethereum.rlp.decode_to_sequence ethereum.rlp.decode_joined_encodings ethereum.rlp.decode_item_length ethereum.rlp.encode_block ethereum.rlp.encode_header ethereum.rlp.encode_account ethereum.rlp.encode_transaction ethereum.rlp.encode_receipt ethereum.rlp.encode_log Attributes ~~~~~~~~~~ .. autoapisummary:: ethereum.rlp.RLP Module Details --------------- RLP ~~~ .. data:: RLP encode ~~~~~~ .. function:: encode(raw_data: RLP) -> ethereum.base_types.Bytes :noindexentry: Encodes `raw_data` into a sequence of bytes using RLP. :param raw_data: A `Bytes`, `Uint`, `Uint256` or sequence of `RLP` encodable objects. :returns: **encoded** -- The RLP encoded bytes representing `raw_data`. :rtype: `eth1spec.base_types.Bytes` .. undocinclude:: /../src/ethereum/rlp.py :language: python :lines: 42-79 encode_bytes ~~~~~~~~~~~~ .. function:: encode_bytes(raw_bytes: ethereum.base_types.Bytes) -> ethereum.base_types.Bytes :noindexentry: Encodes `raw_bytes`, a sequence of bytes, using RLP. :param raw_bytes: Bytes to encode with RLP. :returns: **encoded** -- The RLP encoded bytes representing `raw_bytes`. :rtype: `eth1spec.base_types.Bytes` .. undocinclude:: /../src/ethereum/rlp.py :language: python :lines: 83-109 encode_sequence ~~~~~~~~~~~~~~~ .. function:: encode_sequence(raw_sequence: Sequence[RLP]) -> ethereum.base_types.Bytes :noindexentry: Encodes a list of RLP encodable objects (`raw_sequence`) using RLP. :param raw_sequence: Sequence of RLP encodable objects. :returns: **encoded** -- The RLP encoded bytes representing `raw_sequence`. :rtype: `eth1spec.base_types.Bytes` .. undocinclude:: /../src/ethereum/rlp.py :language: python :lines: 113-137 get_joined_encodings ~~~~~~~~~~~~~~~~~~~~ .. function:: get_joined_encodings(raw_sequence: Sequence[RLP]) -> ethereum.base_types.Bytes :noindexentry: Obtain concatenation of rlp encoding for each item in the sequence raw_sequence. :param raw_sequence: Sequence to encode with RLP. :returns: **joined_encodings** -- The concatenated RLP encoded bytes for each item in sequence raw_sequence. :rtype: `eth1spec.base_types.Bytes` .. undocinclude:: /../src/ethereum/rlp.py :language: python :lines: 141-161 decode ~~~~~~ .. function:: decode(encoded_data: ethereum.base_types.Bytes) -> RLP :noindexentry: Decodes an integer, byte sequence, or list of RLP encodable objects from the byte sequence `encoded_data`, using RLP. :param encoded_data: A sequence of bytes, in RLP form. :returns: **decoded_data** -- Object decoded from `encoded_data`. :rtype: `RLP` .. undocinclude:: /../src/ethereum/rlp.py :language: python :lines: 169-195 decode_to_bytes ~~~~~~~~~~~~~~~ .. function:: decode_to_bytes(encoded_bytes: ethereum.base_types.Bytes) -> ethereum.base_types.Bytes :noindexentry: Decodes a rlp encoded byte stream assuming that the decoded data should be of type `bytes`. :param encoded_bytes: RLP encoded byte stream. :returns: **decoded** -- RLP decoded Bytes data :rtype: `eth1spec.base_types.Bytes` .. undocinclude:: /../src/ethereum/rlp.py :language: python :lines: 198-235 decode_to_sequence ~~~~~~~~~~~~~~~~~~ .. function:: decode_to_sequence(encoded_sequence: ethereum.base_types.Bytes) -> List[RLP] :noindexentry: Decodes a rlp encoded byte stream assuming that the decoded data should be of type `Sequence` of objects. :param encoded_sequence: An RLP encoded Sequence. :returns: **decoded** -- Sequence of objects decoded from `encoded_sequence`. :rtype: `Sequence[RLP]` .. undocinclude:: /../src/ethereum/rlp.py :language: python :lines: 238-275 decode_joined_encodings ~~~~~~~~~~~~~~~~~~~~~~~ .. function:: decode_joined_encodings(joined_encodings: ethereum.base_types.Bytes) -> List[RLP] :noindexentry: Decodes `joined_encodings`, which is a concatenation of RLP encoded objects. :param joined_encodings: concatenation of RLP encoded objects :returns: **decoded** -- A list of objects decoded from `joined_encodings`. :rtype: `List[RLP]` .. undocinclude:: /../src/ethereum/rlp.py :language: python :lines: 278-307 decode_item_length ~~~~~~~~~~~~~~~~~~ .. function:: decode_item_length(encoded_data: ethereum.base_types.Bytes) -> int :noindexentry: Find the length of the rlp encoding for the first object in the encoded sequence. Here `encoded_data` refers to concatenation of rlp encoding for each item in a sequence. NOTE - This is a helper function not described in the spec. It was introduced as the spec doesn't discuss about decoding the RLP encoded data. :param encoded_data: RLP encoded data for a sequence of objects. :returns: **rlp_length** :rtype: `int` .. undocinclude:: /../src/ethereum/rlp.py :language: python :lines: 310-377 encode_block ~~~~~~~~~~~~ .. function:: encode_block(raw_block_data: ethereum.eth_types.Block) -> ethereum.base_types.Bytes :noindexentry: Encode `Block` dataclass .. undocinclude:: /../src/ethereum/rlp.py :language: python :lines: 386-394 encode_header ~~~~~~~~~~~~~ .. function:: encode_header(raw_header_data: ethereum.eth_types.Header) -> ethereum.base_types.Bytes :noindexentry: Encode `Header` dataclass .. undocinclude:: /../src/ethereum/rlp.py :language: python :lines: 399-419 encode_account ~~~~~~~~~~~~~~ .. function:: encode_account(raw_account_data: ethereum.eth_types.Account) -> ethereum.base_types.Bytes :noindexentry: Encode `Account` dataclass .. undocinclude:: /../src/ethereum/rlp.py :language: python :lines: 424-439 encode_transaction ~~~~~~~~~~~~~~~~~~ .. function:: encode_transaction(raw_tx_data: ethereum.eth_types.Transaction) -> ethereum.base_types.Bytes :noindexentry: Encode `Transaction` dataclass .. undocinclude:: /../src/ethereum/rlp.py :language: python :lines: 444-458 encode_receipt ~~~~~~~~~~~~~~ .. function:: encode_receipt(raw_receipt_data: ethereum.eth_types.Receipt) -> ethereum.base_types.Bytes :noindexentry: Encode `Receipt` dataclass .. undocinclude:: /../src/ethereum/rlp.py :language: python :lines: 463-472 encode_log ~~~~~~~~~~ .. function:: encode_log(raw_log_data: ethereum.eth_types.Log) -> ethereum.base_types.Bytes :noindexentry: Encode `Log` dataclass .. undocinclude:: /../src/ethereum/rlp.py :language: python :lines: 477-485