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.
Using protocol buffers - Python Tutorial
From the course: Effective Serialization with Python
Using protocol buffers
- Now that you've generated the Python bindings to waether.proto, let's see how you can use them. Before you can use the code. You'll need to install the Protobuf Python package. Installing packages is a big subject which is out of the scope for this course. The quick solution to get you working is python -m pip install protobuf. And you see that in my computer. It's already installed. Now let's have a look. So ipython. Then I'm going to import the weather_pb2 package as pb. And now let's define a message. So message = pb.Temperature. And I'm going to say that the station is 's42' and the value was a Chilly 17.2 Celsius. And now we need to set the time. So we were saying that the message.time.GetCurrentTime(). Notice that the GetCurrentTime looks a bit weird. It is automatically generated from C++ code which has different naming conventions for methods. We can now have a look at our message. And now to…