add FinishSizePrefixed methods to CSharp FlatBufferBuilder as well

This commit is contained in:
Robert Schmidtke
2017-10-02 11:30:24 +02:00
parent 095b9a17e1
commit f481bf3542

View File

@@ -580,6 +580,25 @@ namespace FlatBuffers
} }
/// @endcond /// @endcond
/// <summary>
/// Finalize a buffer, pointing to the given `root_table`.
/// </summary>
/// <param name="rootTable">
/// An offset to be added to the buffer.
/// </param>
/// <param name="sizePrefix">
/// Whether to prefix the size to the buffer.
/// </param>
protected void Finish(int rootTable, bool sizePrefix)
{
Prep(_minAlign, sizeof(int) + (sizePrefix ? sizeof(int) : 0));
AddOffset(rootTable);
if (sizePrefix) {
AddInt(_bb.Length - _space);
}
_bb.Position = _space;
}
/// <summary> /// <summary>
/// Finalize a buffer, pointing to the given `root_table`. /// Finalize a buffer, pointing to the given `root_table`.
/// </summary> /// </summary>
@@ -588,9 +607,18 @@ namespace FlatBuffers
/// </param> /// </param>
public void Finish(int rootTable) public void Finish(int rootTable)
{ {
Prep(_minAlign, sizeof(int)); Finish(rootTable, false);
AddOffset(rootTable); }
_bb.Position = _space;
/// <summary>
/// Finalize a buffer, pointing to the given `root_table`, with the size prefixed.
/// </summary>
/// <param name="rootTable">
/// An offset to be added to the buffer.
/// </param>
public void FinishSizePrefixed(int rootTable)
{
Finish(rootTable, true);
} }
/// <summary> /// <summary>
@@ -631,9 +659,12 @@ namespace FlatBuffers
/// A FlatBuffer file identifier to be added to the buffer before /// A FlatBuffer file identifier to be added to the buffer before
/// `root_table`. /// `root_table`.
/// </param> /// </param>
public void Finish(int rootTable, string fileIdentifier) /// <param name="sizePrefix">
/// Whether to prefix the size to the buffer.
/// </param>
protected void Finish(int rootTable, string fileIdentifier, bool sizePrefix)
{ {
Prep(_minAlign, sizeof(int) + Prep(_minAlign, sizeof(int) + (sizePrefix ? sizeof(int) : 0) +
FlatBufferConstants.FileIdentifierLength); FlatBufferConstants.FileIdentifierLength);
if (fileIdentifier.Length != if (fileIdentifier.Length !=
FlatBufferConstants.FileIdentifierLength) FlatBufferConstants.FileIdentifierLength)
@@ -646,10 +677,38 @@ namespace FlatBuffers
{ {
AddByte((byte)fileIdentifier[i]); AddByte((byte)fileIdentifier[i]);
} }
Finish(rootTable); Finish(rootTable, sizePrefix);
} }
/// <summary>
/// Finalize a buffer, pointing to the given `rootTable`.
/// </summary>
/// <param name="rootTable">
/// An offset to be added to the buffer.
/// </param>
/// <param name="fileIdentifier">
/// A FlatBuffer file identifier to be added to the buffer before
/// `root_table`.
/// </param>
public void Finish(int rootTable, string fileIdentifier)
{
Finish(rootTable, fileIdentifier, false);
}
/// <summary>
/// Finalize a buffer, pointing to the given `rootTable`, with the size prefixed.
/// </summary>
/// <param name="rootTable">
/// An offset to be added to the buffer.
/// </param>
/// <param name="fileIdentifier">
/// A FlatBuffer file identifier to be added to the buffer before
/// `root_table`.
/// </param>
public void FinishSizePrefixed(int rootTable, string fileIdentifier)
{
Finish(rootTable, fileIdentifier, true);
}
} }
} }