https://github.com/web3p/rlp
Recursive Length Prefix Encoding in PHP.
https://github.com/web3p/rlp
ethreum hacktoberfest rlp transaction
Last synced: 10 months ago
JSON representation
Recursive Length Prefix Encoding in PHP.
- Host: GitHub
- URL: https://github.com/web3p/rlp
- Owner: web3p
- License: mit
- Created: 2018-01-31T01:53:54.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-02-08T20:14:15.000Z (over 3 years ago)
- Last Synced: 2024-09-19T03:19:57.636Z (almost 2 years ago)
- Topics: ethreum, hacktoberfest, rlp, transaction
- Language: PHP
- Homepage: https://www.web3p.xyz/rlp.html
- Size: 90.8 KB
- Stars: 28
- Watchers: 4
- Forks: 23
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rlp
[](https://github.com/web3p/rlp/actions/workflows/php.yml)
[](https://codecov.io/gh/web3p/rlp)
[](https://github.com/web3p/rlp/blob/master/LICENSE)
Recursive Length Prefix Encoding in PHP.
# Install
Set minimum stability to dev
```
composer require web3p/rlp
```
# Usage
RLP encode:
```php
use Web3p\RLP\RLP;
$rlp = new RLP;
// c483646f67
$encoded = $rlp->encode(['dog']);
// 83646f67
$encoded = $rlp->encode('dog');
```
RLP decode:
```php
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]);
```
# API
### Web3p\RLP\RLP
#### encode
Returns recursive length prefix encoding of given inputs.
`encode(mixed $inputs)`
Mixed inputs - array of string, integer or numeric string.
> Note: output is not zero prefixed.
###### Example
* Encode array of string.
```php
use Web3p\RLP\RLP;
$rlp = new RLP;
$encoded = $rlp->encode(['web3p', 'ethereum', 'solidity']);
```
#### decode
Returns array recursive length prefix decoding of given data.
`decode(string $input)`
String input - recursive length prefix encoded string.
> Note: output is not zero prefixed.
###### Example
* Decode recursive length prefix encoded string.
```php
use Web3p\RLP\RLP;
use Web3p\RLP\Types\Str;
$rlp = new RLP;
$encoded = $rlp->encode(['web3p', 'ethereum', 'solidity']);
$decoded = $rlp->decode('0x' . $encoded);
// echo web3p
echo hex2bin($decoded[0]);
// echo ethereum
echo hex2bin($decoded[1]);
// echo solidity
echo hex2bin($decoded[2]);
// or you can
echo Str::decodeHex($decoded[0]);
echo Str::decodeHex($decoded[1]);
echo Str::decodeHex($decoded[2]);
```
# License
MIT