| FlatBuffers An open source project by FPL.

Public Member Functions | Protected Member Functions | Properties | List of all members
FlatBuffers.FlatBufferBuilder Class Reference

Responsible for building up and accessing a FlatBuffer formatted byte array (via ByteBuffer). More...

## Detailed Description

Responsible for building up and accessing a FlatBuffer formatted byte array (via ByteBuffer).

## Public Member Functions
void | Add< T > (Span< T > x)
| Add a span of type T to the buffer (aligns the data and grows if necessary). More...
void | Add< T > (T[] x)
| Add an array of type T to the buffer (aligns the data and grows if necessary). More...
void | AddBool (bool x)
| Add a `bool` to the buffer (aligns the data and grows if necessary). More...
void | AddByte (byte x)
| Add a `byte` to the buffer (aligns the data and grows if necessary). More...
void | AddDouble (double x)
| Add a `double` to the buffer (aligns the data and grows if necessary). More...
void | AddFloat (float x)
| Add a `float` to the buffer (aligns the data and grows if necessary). More...
void | AddInt (int x)
| Add an `int` to the buffer (aligns the data and grows if necessary). More...
void | AddLong (long x)
| Add a `long` to the buffer (aligns the data and grows if necessary). More...
void | AddOffset (int off)
| Adds an offset, relative to where it will be written. More...
void | AddSbyte (sbyte x)
| Add a `sbyte` to the buffer (aligns the data and grows if necessary). More...
void | AddShort (short x)
| Add a `short` to the buffer (aligns the data and grows if necessary). More...
void | AddUint (uint x)
| Add an `uint` to the buffer (aligns the data and grows if necessary). More...
void | AddUlong (ulong x)
| Add an `ulong` to the buffer (aligns the data and grows if necessary). More...
void | AddUshort (ushort x)
| Add an `ushort` to the buffer (aligns the data and grows if necessary). More...
void | Clear ()
| Reset the FlatBufferBuilder by purging all data that it holds. More...
StringOffset | CreateSharedString (string s)
| Store a string in the buffer, which can contain any binary data. More...
StringOffset | CreateString (string s)
| Encode the string `s` in the buffer using UTF-8. More...
StringOffset | CreateUTF8String (Span< byte > chars)
| Creates a string in the buffer from a Span containing a UTF8 string. More...
VectorOffset | CreateVectorOfTables< T > (Offset< T >[] offsets)
| Creates a vector of tables. More...
VectorOffset | EndVector ()
| Writes data necessary to finish a vector construction. More...
void | Finish (int rootTable)
| Finalize a buffer, pointing to the given `root_table`. More...
void | Finish (int rootTable, string fileIdentifier)
| Finalize a buffer, pointing to the given `rootTable`. More...
void | FinishSizePrefixed (int rootTable)
| Finalize a buffer, pointing to the given `root_table`, with the size prefixed. More...
void | FinishSizePrefixed (int rootTable, string fileIdentifier)
| Finalize a buffer, pointing to the given `rootTable`, with the size prefixed. More...
| FlatBufferBuilder (ByteBuffer buffer)
| Create a FlatBufferBuilder backed by the pased in ByteBuffer More...
| FlatBufferBuilder (int initialSize)
| Create a FlatBufferBuilder with a given initial size. More...
byte[] | SizedByteArray ()
| A utility function to copy and return the ByteBuffer data as a `byte[]`. More...

## Protected Member Functions
void | Finish (int rootTable, bool sizePrefix)
| Finalize a buffer, pointing to the given `root_table`. More...
void | Finish (int rootTable, string fileIdentifier, bool sizePrefix)
| Finalize a buffer, pointing to the given `rootTable`. More...

## Properties
ByteBuffer | DataBuffer`[get]`
| Get the ByteBuffer representing the FlatBuffer. More...
bool | ForceDefaults`[get, set]`
| Gets and sets a Boolean to disable the optimization when serializing default values to a Table. More...

## Constructor & Destructor Documentation

## ◆ FlatBufferBuilder() [1/2]

FlatBuffers.FlatBufferBuilder.FlatBufferBuilder | ( | int | initialSize | ) |
| inline

Create a FlatBufferBuilder with a given initial size.

Parameters

  initialSize | The initial size to use for the internal buffer.

## ◆ FlatBufferBuilder() [2/2]

FlatBuffers.FlatBufferBuilder.FlatBufferBuilder | ( | ByteBuffer | buffer | ) |
| inline

