Python-like dumps / loads / dump / load

Python-like dumps / loads / dump / load

1. Serialization

Recently, I was looking at the transaction of the blockchain, which mentioned and mentioned the concept of serialization . When transactions are transmitted over the network or exchanged between applications, they are serialized. Serialization is the process of converting an internal representation of a data structure into a format (also known as a byte stream) that can be sent one byte at a time . Serialization is most commonly used to encode data structures for transmission over a network or for storage in files.

2. Deserialization

Most Bitcoin libraries and architectures do not store transactions as byte streams internally, because every time a single field needs to be accessed, complex parsing is required.
For convenience and readability, the Bitcoin library stores transactions internally in data structures (usually object-oriented structures).
The process of converting from a byte stream representation of a transaction to a library's internal data structure representation is called deserialization or transaction parsing . The process of converting back to a stream of bytes for transmission over a network, hashing, or storage on disk is called serialization. Most Bitcoin function libraries have built-in functions for transaction serialization and deserialization

3. Python serialization and deserialization

Corresponding to the serialization and deserialization of blockchain transactions, I have deepened my understanding of serialization and deserialization in Python.
Serialization (encoding): Convert python object encoding to Json string.
Deserialization (decoding): Decode the json format string into a python object.
The main methods of the json library: dumps, dump, loads, load
1. dumps function: serialize the dictionary type into a json format string through json
2. loads function: convert the json encoded string into a python data structure
json .dumps() encodes pyhton's data type to str's josn format
json.loads() decodes str's json data type to pyhton's data type

json.dump(x,y) x is the object, y is the file object write json to the file
json.losd(y) read json from the file object

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324811553&siteId=291194637