servicepoint/crates/servicepoint_binding_cs/ServicePoint/BitVec.cs

89 lines
1.7 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-08-29 21:40:33 +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 20:56:55 +02:00
return new BitVec(NativeMethods.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-15 21:50:43 +02:00
return new BitVec(NativeMethods.sp_bitvec_load(bytesPtr, (nuint)bytes.Length));
2024-05-13 00:17:40 +02:00
}
}
}
public BitVec Clone()
{
unsafe
{
2024-10-15 21:50:43 +02:00
return new BitVec(NativeMethods.sp_bitvec_clone(Instance));
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 20:56:55 +02:00
return NativeMethods.sp_bitvec_get(Instance, index);
2024-05-13 00:17:40 +02:00
}
}
set
{
unsafe
{
2024-10-16 20:56:55 +02:00
NativeMethods.sp_bitvec_set(Instance, index, value);
2024-05-13 00:17:40 +02:00
}
}
}
public void Fill(bool value)
{
unsafe
{
2024-10-15 21:50:43 +02:00
NativeMethods.sp_bitvec_fill(Instance, 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 20:56:55 +02:00
return NativeMethods.sp_bitvec_len(Instance);
2024-05-13 00:17:40 +02:00
}
}
}
public Span<byte> Data
{
get
{
unsafe
{
2024-10-15 21:50:43 +02:00
var slice = NativeMethods.sp_bitvec_unsafe_data_ref(Instance);
return new Span<byte>(slice.start, (int)slice.length);
}
}
}
2024-08-29 21:40:33 +02:00
private unsafe BitVec(BindGen.BitVec* instance) : base(instance)
2024-05-13 00:17:40 +02:00
{
}
2024-10-15 21:50:43 +02:00
private protected override unsafe void Free() => NativeMethods.sp_bitvec_free(Instance);
2024-05-13 00:17:40 +02:00
}