提交导表相关功能

This commit is contained in:
2025-09-27 17:53:39 +08:00
parent f899a55769
commit c1a3df2192
79 changed files with 4365 additions and 1 deletions

View File

@@ -0,0 +1,77 @@
using System.Buffers;
namespace NBConfigBuilder;
public enum MemoryStreamBufferSource
{
None = 0,
Pack = 1,
UnPack = 2,
}
public sealed class MemoryStreamBuffer : MemoryStream, IBufferWriter<byte>
{
public MemoryStreamBufferSource MemoryStreamBufferSource;
public MemoryStreamBuffer()
{
}
public MemoryStreamBuffer(MemoryStreamBufferSource memoryStreamBufferSource, int capacity) : base(capacity)
{
MemoryStreamBufferSource = memoryStreamBufferSource;
}
public MemoryStreamBuffer(byte[] buffer) : base(buffer)
{
}
public void Advance(int count)
{
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count), count, "The value of 'count' cannot be negative.");
}
var newLength = Position + count;
if (newLength != Length)
{
SetLength(newLength);
}
Position = newLength;
}
public Memory<byte> GetMemory(int sizeHint = 0)
{
if (sizeHint < 0)
{
throw new ArgumentOutOfRangeException(nameof(sizeHint), sizeHint,
"The value of 'count' cannot be negative.");
}
if (Length - Position <= sizeHint)
{
SetLength(Position + sizeHint);
}
return new Memory<byte>(GetBuffer(), (int)Position, (int)(Length - Position));
}
public Span<byte> GetSpan(int sizeHint = 0)
{
if (sizeHint < 0)
{
throw new ArgumentOutOfRangeException(nameof(sizeHint), sizeHint,
"The value of 'count' cannot be negative.");
}
if (Length - Position <= sizeHint)
{
SetLength(Position + sizeHint);
}
return new Span<byte>(GetBuffer(), (int)Position, (int)(Length - Position));
}
}