blockchainethdev/rlp
最新稳定版本:0.3.4
Composer 安装命令:
composer require blockchainethdev/rlp
包简介
Recursive Length Prefix Encoding in PHP.
README 文档
README
Recursive Length Prefix Encoding in PHP.
Install
Set minimum stability to dev
composer require blockchainethdev/rlp
Usage
RLP encode:
use Blockchainethdev\RLP\RLP; $rlp = new RLP; // c483646f67 $encoded = $rlp->encode(['dog']); // 83646f67 $encoded = $rlp->encode('dog');
RLP decode:
use Blockchainethdev\RLP\RLP; use Blockchainethdev\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
Blockchainethdev\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.
use Blockchainethdev\RLP\RLP; $rlp = new RLP; $encoded = $rlp->encode(['blockchainethdev', '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.
use Blockchainethdev\RLP\RLP; use Blockchainethdev\RLP\Types\Str; $rlp = new RLP; $encoded = $rlp->encode(['blockchainethdev', 'ethereum', 'solidity']); $decoded = $rlp->decode('0x' . $encoded); // echo blockchainethdev 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
统计信息
- 总下载量: 268
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-29