blob: c9b813d0510bc1e7bc5ed27abf386ca1b4e73c43 [file] [log] [blame]
<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<title>FlatBuffers: FlatBuffers</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,400italic,500,500italic,700,700italic|Roboto+Mono:400,700" rel="stylesheet">
<link href="style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea" style="height: 110px;">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="commonprojectlogo">
<img alt="Logo" src="fpl_logo_small.png"/>
</td>
<td style="padding-left: 0.5em;">
<div id="projectname">FlatBuffers
</div>
<div style="font-size:12px;">
An open source project by <a href="https://developers.google.com/games/#Tools">FPL</a>.
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('index.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="PageDoc"><div class="header">
<div class="headertitle">
<div class="title">FlatBuffers </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><a class="anchor" id="flatbuffers_index"></a></p>
<h1><a class="anchor" id="flatbuffers_overview"></a>
Overview</h1>
<p><a class="el" href="index.html#flatbuffers_overview">FlatBuffers</a> is an efficient cross platform serialization library for C++, C#, C, Go, Java, Kotlin, JavaScript, Lobster, Lua, TypeScript, PHP, Python, Rust and Swift. It was originally created at Google for game development and other performance-critical applications.</p>
<p>It is available as Open Source on <a href="http://github.com/google/flatbuffers">GitHub</a> under the Apache license, v2 (see LICENSE.txt).</p>
<h2><a class="anchor" id="autotoc_md0"></a>
Why use FlatBuffers?</h2>
<ul>
<li><b>Access to serialized data without parsing/unpacking</b> - What sets FlatBuffers apart is that it represents hierarchical data in a flat binary buffer in such a way that it can still be accessed directly without parsing/unpacking, while also still supporting data structure evolution (forwards/backwards compatibility).</li>
<li><b>Memory efficiency and speed</b> - The only memory needed to access your data is that of the buffer. It requires 0 additional allocations (in C++, other languages may vary). FlatBuffers is also very suitable for use with mmap (or streaming), requiring only part of the buffer to be in memory. Access is close to the speed of raw struct access with only one extra indirection (a kind of vtable) to allow for format evolution and optional fields. It is aimed at projects where spending time and space (many memory allocations) to be able to access or construct serialized data is undesirable, such as in games or any other performance sensitive applications. See the <a class="el" href="flatbuffers_benchmarks.html">benchmarks</a> for details.</li>
<li><b>Flexible</b> - Optional fields means not only do you get great forwards and backwards compatibility (increasingly important for long-lived games: don't have to update all data with each new version!). It also means you have a lot of choice in what data you write and what data you don't, and how you design data structures.</li>
<li><b>Tiny code footprint</b> - Small amounts of generated code, and just a single small header as the minimum dependency, which is very easy to integrate. Again, see the benchmark section for details.</li>
<li><b>Strongly typed</b> - Errors happen at compile time rather than manually having to write repetitive and error prone run-time checks. Useful code can be generated for you.</li>
<li><p class="startli"><b>Convenient to use</b> - Generated C++ code allows for terse access &amp; construction code. Then there's optional functionality for parsing schemas and JSON-like text representations at runtime efficiently if needed (faster and more memory efficient than other JSON parsers).</p>
<p class="startli">Java, Kotlin and Go code supports object-reuse. C# has efficient struct based accessors.</p>
</li>
<li><b>Cross platform code with no dependencies</b> - C++ code will work with any recent gcc/clang and VS2010. Comes with build files for the tests &amp; samples (Android .mk files, and cmake for all other platforms).</li>
</ul>
<h3><a class="anchor" id="autotoc_md1"></a>
Why not use Protocol Buffers, or .. ?</h3>
<p>Protocol Buffers is indeed relatively similar to FlatBuffers, with the primary difference being that FlatBuffers does not need a parsing/ unpacking step to a secondary representation before you can access data, often coupled with per-object memory allocation. The code is an order of magnitude bigger, too. Protocol Buffers has no optional text import/export.</p>
<h3><a class="anchor" id="autotoc_md2"></a>
But all the cool kids use JSON!</h3>
<p>JSON is very readable (which is why we use it as our optional text format) and very convenient when used together with dynamically typed languages (such as JavaScript). When serializing data from statically typed languages, however, JSON not only has the obvious drawback of runtime inefficiency, but also forces you to write <em>more</em> code to access data (counterintuitively) due to its dynamic-typing serialization system. In this context, it is only a better choice for systems that have very little to no information ahead of time about what data needs to be stored.</p>
<p>If you do need to store data that doesn't fit a schema, FlatBuffers also offers a schema-less (self-describing) version!</p>
<p>Read more about the "why" of FlatBuffers in the <a class="el" href="flatbuffers_white_paper.html">white paper</a>.</p>
<h3><a class="anchor" id="autotoc_md3"></a>
Who uses FlatBuffers?</h3>
<ul>
<li><a href="http://www.cocos2d-x.org/">Cocos2d-x</a>, the #1 open source mobile game engine, uses it to serialize all their <a href="http://www.cocos2d-x.org/reference/native-cpp/V3.5/d7/d2d/namespaceflatbuffers.html">game data</a>.</li>
<li><a href="http://facebook.com/">Facebook</a> uses it for client-server communication in their Android app. They have a nice <a href="https://code.facebook.com/posts/872547912839369/improving-facebook-s-performance-on-android-with-flatbuffers/">article</a> explaining how it speeds up loading their posts.</li>
<li><a href="https://developers.google.com/games/#Tools">Fun Propulsion Labs</a> at Google uses it extensively in all their libraries and games.</li>
</ul>
<h2><a class="anchor" id="autotoc_md4"></a>
Usage in brief</h2>
<p>This section is a quick rundown of how to use this system. Subsequent sections provide a more in-depth usage guide.</p>
<ul>
<li>Write a schema file that allows you to define the data structures you may want to serialize. Fields can have a scalar type (ints/floats of all sizes), or they can be a: string; array of any type; reference to yet another object; or, a set of possible objects (unions). Fields are optional and have defaults, so they don't need to be present for every object instance.</li>
<li>Use <code>flatc</code> (the FlatBuffer compiler) to generate a C++ header (or Java/Kotlin/C#/Go/Python.. classes) with helper classes to access and construct serialized data. This header (say <code>mydata_generated.h</code>) only depends on <code>flatbuffers.h</code>, which defines the core functionality.</li>
<li>Use the <code>FlatBufferBuilder</code> class to construct a flat binary buffer. The generated functions allow you to add objects to this buffer recursively, often as simply as making a single function call.</li>
<li>Store or send your buffer somewhere!</li>
<li>When reading it back, you can obtain the pointer to the root object from the binary buffer, and from there traverse it conveniently in-place with <code>object-&gt;field()</code>.</li>
</ul>
<h2><a class="anchor" id="autotoc_md5"></a>
In-depth documentation</h2>
<ul>
<li>How to <a class="el" href="flatbuffers_guide_building.html">build the compiler</a> and samples on various platforms.</li>
<li>How to <a class="el" href="flatbuffers_guide_using_schema_compiler.html">use the compiler</a>.</li>
<li>How to <a class="el" href="flatbuffers_guide_writing_schema.html">write a schema</a>.</li>
<li>How to <a class="el" href="flatbuffers_guide_use_cpp.html">use the generated C++ code</a> in your own programs.</li>
<li>How to <a class="el" href="flatbuffers_guide_use_java.html">use the generated Java code</a> in your own programs.</li>
<li>How to <a class="el" href="flatbuffers_guide_use_c-sharp.html">use the generated C# code</a> in your own programs.</li>
<li>How to use the generated Kotlin code in your own programs.</li>
<li>How to <a class="el" href="flatbuffers_guide_use_go.html">use the generated Go code</a> in your own programs.</li>
<li>How to <a class="el" href="flatbuffers_guide_use_lua.html">use the generated Lua code</a> in your own programs.</li>
<li>How to <a class="el" href="flatbuffers_guide_use_javascript.html">use the generated JavaScript code</a> in your own programs.</li>
<li>How to <a class="el" href="flatbuffers_guide_use_typescript.html">use the generated TypeScript code</a> in your own programs.</li>
<li>How to <a class="el" href="flatbuffers_guide_use_c.html">use FlatBuffers in C with `flatcc`</a> in your own programs.</li>
<li>How to <a class="el" href="flatbuffers_guide_use_lobster.html">use the generated Lobster code</a> in your own programs.</li>
<li>How to <a class="el" href="flatbuffers_guide_use_rust.html">use the generated Rust code</a> in your own programs.</li>
<li>How to <a class="el" href="flatbuffers_guide_use_swift.html">use the generated Swift code</a> in your own programs.</li>
<li><a class="el" href="flatbuffers_support.html">Support matrix</a> for platforms/languages/features.</li>
<li>Some <a class="el" href="flatbuffers_benchmarks.html">benchmarks</a> showing the advantage of using FlatBuffers.</li>
<li>A <a class="el" href="flatbuffers_white_paper.html">white paper</a> explaining the "why" of FlatBuffers.</li>
<li>How to use the <a class="el" href="flexbuffers.html">schema-less</a> version of FlatBuffers.</li>
<li>A description of the <a class="el" href="flatbuffers_internals.html">internals</a> of FlatBuffers.</li>
<li>A formal <a class="el" href="flatbuffers_grammar.html">grammar</a> of the schema language.</li>
</ul>
<h2><a class="anchor" id="autotoc_md6"></a>
Online resources</h2>
<ul>
<li><a href="http://github.com/google/flatbuffers">GitHub repository</a></li>
<li><a href="http://google.github.io/flatbuffers">Landing page</a></li>
<li><a href="https://groups.google.com/forum/#!forum/flatbuffers">FlatBuffers Google Group</a></li>
<li><a href="https://discord.gg/6qgKs3R">Discord</a> and <a href="https://gitter.im/lobster_programming_language/community">Gitter</a> chat.</li>
<li><a href="http://github.com/google/flatbuffers/issues">FlatBuffers Issues Tracker</a></li>
<li>Independent implementations &amp; tools:<ul>
<li><a href="https://github.com/dvidelabs/flatcc">FlatCC</a> Alternative FlatBuffers parser, code generator and runtime all in C.</li>
</ul>
</li>
<li>Videos:<ul>
<li>Colt's <a href="https://www.youtube.com/watch?v=iQTxMkSJ1dQ">DevByte</a>.</li>
<li>GDC 2015 <a href="https://www.youtube.com/watch?v=olmL1fUnQAQ">Lightning Talk</a>.</li>
<li>FlatBuffers for <a href="https://www.youtube.com/watch?v=-BPVId_lA5w">Go</a>.</li>
<li>Evolution of FlatBuffers <a href="https://www.youtube.com/watch?v=a0QE0xS8rKM">visualization</a>.</li>
</ul>
</li>
<li>Useful documentation created by others:<ul>
<li><a href="https://rwinslow.com/tags/flatbuffers/">FlatBuffers in Go</a></li>
<li><a href="http://frogermcs.github.io/flatbuffers-in-android-introdution/">FlatBuffers in Android</a></li>
<li><a href="http://frogermcs.github.io/json-parsing-with-flatbuffers-in-android/">Parsing JSON to FlatBuffers in Java</a></li>
<li><a href="http://exiin.com/blog/flatbuffers-for-unity-sample-code/">FlatBuffers in Unity</a></li>
<li><a href="https://github.com/mzaks/FlexBuffers-CSharp">FlexBuffers C#</a> and <a href="https://medium.com/@icex33/flexbuffers-for-unity3d-4d1ab5c53fbe?">article</a> on its use. </li>
</ul>
</li>
</ul>
</div></div><!-- PageDoc -->
</div><!-- contents -->
</div><!-- doc-content -->
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-49880327-7', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>