mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-03 04:21:13 +00:00
Added -M flatc flag to the documentation.
Change-Id: Ie19af91ec5bf0b65297cba58c124bceaa58fd73e
This commit is contained in:
@@ -76,7 +76,7 @@ $(document).ready(function(){initNavTree('md__python_usage.html','');});
|
||||
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="keywordflow">for</span> i <span class="keywordflow">in</span> xrange(monster.InventoryLength()):</div>
|
||||
<div class="line"><a name="l00002"></a><span class="lineno"> 2</span>  monster.Inventory(i) <span class="comment"># do something here</span></div>
|
||||
</div><!-- fragment --><p>You can also construct these buffers in Python using the functions found in the generated code, and the FlatBufferBuilder class:</p>
|
||||
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> builder = flatbuffers.NewBuilder(0)</div>
|
||||
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> builder = flatbuffers.Builder(0)</div>
|
||||
</div><!-- fragment --><p>Create strings:</p>
|
||||
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> s = builder.CreateString(<span class="stringliteral">"MyMonster"</span>)</div>
|
||||
</div><!-- fragment --><p>Create a table with a struct contained therein:</p>
|
||||
@@ -90,7 +90,7 @@ $(document).ready(function(){initNavTree('md__python_usage.html','');});
|
||||
<div class="line"><a name="l00008"></a><span class="lineno"> 8</span> example.MonsterAddTest4(builder, test4s)</div>
|
||||
<div class="line"><a name="l00009"></a><span class="lineno"> 9</span> mon = example.MonsterEnd(builder)</div>
|
||||
<div class="line"><a name="l00010"></a><span class="lineno"> 10</span> </div>
|
||||
<div class="line"><a name="l00011"></a><span class="lineno"> 11</span> final_flatbuffer = bulder.Output()</div>
|
||||
<div class="line"><a name="l00011"></a><span class="lineno"> 11</span> final_flatbuffer = builder.Output()</div>
|
||||
</div><!-- fragment --><p>Unlike C++, Python does not support table creation functions like 'createMonster()'. This is to create the buffer without using temporary object allocation (since the <code>Vec3</code> is an inline component of <code>Monster</code>, it has to be created right where it is added, whereas the name and the inventory are not inline, and <b>must</b> be created outside of the table creation sequence). Structs do have convenient methods that allow you to construct them in one call. These also have arguments for nested structs, e.g. if a struct has a field <code>a</code> and a nested struct field <code>b</code> (which has fields <code>c</code> and <code>d</code>), then the arguments will be <code>a</code>, <code>c</code> and <code>d</code>.</p>
|
||||
<p>Vectors also use this start/end pattern to allow vectors of both scalar types and structs:</p>
|
||||
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> example.MonsterStartInventoryVector(builder, 5)</div>
|
||||
|
||||
Reference in New Issue
Block a user