From the course: Effective Serialization with Python
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Solution: Trade objects size - Python Tutorial
From the course: Effective Serialization with Python
Solution: Trade objects size
(upbeat music) - [Instructor] We start by writing the Protocol Buffers of the finishing file. So, this is the trade, with the syntax of Port three the package, and we import Timestamp. The Python Data and Type is mapped to Protocol Buffers Timestamp. The symbol, which is a string in Python is a string in Protocol Buffers. The volume which is in int in Python is int 64 in Protocol Buffers, the price which is float in Python is a double in Protocol Buffers. And finally, the buy which is Boolean Python is also Boolean in Protocol Buffers. Once we wrote this file, we can generate. So, Protoc--Python_out. current directory, and the trade.proto, that we have. And now once the code is generated, we can use the code. At the beginning, we import the generated code as PB. And then, we start with the initial size of zero. For every object in trades, we create a Protocol Buffer object from the trade. And remember…