From 95cc140afed9b5b3c77df805c7a0b77db9e241df Mon Sep 17 00:00:00 2001 From: PeterSvP Date: Sun, 3 Aug 2025 10:27:52 +0300 Subject: [PATCH 1/2] 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. --- net/FlatBuffers/ByteBuffer.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/net/FlatBuffers/ByteBuffer.cs b/net/FlatBuffers/ByteBuffer.cs index 98772ee889a..4d9c4464f2f 100644 --- a/net/FlatBuffers/ByteBuffer.cs +++ b/net/FlatBuffers/ByteBuffer.cs @@ -264,6 +264,22 @@ public T[] ToArray(int pos, int len) } #endif + public T[] ToArrayPadded(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(Position, Length - Position, padLeft, padRight); + } + public byte[] ToSizedArray() { return ToArray(Position, Length - Position); From f4aab58262eb3dcde9ffd65b4414a7c9c46c80b7 Mon Sep 17 00:00:00 2001 From: Peter Petrov Date: Mon, 25 Aug 2025 03:05:02 +0300 Subject: [PATCH 2/2] Fix indentation --- net/FlatBuffers/ByteBuffer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/FlatBuffers/ByteBuffer.cs b/net/FlatBuffers/ByteBuffer.cs index 4d9c4464f2f..07352f49535 100644 --- a/net/FlatBuffers/ByteBuffer.cs +++ b/net/FlatBuffers/ByteBuffer.cs @@ -274,8 +274,8 @@ public T[] ToArrayPadded(int pos, int len, int padLeft, int padRight) Buffer.BlockCopy(raw, pos, arr, padLeft, len); return arr; } - - public byte[] ToSizedArrayPadded(int padLeft, int padRight) + + public byte[] ToSizedArrayPadded(int padLeft, int padRight) { return ToArrayPadded(Position, Length - Position, padLeft, padRight); }