secjs blockchain rlp lib
npm install @sec-block/secjs-rlp
*
This package is used for SEC blockchain rlp encoding.
* SECRlpEncode
* new SECRlpEncode(config)
* .encode(input, buffer, offset) ⇒ Buffer
* .decode(input, start, end) ⇒ Array
* .getLength(input) ⇒ Number
| Param | Type | Description |
| --- | --- | --- |
| config | TBD | TBD, will be implemented in the future |
Example
``js
const RLP = require('encode.js')
const rlp = new RLP()
``
| Param | Type | Description |
| --- | --- | --- |
| input | {Buffer, String, Integer, Array} | Input data for RLP encode |
| buffer | {Buffer} | Input buffer which is in RLP encoded format |
| offset | {Buffer} | Buffer offset position |
| Param | Type | Description |
| --- | --- | --- |
| input | {Buffer, String, Integer, Array} | Input should be in RLP encoded structure |
| start | {Integer} | "input" data array starting index |
| end | {Integer} | "input" data array ending index |
| Param | Type | Description |
| --- | --- | --- |
| input | {Buffer, String, Integer, Array} | Input should be in RLP encoded data, or the returned length is wrong |
*
主要的函数:
1. RLP编码: encode(input, buffer, offset) => Buffer
输入"input"可以是{Buffer,String,Integer,Array},RLP编码仅对两种数据结构进行处理:列表及字符串
Nodejs中Array即为列表,其他类型{Buffer,String,Integer}作为字符串处理
该函数的输出结果为RLP编码后的input,类型为Buffer
2. RLP解码:decode(input, start, end) => Array
输入"input"可以是{Buffer,String,Integer,Array},无论哪种类型,都会被先转换为Buffer类型再进行处理
作用与encode相反,将RLP格式的数据进行解码, 输出为Array类型
3. 获取长度函数: getLength(input) => Number
input为经过RLP编码后的数据
函数根据前几个字节的值获取整个input数据的长度