PACK和UNPACK的实现细节
1 个回答
- 投票数
-
- 2019-03-01
我已经在
PACK
项目中实现了UNPACK
和tezbridge-crypto
.您可以在此处签出源代码: codec.js#L426
以下是一些测试用例: index.js#L35
简而言之,有几个映射( codec.js#L166 , codec.js#L288 )在Michline值和二进制表示形式之间. 转换只是遍历数据的一种方法,每种数据类型(例如
int
,string
..)都有其特定的编码/解码方法.I have implemented the
PACK
andUNPACK
intezbridge-crypto
project.You can checkout the source code here: codec.js#L426
Here are some test cases: index.js#L35
In short words, there are several mappings(codec.js#L166, codec.js#L288) between the Michline value and the binary representation. The conversion is just a one way walk though the data, and each data type(like
int
,string
..) has its specific encoding/decoding method.-
我在[tezos](https://gitlab.com/tezos/tezos)存储库中搜索源代码,以获取您拥有的op_mapping.我很好奇这些映射在哪里定义的,但是我没有找到它们.浏览tezos源代码使我在`binary_writer.ml`中找到了函数`write_rec`.I was grepping around the source code from the [tezos](https://gitlab.com/tezos/tezos) repository for the op_mapping you have. I am curious where these mappings are defined in there, but I have not found them. Looking through tezos source code has led me to a function `write_rec` in `binary_writer.ml`.
- 0
- 2019-03-04
- MCH
-
这些也是不错的资源:[data_encoding库](http://tezos.gitlab.io/mainnet/tutorials/data_encoding.html)和[Module Tezos_data_encoding.Data_encoding](http://tezos.gitlab.io/mainnet/api/api-inline.html#tezos-data-encoding/Tezos_data_encoding/index.html)These are also good resources: [The data_encoding library](http://tezos.gitlab.io/mainnet/tutorials/data_encoding.html) and [Module Tezos_data_encoding.Data_encoding](http://tezos.gitlab.io/mainnet/api/api-inline.html#tezos-data-encoding/Tezos_data_encoding/index.html)
- 0
- 2019-03-04
- MCH
在字节操作部分中迈克尔逊白色文件,其中提到:
我想知道有关如何实现
PACK
和UNPACK
以及二进制表示形式的更多细节的信息.我查看了源代码,实现中没有太多注释.编辑:
用户catsigma给出的详细信息非常有用,但是我仍然希望能够跟踪序列化在源代码中的工作方式以及对二进制代码映射的操作来自何处.
我在这里找到
interp
函数和Pack
的实现:src/proto_alpha/lib_protocol/src/script_interpreter.ml#L697
pack_data
在这里定义:src/proto_alpha/lib_protocol/src/script_ir_translator.ml#L3162
Data_encoding.Binary.to_bytes_exn
看起来像键函数.src/lib_data_encoding/binary_writer.ml#L338
现在让我们尝试查找
False
的编码.这是重新整理的更多代码 src/lib_data_encoding/binary_writer.ml :现在,我们需要找到
MBytes.set_int8
.我只找到类型签名文件.src/lib_protocol_environment/sigs/v1/mBytes.mli
mBytes
看起来像是一个外部库,但我没有找到名称.另外,我看不到它与tezbridge-crypto中提到的op_mapping
如何匹配.