SECRlpEncode
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
new SECRlpEncode(config)
new SECRlpEncode(config) Constructs a rlp encode class.
Param | Type | Description |
---|---|---|
config | TBD |
TBD, will be implemented in the future |
Example
const RLP = require('encode.js')
const rlp = new RLP()
Buffer
SECRlpEncode.encode(input, buffer, offset) ⇒ Returns input in RLP encoded format
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 |
Array
SECRlpEncode.decode(input, start, end) ⇒ RLP decode for input data
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 |
Number
SECRlpEncode.getLength(input) ⇒ Returns input's length according to the first several indication bytes
Param | Type | Description |
---|---|---|
input | {Buffer, String, Integer, Array} |
Input should be in RLP encoded data, or the returned length is wrong |
中文简介:
本库函数用于SEC区块链的RLP编码 RLP编码用于存储和传输数据,处理数据则用.json格式文件 json文件由RLP编码过以后,由于json文件的键值被去掉了,仅保留内容,因此剩下了大量的空间
主要的函数:
-
RLP编码: encode(input, buffer, offset) => Buffer 输入"input"可以是{Buffer,String,Integer,Array},RLP编码仅对两种数据结构进行处理:列表及字符串 Nodejs中Array即为列表,其他类型{Buffer,String,Integer}作为字符串处理 该函数的输出结果为RLP编码后的input,类型为Buffer
-
RLP解码:decode(input, start, end) => Array 输入"input"可以是{Buffer,String,Integer,Array},无论哪种类型,都会被先转换为Buffer类型再进行处理 作用与encode相反,将RLP格式的数据进行解码, 输出为Array类型
-
获取长度函数: getLength(input) => Number input为经过RLP编码后的数据 函数根据前几个字节的值获取整个input数据的长度