Create a FlatBufferBuilder backed by the pased in ByteBuffer

Parameters

  buffer | The ByteBuffer to write to

## Member Function Documentation

## ◆ Add< T >() [1/2]

void FlatBuffers.FlatBufferBuilder.Add< T > | ( | Span< T > | x | ) |
| inline

Add a span of type T to the buffer (aligns the data and grows if necessary).

Template Parameters

  T | The type of the input data

Parameters

  x | The span to copy data from

Type Constraints

  T | : | struct |

## ◆ Add< T >() [2/2]

void FlatBuffers.FlatBufferBuilder.Add< T > | ( | T[] | x | ) |
| inline

Add an array of type T to the buffer (aligns the data and grows if necessary).

Template Parameters

  T | The type of the input data

Parameters

  x | The array to copy data from

Type Constraints

  T | : | struct |

## ◆ AddBool()

void FlatBuffers.FlatBufferBuilder.AddBool | ( | bool | x | ) |
| inline

Add a `bool` to the buffer (aligns the data and grows if necessary).

Parameters

  x | The `bool` to add to the buffer.

## ◆ AddByte()

void FlatBuffers.FlatBufferBuilder.AddByte | ( | byte | x | ) |
| inline

Add a `byte` to the buffer (aligns the data and grows if necessary).

Parameters

  x | The `byte` to add to the buffer.

## ◆ AddDouble()

void FlatBuffers.FlatBufferBuilder.AddDouble | ( | double | x | ) |
| inline

Add a `double` to the buffer (aligns the data and grows if necessary).

Parameters

  x | The `double` to add to the buffer.

## ◆ AddFloat()

void FlatBuffers.FlatBufferBuilder.AddFloat | ( | float | x | ) |
| inline

Add a `float` to the buffer (aligns the data and grows if necessary).

Parameters

  x | The `float` to add to the buffer.

## ◆ AddInt()

void FlatBuffers.FlatBufferBuilder.AddInt | ( | int | x | ) |
| inline

Add an `int` to the buffer (aligns the data and grows if necessary).

Parameters

  x | The `int` to add to the buffer.

## ◆ AddLong()

void FlatBuffers.FlatBufferBuilder.AddLong | ( | long | x | ) |
| inline

Add a `long` to the buffer (aligns the data and grows if necessary).

Parameters

  x | The `long` to add to the buffer.

## ◆ AddOffset()

void FlatBuffers.FlatBufferBuilder.AddOffset | ( | int | off | ) |
| inline

Adds an offset, relative to where it will be written.

Parameters

  off | The offset to add to the buffer.

## ◆ AddSbyte()

void FlatBuffers.FlatBufferBuilder.AddSbyte | ( | sbyte | x | ) |
| inline

Add a `sbyte` to the buffer (aligns the data and grows if necessary).

Parameters

  x | The `sbyte` to add to the buffer.

## ◆ AddShort()

void FlatBuffers.FlatBufferBuilder.AddShort | ( | short | x | ) |
| inline

Add a `short` to the buffer (aligns the data and grows if necessary).

Parameters

  x | The `short` to add to the buffer.

## ◆ AddUint()

void FlatBuffers.FlatBufferBuilder.AddUint | ( | uint | x | ) |
| inline

Add an `uint` to the buffer (aligns the data and grows if necessary).

Parameters

  x | The `uint` to add to the buffer.

## ◆ AddUlong()

void FlatBuffers.FlatBufferBuilder.AddUlong | ( | ulong | x | ) |
| inline

Add an `ulong` to the buffer (aligns the data and grows if necessary).

Parameters

  x | The `ulong` to add to the buffer.

## ◆ AddUshort()

void FlatBuffers.FlatBufferBuilder.AddUshort | ( | ushort | x | ) |
| inline

Add an `ushort` to the buffer (aligns the data and grows if necessary).

Parameters

  x | The `ushort` to add to the buffer.

## ◆ Clear()

void FlatBuffers.FlatBufferBuilder.Clear | ( |  | ) |
| inline

Reset the FlatBufferBuilder by purging all data that it holds.

## ◆ CreateSharedString()

StringOffset FlatBuffers.FlatBufferBuilder.CreateSharedString | ( | string | s | ) |
| inline

Store a string in the buffer, which can contain any binary data.

If a string with this exact contents has already been serialized before, instead simply returns the offset of the existing string.

Parameters

  s | The string to encode.

Returns
  The offset in the buffer where the encoded string starts.

