We use optimized encoding of constant values to save space in serialization.
We use optimized encoding of constant values to save space in serialization. Since Box registers are stored as Constant nodes we save 1 byte for each register. This is due to convention that Value.opCode falling in [1..LastDataType] region is a constant. Thus, we can just decode an instance of SType and then decode data using DataSerializer.
Decoding of constants depends on the first byte and in general is a recursive procedure consuming some number of bytes from Reader.
Decoding of types depends on the first byte and in general is a recursive procedure consuming some number of bytes from Reader.
Decoding of types depends on the first byte and in general is a recursive procedure consuming some number of bytes from Reader. All data types are recognized by the first byte falling in the region [FirstDataType .. LastDataType]
SFunc types occupy remaining space of byte values [FirstFuncType ..
SFunc types occupy remaining space of byte values [FirstFuncType .. 255]
The last constant code is equal to FirstFuncType which represent generic function type.
The last constant code is equal to FirstFuncType which represent generic function type. We use this single code to represent all functional constants, since we don't have enough space in single byte. Subsequent bytes have to be read from Reader in order to decode the type of the function and the corresponding data.
The set of all possible IR graph nodes can be split in two subsets: 1) operations which may appear in ErgoTree (these are defined by
OpCodes
below) 2) operations which are not valid to be in ErgoTree, but serve special purposes. (these are defined byOpCodesExtra
) We can assume they are both Byte-sized codes, and store as a single byte, but as long as we can differentiate them from context (and where we cannot, we should use special encoding).The general extended encoding is like the following: 0-255 - range of OpCodes 256-511 - range of OpCodesExtra Thus, any code in an extended code range of 0-511 can be saved using
putUShort
. We use Byte to represent OpCodes and OpCodesExtra. We use Short to represent any op code from extended code range. And we use VLQ to serialize Short values of extended codes.Examples: 1) For validation rule CheckValidOpCode we use OpCodes range, so we use single byte encoding. 2) For CheckCostFuncOperation we use 1-511 range and extended encoding (see docs)