Skip to content

vincentlg/rlp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 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 = $enccodedBuffer->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 = $enccodedBuffer->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');

License

MIT

About

Recursive Length Prefix Encoding in PHP.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • PHP 100.0%