## ◆ CreateString()

StringOffset FlatBuffers.FlatBufferBuilder.CreateString | ( | string | s | ) |
| inline

Encode the string `s` in the buffer using UTF-8.

Parameters

  s | The string to encode.

Returns
  The offset in the buffer where the encoded string starts.

## ◆ CreateUTF8String()

StringOffset FlatBuffers.FlatBufferBuilder.CreateUTF8String | ( | Span< byte > | chars | ) |
| inline

Creates a string in the buffer from a Span containing a UTF8 string.

Parameters

  chars | the UTF8 string to add to the buffer

Returns
  The offset in the buffer where the encoded string starts.

## ◆ CreateVectorOfTables< T >()

VectorOffset FlatBuffers.FlatBufferBuilder.CreateVectorOfTables< T > | ( | Offset< T >[] | offsets | ) |
| inline

Creates a vector of tables.

Parameters

  offsets | Offsets of the tables.

Type Constraints

  T | : | struct |

## ◆ EndVector()

VectorOffset FlatBuffers.FlatBufferBuilder.EndVector | ( |  | ) |
| inline

Writes data necessary to finish a vector construction.

## ◆ Finish() [1/4]

void FlatBuffers.FlatBufferBuilder.Finish | ( | int | rootTable | ) |
| inline

Finalize a buffer, pointing to the given `root_table`.

Parameters

  rootTable | An offset to be added to the buffer.

## ◆ Finish() [2/4]

void FlatBuffers.FlatBufferBuilder.Finish | ( | int | rootTable,
|  | bool | sizePrefix
| ) |  |
| inline protected

Finalize a buffer, pointing to the given `root_table`.

Parameters

  rootTable | An offset to be added to the buffer.
  sizePrefix | Whether to prefix the size to the buffer.

## ◆ Finish() [3/4]

void FlatBuffers.FlatBufferBuilder.Finish | ( | int | rootTable,
|  | string | fileIdentifier
| ) |  |
| inline

Finalize a buffer, pointing to the given `rootTable`.

Parameters

  rootTable | An offset to be added to the buffer.
  fileIdentifier | A FlatBuffer file identifier to be added to the buffer before `root_table`.

## ◆ Finish() [4/4]

void FlatBuffers.FlatBufferBuilder.Finish | ( | int | rootTable,
|  | string | fileIdentifier,
|  | bool | sizePrefix
| ) |  |
| inline protected

Finalize a buffer, pointing to the given `rootTable`.

Parameters

  rootTable | An offset to be added to the buffer.
  fileIdentifier | A FlatBuffer file identifier to be added to the buffer before `root_table`.
  sizePrefix | Whether to prefix the size to the buffer.

## ◆ FinishSizePrefixed() [1/2]

void FlatBuffers.FlatBufferBuilder.FinishSizePrefixed | ( | int | rootTable | ) |
| inline

Finalize a buffer, pointing to the given `root_table`, with the size prefixed.

Parameters

  rootTable | An offset to be added to the buffer.

## ◆ FinishSizePrefixed() [2/2]

void FlatBuffers.FlatBufferBuilder.FinishSizePrefixed | ( | int | rootTable,
|  | string | fileIdentifier
| ) |  |
| inline

Finalize a buffer, pointing to the given `rootTable`, with the size prefixed.

Parameters

  rootTable | An offset to be added to the buffer.
  fileIdentifier | A FlatBuffer file identifier to be added to the buffer before `root_table`.

## ◆ SizedByteArray()

byte[] FlatBuffers.FlatBufferBuilder.SizedByteArray | ( |  | ) |
| inline

A utility function to copy and return the ByteBuffer data as a `byte[]`.

Returns
  A full copy of the FlatBuffer data.

## Property Documentation

## ◆ DataBuffer

ByteBuffer FlatBuffers.FlatBufferBuilder.DataBuffer
| get

Get the ByteBuffer representing the FlatBuffer.

This is typically only called after you call `Finish()`. The actual data starts at the ByteBuffer's current position, not necessarily at `0`.

Returns
  Returns the ByteBuffer for this FlatBuffer.

## ◆ ForceDefaults

bool FlatBuffers.FlatBufferBuilder.ForceDefaults
| get set

Gets and sets a Boolean to disable the optimization when serializing default values to a Table.

In order to save space, fields that are set to their default value don't get serialized into the buffer.

The documentation for this class was generated from the following file:

- FlatBufferBuilder.cs