servicepoint/crates/servicepoint_binding_cs/ServicePoint/BitVec.cs

89 lines
1.8 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
{
public static BitVec New(int size)
{
unsafe
{
return new BitVec(NativeMethods.sp_bit_vec_new((nuint)size));
2024-05-13 00:17:40 +02:00
}
}
public static BitVec Load(Span<byte> bytes)
{
unsafe
{
fixed (byte* bytesPtr = bytes)
{
return new BitVec(NativeMethods.sp_bit_vec_load(bytesPtr, (nuint)bytes.Length));
2024-05-13 00:17:40 +02:00
}
}
}
public BitVec Clone()
{
unsafe
{
return new BitVec(NativeMethods.sp_bit_vec_clone(Instance));
2024-05-13 00:17:40 +02:00
}
}
public bool this[int index]
{
get
{
unsafe
{
return NativeMethods.sp_bit_vec_get(Instance, (nuint)index);
2024-05-13 00:17:40 +02:00
}
}
set
{
unsafe
{
NativeMethods.sp_bit_vec_set(Instance, (nuint)index, value);
2024-05-13 00:17:40 +02:00
}
}
}
public void Fill(bool value)
{
unsafe
{
NativeMethods.sp_bit_vec_fill(Instance, value);
2024-05-13 00:17:40 +02:00
}
}
public int Length
{
get
{
unsafe
{
return (int)NativeMethods.sp_bit_vec_len(Instance);
2024-05-13 00:17:40 +02:00
}
}
}
public Span<byte> Data
{
get
{
unsafe
{
var slice = NativeMethods.sp_bit_vec_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-09-07 14:11:15 +02:00
private protected override unsafe void Free() => NativeMethods.sp_bit_vec_free(Instance);
2024-05-13 00:17:40 +02:00
}