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>
@@ -621,35 +649,66 @@ namespace FlatBuffers
return newArray; return newArray;
} }
/// <summary> /// <summary>
/// Finalize a buffer, pointing to the given `rootTable`. /// Finalize a buffer, pointing to the given `rootTable`.
/// </summary> /// </summary>
/// <param name="rootTable"> /// <param name="rootTable">
/// An offset to be added to the buffer. /// An offset to be added to the buffer.
/// </param> /// </param>
/// <param name="fileIdentifier"> /// <param name="fileIdentifier">
/// 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.
Prep(_minAlign, sizeof(int) + /// </param>
FlatBufferConstants.FileIdentifierLength); protected void Finish(int rootTable, string fileIdentifier, bool sizePrefix)
if (fileIdentifier.Length != {
FlatBufferConstants.FileIdentifierLength) Prep(_minAlign, sizeof(int) + (sizePrefix ? sizeof(int) : 0) +
throw new ArgumentException( FlatBufferConstants.FileIdentifierLength);
"FlatBuffers: file identifier must be length " + if (fileIdentifier.Length !=
FlatBufferConstants.FileIdentifierLength, FlatBufferConstants.FileIdentifierLength)
"fileIdentifier"); throw new ArgumentException(
for (int i = FlatBufferConstants.FileIdentifierLength - 1; i >= 0; "FlatBuffers: file identifier must be length " +
i--) FlatBufferConstants.FileIdentifierLength,
{ "fileIdentifier");
AddByte((byte)fileIdentifier[i]); for (int i = FlatBufferConstants.FileIdentifierLength - 1; i >= 0;
} i--)
Finish(rootTable); {
AddByte((byte)fileIdentifier[i]);
}
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);
}
} }
} }