servicepoint/crates/servicepoint_binding_cs/ServicePoint/BitVec.cs

88 lines
1.5 KiB
C#
Raw Normal View History

using ServicePoint.BindGen;
2024-05-13 00:17:40 +02:00
namespace ServicePoint;
2024-05-13 00:17:40 +02:00
2024-10-16 22:46:34 +02:00
public sealed class BitVec : SpNativeInstance<BindGen.BitVec>
2024-05-13 00:17:40 +02:00
{
2024-10-16 20:56:55 +02:00
public static BitVec New(nuint size)
2024-05-13 00:17:40 +02:00
{
unsafe
{
2024-10-16 21:59:35 +02:00
return new BitVec(BitVecNative.sp_bitvec_new(size));
2024-05-13 00:17:40 +02:00
}
}
public static BitVec Load(Span<byte> bytes)
{
unsafe
{
fixed (byte* bytesPtr = bytes)
{
2024-10-16 21:59:35 +02:00
return new BitVec(BitVecNative.sp_bitvec_load(bytesPtr, (nuint)bytes.Length));
2024-05-13 00:17:40 +02:00
}
}
}
public BitVec Clone()
{
unsafe
{
2024-10-16 22:46:34 +02:00
return new BitVec(Instance->Clone());
2024-05-13 00:17:40 +02:00
}
}
2024-10-16 20:56:55 +02:00
public bool this[nuint index]
2024-05-13 00:17:40 +02:00
{
get
{
unsafe
{
2024-10-16 22:46:34 +02:00
return Instance->Get(index);
2024-05-13 00:17:40 +02:00
}
}
set
{
unsafe
{
2024-10-16 22:46:34 +02:00
Instance->Set(index, value);
2024-05-13 00:17:40 +02:00
}
}
}
public void Fill(bool value)
{
unsafe
{
2024-10-16 22:46:34 +02:00
Instance->Fill(value);
2024-05-13 00:17:40 +02:00
}
}
2024-10-16 20:56:55 +02:00
public nuint Length
2024-05-13 00:17:40 +02:00
{
get
{
unsafe
{
2024-10-16 22:46:34 +02:00
return Instance->Len();
2024-05-13 00:17:40 +02:00
}
}
}
public Span<byte> Data
{
get
{
unsafe
{
2024-10-16 22:46:34 +02:00
return Instance->UnsafeDataRef().AsSpan();
}
}
}
2024-10-16 22:46:34 +02:00
private unsafe BitVec(BindGen.BitVec* instance) : base(instance)
2024-05-13 00:17:40 +02:00
{
}
2024-10-16 22:46:34 +02:00
private protected override unsafe void Free() => Instance->Free();
2024-05-13 00:17:40 +02:00
}