Flat Buffers - Constructs



Overview

Let us now look at a few basic data structures and data types which Google Flat 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 Flat Buffers data types one by one −

Data Types

  • table − "table" is a very basic building block of Flat 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 Flat Buffers types like int, short, 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. We can use alias as well like int16 for short, float32 for float etc.

  • bool − "bool" data type is one of the basic building blocks of Flat 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 Flat Buffers. It translates to an enum in the languages that we use, for example, Java.

  • vector − [] notation is used to create vector or array and is one of the composite datatypes of Flat Buffers. Flat Buffers vector is similar to java array.

  • struct − "struct" is one of the composite datatypes of Flat Buffers. It is used to create non-modifiable set of scalar values. struct uses less memory and is very fast in lookup.

  • Nested Class − We can use an class created using "table" within another "table" and thus creating a nested class.

  • union − "union" is used to create a structure which can accept any of the different type of values.

Advertisements