Module encode

Expand description

Bitcoin consensus-encodable types.

This is basically a replacement of the Encodable trait which does normalization of endianness etc., to ensure that the encoding matches the network consensus encoding.

Essentially, anything that must go on the disk or network must be encoded using the Encodable trait, since this data must be the same for all systems. Any data going to the user e.g., over JSONRPC, should use the ordinary Encodable trait. (This should also be the same across systems, of course, but has some critical differences from the network format e.g., scripts come with an opcode decode, hashes are big-endian, numbers are typically big-endian decimals, etc.)

Structs§

CheckedData
Data and a 4-byte checksum.
VarInt
A variable-length unsigned integer.

Enums§

Error
Encoding error.
FromHexError
Hex deserialization error.

Constants§

MAX_VEC_SIZE
Maximum size, in bytes, of a vector we are allowed to decode.

Traits§

Decodable
Data which can be encoded in a consensus-consistent way.
Encodable
Data which can be encoded in a consensus-consistent way.
ReadExt
Extensions of Read to decode data as per Bitcoin consensus.
WriteExt
Extensions of Write to encode data as per Bitcoin consensus.

Functions§

deserialize
Deserializes an object from a vector, will error if said deserialization doesn’t consume the entire vector.
deserialize_hex
Deserialize any decodable type from a hex string, will error if said deserialization doesn’t consume the entire vector.
deserialize_partial
Deserializes an object from a vector, but will not report an error if said deserialization doesn’t consume the entire vector.
serialize
Encodes an object into a vector.
serialize_hex
Encodes an object into a hex-encoded string.