mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-07 13:53:38 +00:00
[C#] Added ToSizedArrayPadded(int padLeft, int padRight) to ByteBuffers to avoid unnecessary copying. (#8658)
* Added ToSizedArrayPadded(int padLeft, int padRight) + ToArrayPadded(pos, len, padLeft, padRight) to the byteBuffers. This is for API completion and to avoid unnecessary copy when framing my packets. I needed this to create a flat buffer with space in front of it for header / metadata. * Fix indentation --------- Co-authored-by: Björn Harrtell <bjornharrtell@users.noreply.github.com> Co-authored-by: Wouter van Oortmerssen <aardappel@gmail.com>
This commit is contained in:
@@ -264,6 +264,22 @@ namespace Google.FlatBuffers
|
||||
}
|
||||
#endif
|
||||
|
||||
public T[] ToArrayPadded<T>(int pos, int len, int padLeft, int padRight)
|
||||
where T : struct
|
||||
{
|
||||
AssertOffsetAndLength(pos, len);
|
||||
int totalBytes = padLeft + len + padRight;
|
||||
byte[] raw = _buffer.Buffer;
|
||||
T[] arr = new T[totalBytes];
|
||||
Buffer.BlockCopy(raw, pos, arr, padLeft, len);
|
||||
return arr;
|
||||
}
|
||||
|
||||
public byte[] ToSizedArrayPadded(int padLeft, int padRight)
|
||||
{
|
||||
return ToArrayPadded<byte>(Position, Length - Position, padLeft, padRight);
|
||||
}
|
||||
|
||||
public byte[] ToSizedArray()
|
||||
{
|
||||
return ToArray<byte>(Position, Length - Position);
|
||||
|
||||
Reference in New Issue
Block a user