
Learn how to serialize data with FlatBuffers, a lightweight binary serialization solution by Google, including how to write and evolve FlatBuffers schemas and leverage binary serialization benefits.
Welcome to a course introduction that guides you on navigating the material, accessing support, and using FAQs and Q&A to get help quickly, with lifetime access and a certificate.
Begin by setting up the project, installing IDEs and dependencies, and building a Hello, world program. Learn serialization with built-in C++ features and the flatbuffers library and schema language.
Install visual studio by downloading the installer, select desktop development with C++, and add cmake tools for Windows, with an optional game development workload.
Install CMake on Windows by downloading the 64-bit msi, running the install wizard, agreeing to terms, adding CMake to the system PATH, and finishing to enable project management.
Install the Ninja build system on Windows by downloading the ninja-win zip, extracting the executable into a Ninja folder, and updating the PATH environment variable.
Install Git on Windows by downloading the Git for Windows setup, selecting default options, using the Windows console, and completing the installer.
Set up a C++ hello world project with CMake: create CMakeLists.txt, define project, add executable, write main.cpp, build in Visual Studio, and run to print 'Hello, World!' to the console.
learn coding standards for C++20 projects by configuring editorconfig and clang-format, following Google style rules, and applying naming conventions for variables, functions, classes, and members.
Create two console apps, a sender and a reader, configure CMake to build both executables, and verify by building and running messages that simulate real-world communication.
Explore what serialization means, compare binary and text formats like json and xml, and learn how binary serialization boosts speed and efficiency while preserving data evolution with FlatBuffers.
Serialize data yourself in C++ by implementing a message class with a text field, getters, setters, and stream operators for writing to a binary file; this approach is not scalable.
Explore common problems in custom C++ serialization, such as missing multi-language support and compatibility with old messages, and learn how FlatBuffers offers a simple, lightweight solution.
Learn how to use FlatBuffers to serialize data in C++ by compiling .fbs files with flatc, generating headers, and exploring the builder pattern and root types.
Learn to download and integrate the flatbuffers library with CMake FetchContent, declare and fetch the dependency from a git tag, then find_package and link sender and reader to flatbuffers.
Set up flatbuffer compilation in cmake by adding message.fbs, defining the course namespace and a message table with a text field, and setting the root type to the message table.
Serialize a flatbuffer binary by using a FlatBufferBuilder to store strings, create a root message, finish the buffer, and write bytes to a file.
Learn to read flatbuffer data from a binary file using C++20 filesystem, read bytes into a buffer, and parse with GetMessage to print the message text.
Explore the root type as the simplest unit in flatbuffers and see how removing it affects generated headers, reader behavior, and network transfers.
Declare an enumeration with the enum keyword to define message types such as notification and warning, backed by a sized type and defaulting to the first type when unset.
Explore how FlatBuffers separates structs as small scalar value types from tables, which are instantiatable classes with serialization, via a country struct with unsigned country and state codes.
Explore FlatBuffers array types by introducing a MessagePack that stores a list of messages, using vectors of offsets, creating and finishing a message pack, and iterating to read messages.
Explore how optional and required fields work in FlatBuffers, including scalar vs reference types, validation, and error handling when required fields trigger assertions.
Explore unions, safe flatbuffers constructs backed by an enumeration that act as a variant in C++, allowing a packet data union to carry either a message or a message pack.
Expose the object API in flatbuffers for C++ by using the --gen-object-api flag to generate types with buffer-to-type conversions, and explore UnPack and UnPackTo returning MessagePackT on heap or stack.
Serialize flatbuffers data to json for debugging by enabling reflection with --reflect-types and --reflect-names, then use a json visitor and IterateFlatbuffer with MiniReflectTypeTable to write message.json.
Deserialize from json using a FlatBuffers binary schema (.bfbs), build the schema, load the binary and json with a parser, then parse to produce flatbuffer memory.
Handle schema updates in flatbuffers by safely adding new members, renaming fields, and deprecating properties, while avoiding struct changes, memory mapping, and unsafe reordering.
Welcome
In this bite-sized course you will learn what data serialization is and how to do it properly. Data serialization is crucial for various tasks. It is essential for web developers who need to transmit data over the network. It is also important for desktop applications and games where the ability to save and retrieve settings or game saves is necessary.
In any of the above cases you would like to have a fast method of preparing data for being sent and also read back on the other side. So I will introduce binary serialization and its benefits compared to the more widespread JSON or XML alternatives.
FlatBuffers
This library is developed by Google and is a really efficient mechanism for serializing data. It is one of the two libraries available that are really popular, and the second one is also developed by Google and is called ProtoBuf, which is used mostly for their other technology called gRPC. The FlatBuffers library is more lightweight and versatile, though, and you can use it for so much more than ProtoBuf.
I will be teaching the FlatBuffers schema language for most of this course. But a lot of the ideas taken from FlatBuffers are also applicable to ProtoBuf and gRPC communication. You will also be able to compile FlatBuffers for other languages as well and not just for C++—so you can have a C++ server and an EcmaScript client, for example.
This course is primarily taught on the Windows OS, but the knowledge gained can easily translate into other operating systems as well.