mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-29 09:52:02 +00:00
Clarified in the docs how to get to the serialized bytes.
This was a frequent source of confusion, since in all implementations the data doesn't start at offset 0 in the buffer. Change-Id: I045966e65928e9acd9def84e215914ecb5510653
This commit is contained in:
@@ -1161,12 +1161,23 @@ like so:
|
|||||||
~~~{.java}
|
~~~{.java}
|
||||||
// This must be called after `finish()`.
|
// This must be called after `finish()`.
|
||||||
java.nio.ByteBuffer buf = builder.dataBuffer();
|
java.nio.ByteBuffer buf = builder.dataBuffer();
|
||||||
|
// The data in this ByteBuffer does NOT start at 0, but at buf.position().
|
||||||
|
// The number of bytes is buf.remaining().
|
||||||
|
|
||||||
|
// Alternatively this copies the above data out of the ByteBuffer for you:
|
||||||
|
bytes[] buf = builder.sizedByteArray();
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-csharp">
|
<div class="language-csharp">
|
||||||
~~~{.cs}
|
~~~{.cs}
|
||||||
// This must be called after `Finish()`.
|
// This must be called after `Finish()`.
|
||||||
var buf = builder.DataBuffer; // Of type `FlatBuffers.ByteBuffer`.
|
var buf = builder.DataBuffer; // Of type `FlatBuffers.ByteBuffer`.
|
||||||
|
// The data in this ByteBuffer does NOT start at 0, but at buf.Position.
|
||||||
|
// The end of the data is marked by buf.Length, so the size is
|
||||||
|
// buf.Length - buf.Position.
|
||||||
|
|
||||||
|
// Alternatively this copies the above data out of the ByteBuffer for you:
|
||||||
|
bytes[] buf = builder.SizedByteArray();
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-go">
|
<div class="language-go">
|
||||||
@@ -1184,13 +1195,16 @@ like so:
|
|||||||
<div class="language-javascript">
|
<div class="language-javascript">
|
||||||
~~~{.js}
|
~~~{.js}
|
||||||
// This must be called after `finish()`.
|
// This must be called after `finish()`.
|
||||||
var buf = builder.dataBuffer(); // Of type `flatbuffers.ByteBuffer`.
|
var buf = builder.asUint8Array(); // Of type `Uint8Array`.
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-php">
|
<div class="language-php">
|
||||||
~~~{.php}
|
~~~{.php}
|
||||||
// This must be called after `finish()`.
|
// This must be called after `finish()`.
|
||||||
$buf = $builder->dataBuffer(); // Of type `Google\FlatBuffers\ByteBuffer`
|
$buf = $builder->dataBuffer(); // Of type `Google\FlatBuffers\ByteBuffer`
|
||||||
|
// The data in this ByteBuffer does NOT start at 0, but at buf->getPosition().
|
||||||
|
// The end of the data is marked by buf->capacity(), so the size is
|
||||||
|
// buf->capacity() - buf->getPosition().
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-c">
|
<div class="language-c">
|
||||||
|
|||||||
@@ -238,9 +238,8 @@ flatbuffers.Builder.prototype.dataBuffer = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the ByteBuffer representing the FlatBuffer. Only call this after you've
|
* Get the bytes representing the FlatBuffer. Only call this after you've
|
||||||
* called finish(). The actual data starts at the ByteBuffer's current position,
|
* called finish().
|
||||||
* not necessarily at 0.
|
|
||||||
*
|
*
|
||||||
* @returns {Uint8Array}
|
* @returns {Uint8Array}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -582,6 +582,8 @@ namespace FlatBuffers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// This is typically only called after you call `Finish()`.
|
/// This is typically only called after you call `Finish()`.
|
||||||
|
/// The actual data starts at the ByteBuffer's current position,
|
||||||
|
/// not necessarily at `0`.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// Returns the ByteBuffer for this FlatBuffer.
|
/// Returns the ByteBuffer for this FlatBuffer.
|
||||||
|
|||||||
Reference in New Issue
Block a user