Documentation

RLP
in package

It's a instance for ethereum recursive length encoding.

RLP encode:

use Web3p\RLP\RLP;

$rlp = new RLP;
// c483646f67
$encoded = $rlp->encode(['dog']);

// 83646f67
$encoded = $rlp->encode('dog');

RLP decode:

use Web3p\RLP\RLP;
use Web3p\RLP\Types\Str;

$rlp = new RLP;
$encoded = $rlp->encode(['dog']);

// only accept 0x prefixed hex string
$decoded = $rlp->decode('0x' . $encoded);

// show 646f67
echo $decoded[0];

// show dog
echo hex2bin($decoded[0]);

// or you can
echo Str::decodeHex($decoded[0]);
Tags
author

Peter Lai alk03073135@gmail.com

link
https://www.web3p.xyz
filesource

https://github.com/web3p/rlp

Table of Contents

decode()  : array<string|int, mixed>
Return RLP decoded of the given hex encoded data.
encode()  : string
Return RLP encoded of the given inputs.
decodeData()  : array<string|int, mixed>
Main function of RLP decode.
encodeInput()  : string
Main encode function to transform data to hex encoded string.
encodeLength()  : string
Return RLP encoded the length of data.
intToHex()  : string
Return hex of the given integer.
padToEven()  : string
Pad hex encoded data to even length (add 0).

Methods

decode()

Return RLP decoded of the given hex encoded data.

public decode(string $input) : array<string|int, mixed>
Parameters
$input : string

hex encoded data

Return values
array<string|int, mixed>

decoded data

encode()

Return RLP encoded of the given inputs.

public encode(mixed $inputs) : string
Parameters
$inputs : mixed

mixed type of data you want to RLP encode

Return values
string

RLP encoded hex string of inputs

decodeData()

Main function of RLP decode.

protected decodeData(string $input) : array<string|int, mixed>
Parameters
$input : string

hex encoded data

Return values
array<string|int, mixed>

decoded data

encodeInput()

Main encode function to transform data to hex encoded string.

protected encodeInput(mixed $input) : string
Parameters
$input : mixed

data

Return values
string

hex encoded string

encodeLength()

Return RLP encoded the length of data.

protected encodeLength(int $length, int $offset) : string
Parameters
$length : int

length of data

$offset : int

offset of data

Return values
string

hex encoded of the length

intToHex()

Return hex of the given integer.

protected intToHex(int $input) : string
Parameters
$input : int

integer

Return values
string

hex encoded of the input

padToEven()

Pad hex encoded data to even length (add 0).

protected padToEven(string $input) : string
Parameters
$input : string

hex encoded string

Return values
string

hex encoded string

Search results