servicepoint-binding-csharp/servicepoint2-binding-cs/src/Connection.cs
Vinzenz Schroeter 1dad113ca1 a bunch of minor changes combined:
- From instead of Into
- unsafe_data_ref for other payloads
- CByteSlice for returning memory spans
- send Packet instead of Into<Packet>
- expose packet layer to C/C#
2024-05-15 20:34:51 +02:00

36 lines
798 B
C#

using System.Text;
using ServicePoint2.BindGen;
namespace ServicePoint2;
public sealed class Connection : Sp2NativeInstance<BindGen.Connection>
{
public static Connection Open(string host)
{
unsafe
{
fixed (byte* bytePtr = Encoding.UTF8.GetBytes(host))
{
return new Connection(NativeMethods.sp2_connection_open(bytePtr));
}
}
}
public bool Send(Packet packet)
{
unsafe
{
return NativeMethods.sp2_connection_send(Instance, packet.Into());
}
}
private protected override unsafe void Dealloc()
{
NativeMethods.sp2_connection_dealloc(Instance);
}
private unsafe Connection(BindGen.Connection* instance) : base(instance)
{
}
}