Protocol Buffers - Constructs



Overview

Let us now look at a few basic data structures and data types which Google Protocol Buffers provides. We will look at these data structures using an example of a Movie theater.

Note that for this structure while we will be using Java code, using them in Python code should also be equally simple and possible.

In the next few chapters, we will discuss the following Protocol Buffers data types one by one −

Data Types

  • message − "message" is a very basic building block of Protocol Buffers. This translates to a class in the languages that we use, for example, Java, Python, etc

  • string − "string" data type translate to a string in the languages that we use, for example, Java, Python, etc

  • Numbers − Numbers include Protocol Buffers types like int32, int64, float, double, which are basic building blocks of Protobuf. It translates to int, long float, double, respectively, in the languages that we use, for example, Java, Python, etc.

  • bool − "bool" data type is one of the basic building blocks of Protocol Buffers. It translates to Boolean in the languages that we use, for example, Java, Python, etc.

  • enum − "enum" is one of the composite datatypes of Protocol Buffers. It translates to an enum in the languages that we use, for example, Java.

  • repeated − "repeated" is used to create array or list and is one of the composite datatypes of Protocol Buffers. Protocol Buffers translates this to a java.util.list interface in Java.

  • map − "Map" is one of the composite datatypes of Protocol Buffers. Protocol Buffers translates this to a java.util.Map interface in Java.

  • Nested Class − We can use an class created using "message" within another "message" and thus creating a nested class. Protocol Buffers translates translates this to a nested Java class.

Advertisements