Skip to main content

decode_bytes

Function decode_bytes 

Source
pub fn decode_bytes(data: &[u8]) -> RlpResult<Vec<u8>>
Expand description

Decode an RLP-encoded byte string.

This function decodes an RLP string (not a list) into raw bytes. Uses Header::decode_bytes from alloy-rlp internally.

§Arguments

  • data - RLP-encoded string data

§Returns

  • Ok(Vec<u8>) - The decoded bytes
  • Err(ParseError) - If decoding fails or data is a list

§Errors

Returns ParseError::InvalidRlp if:

  • The data is not valid RLP encoding
  • The data encodes a list instead of a string
  • The data is truncated

§Example

use txgate_chain::rlp::decode_bytes;

// Single byte (< 0x80) is itself
let data = [0x42];
assert_eq!(decode_bytes(&data).unwrap(), vec![0x42]);

// Empty string (0x80)
let empty = [0x80];
assert_eq!(decode_bytes(&empty).unwrap(), Vec::<u8>::new());

// Short string (0x80 + len, then bytes)
let short = [0x83, 0x61, 0x62, 0x63]; // "abc"
assert_eq!(decode_bytes(&short).unwrap(), vec![0x61, 0x62, 0x63]);