Skip to content

Commit b614b19

Browse files
committed
Update README.md
1 parent 83d8593 commit b614b19

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

README.md

+33-16
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,38 @@ composer require web3p/rlp
1515
# Usage
1616

1717
RLP encode:
18+
1819
```php
1920
use Web3p\RLP\RLP;
2021

2122
$rlp = new RLP;
22-
$encodedBuffer = $rlp->encode(['dog']);
23+
// c483646f67
24+
$encoded = $rlp->encode(['dog']);
2325

24-
// to string, encoding: ascii utf8 hex
25-
$encodedBuffer->toString($encoding);
26+
// 83646f67
27+
$encoded = $rlp->encode('dog');
2628
```
2729

2830
RLP decode:
31+
2932
```php
3033
use Web3p\RLP\RLP;
34+
use Web3p\RLP\Types\Str;
3135

3236
$rlp = new RLP;
33-
$encodedBuffer = $rlp->encode(['dog']);
37+
$encoded = $rlp->encode(['dog']);
3438

3539
// only accept 0x prefixed hex string
36-
$decodedArray = $rlp->decode('0x' . $encodedBuffer->toString('hex'));
40+
$decoded = $rlp->decode('0x' . $encoded);
41+
42+
// show 646f67
43+
echo $decoded[0];
3744

3845
// show dog
39-
echo $decodedArray[0]->toString('utf8');
46+
echo hex2bin($decoded[0]);
47+
48+
// or you can
49+
echo Str::decodeHex($decoded[0]);
4050
```
4151

4252
# API
@@ -45,12 +55,14 @@ echo $decodedArray[0]->toString('utf8');
4555

4656
#### encode
4757

48-
Returns recursive length prefix encoding of given data.
58+
Returns recursive length prefix encoding of given inputs.
4959

5060
`encode(mixed $inputs)`
5161

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

64+
> Note: output is not zero prefixed.
65+
5466
###### Example
5567

5668
* Encode array of string.
@@ -59,9 +71,7 @@ Mixed inputs - array of string, integer or numeric string.
5971
use Web3p\RLP\RLP;
6072

6173
$rlp = new RLP;
62-
$encodedBuffer = $rlp->encode(['web3p', 'ethereum', 'solidity']);
63-
$encodedString = $encodedBuffer->toString('hex');
64-
74+
$encoded = $rlp->encode(['web3p', 'ethereum', 'solidity']);
6575
```
6676

6777
#### decode
@@ -72,26 +82,33 @@ Returns array recursive length prefix decoding of given data.
7282

7383
String input - recursive length prefix encoded string.
7484

85+
> Note: output is not zero prefixed.
86+
7587
###### Example
7688

7789
* Decode recursive length prefix encoded string.
7890

7991
```php
8092
use Web3p\RLP\RLP;
93+
use Web3p\RLP\Types\Str;
8194

8295
$rlp = new RLP;
83-
$encodedBuffer = $rlp->encode(['web3p', 'ethereum', 'solidity']);
84-
$encodedString = $encodedBuffer->toString('hex');
85-
$decodedArray = $rlp->decode('0x' . $encodedString);
96+
$encoded = $rlp->encode(['web3p', 'ethereum', 'solidity']);
97+
$decoded = $rlp->decode('0x' . $encoded);
8698

8799
// echo web3p
88-
echo $decodedArray[0]->toString('utf8');
100+
echo hex2bin($decoded[0]);
89101

90102
// echo ethereum
91-
echo $decodedArray[1]->toString('utf8');
103+
echo hex2bin($decoded[1]);
92104

93105
// echo solidity
94-
echo $decodedArray[2]->toString('utf8');
106+
echo hex2bin($decoded[2]);
107+
108+
// or you can
109+
echo Str::decodeHex($decoded[0]);
110+
echo Str::decodeHex($decoded[1]);
111+
echo Str::decodeHex($decoded[2]);
95112
```
96113

97114
# License

0 commit comments

Comments
 (0)