Skip to content
/ rlp Public
forked from web3p/rlp

Recursive Length Prefix Encoding in PHP.

License

Notifications You must be signed in to change notification settings

sc0Vu/rlp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rlp

Recursive Length Prefix Encoding in PHP.

Build Status codecov Licensed under the MIT License

Install

Set minimum stability to dev

composer require web3p/rlp

Usage

RLP encode:

use Web3p\RLP\RLP;

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

// to string, encoding: ascii utf8 hex
$encodedBuffer->toString($encoding);

RLP decode:

use Web3p\RLP\RLP;

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

// only accept 0x prefixed hex string
$decodedArray = $rlp->decode('0x' . $encodedBuffer->toString('hex'));

// show dog
echo $decodedArray[0]->toString('utf8');

API

Web3p\RLP\RLP

encode

Returns recursive length prefix encoding of given data.

encode(mixed $inputs)

Mixed inputs - array of string, integer or numeric string.

Example
  • Encode array of string.
use Web3p\RLP\RLP;

$rlp = new RLP;
$encodedBuffer = $rlp->encode(['web3p', 'ethereum', 'solidity']);
$encodedString = $encodedBuffer->toString('hex');

decode

Returns array recursive length prefix decoding of given data.

decode(string $input)

String input - recursive length prefix encoded string.

Example
  • Decode recursive length prefix encoded string.
use Web3p\RLP\RLP;

$rlp = new RLP;
$encodedBuffer = $rlp->encode(['web3p', 'ethereum', 'solidity']);
$encodedString = $encodedBuffer->toString('hex');
$decodedArray = $rlp->decode('0x' . $encodedString);

// echo web3p
echo $decodedArray[0]->toString('utf8');

// echo ethereum
echo $decodedArray[1]->toString('utf8');

// echo solidity
echo $decodedArray[2]->toString('utf8');

Contribution

Thank you for considering to help out with the source code!

Pull requests and issues are always welcome.

License

MIT

About

Recursive Length Prefix Encoding in PHP.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%