add Load methods with Spans

This commit is contained in:
Vinzenz Schroeter 2024-10-19 16:04:01 +02:00
parent f836220259
commit f968f92917
6 changed files with 46 additions and 2 deletions

View file

@ -2,6 +2,17 @@ namespace ServicePoint;
public sealed partial class BitVec public sealed partial class BitVec
{ {
public static BitVec Load(Span<byte> bytes)
{
unsafe
{
fixed (byte* bytesPtr = bytes)
{
return Load(bytesPtr, (nuint)bytes.Length);
}
}
}
public bool this[nuint index] public bool this[nuint index]
{ {
get => Get(index); get => Get(index);

View file

@ -2,6 +2,17 @@ namespace ServicePoint;
public sealed partial class Bitmap public sealed partial class Bitmap
{ {
public static Bitmap Load(nuint width, nuint height, Span<byte> bytes)
{
unsafe
{
fixed (byte* bytesPtr = bytes)
{
return Load(width, height, bytesPtr, (nuint)bytes.Length);
}
}
}
public bool this[nuint x, nuint y] public bool this[nuint x, nuint y]
{ {
get => Get(x, y); get => Get(x, y);

View file

@ -2,6 +2,17 @@ namespace ServicePoint;
public sealed partial class BrightnessGrid public sealed partial class BrightnessGrid
{ {
public static BrightnessGrid Load(nuint width, nuint height, Span<byte> bytes)
{
unsafe
{
fixed (byte* bytesPtr = bytes)
{
return Load(width, height, bytesPtr, (nuint)bytes.Length);
}
}
}
public byte this[nuint x, nuint y] public byte this[nuint x, nuint y]
{ {
get => Get(x, y); get => Get(x, y);

View file

@ -2,5 +2,5 @@ namespace ServicePoint;
public partial struct SPByteSlice public partial struct SPByteSlice
{ {
public unsafe Span<byte> AsSpan() => new Span<byte>(start, (int)length); public unsafe Span<byte> AsSpan() => new (start, (int)length);
} }

View file

@ -4,6 +4,17 @@ namespace ServicePoint;
public sealed partial class Cp437Grid public sealed partial class Cp437Grid
{ {
public static Cp437Grid Load(nuint width, nuint height, Span<byte> bytes)
{
unsafe
{
fixed (byte* bytesPtr = bytes)
{
return Load(width, height, bytesPtr, (nuint)bytes.Length);
}
}
}
public byte this[nuint x, nuint y] public byte this[nuint x, nuint y]
{ {
get => Get(x, y); get => Get(x, y);

View file

@ -4,7 +4,7 @@ namespace ServicePoint;
public sealed partial class Packet public sealed partial class Packet
{ {
public static bool TryFromBytes(Span<byte> bytes, [MaybeNullWhen(false)] out Packet packet) public static bool TryLoad(Span<byte> bytes, [MaybeNullWhen(false)] out Packet packet)
{ {
unsafe unsafe
{ {