gleeth/encoding/rlp

Types

Errors that can occur during RLP decoding

pub type RlpError {
  InvalidPrefix(Int)
  UnexpectedEnd
  ExtraData
  InvalidLength
}

Constructors

  • InvalidPrefix(Int)
  • UnexpectedEnd
  • ExtraData
  • InvalidLength

Represents an RLP-encodable item. RLP encodes two types: raw byte strings and lists of RLP items.

pub type RlpItem {
  RlpBytes(BitArray)
  RlpList(List(RlpItem))
}

Constructors

  • RlpBytes(BitArray)
  • RlpList(List(RlpItem))

Values

pub fn decode(data: BitArray) -> Result(RlpItem, RlpError)

Decode bytes into an RLP item

pub fn encode(item: RlpItem) -> BitArray

Encode an RLP item to bytes

pub fn encode_hex_field(hex_string: String) -> RlpItem

Convert a “0x…” hex string to an RLP item with minimal encoding. Strips the 0x prefix, decodes hex to bytes, and removes leading zero bytes.

pub fn encode_int(value: Int) -> RlpItem

Convert an integer to an RLP item. Uses big-endian minimal encoding: 0 becomes empty bytes.

pub fn encode_string(value: String) -> RlpItem

Convert a UTF-8 string to an RLP item

Search Document