servicepoint/crates/servicepoint_binding_cs/ServicePoint/Connection.cs

41 lines
868 B
C#
Raw Normal View History

2024-05-13 00:17:40 +02:00
using System.Text;
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 Connection : SpNativeInstance<BindGen.Connection>
2024-05-13 00:17:40 +02:00
{
public static Connection Open(string host)
{
unsafe
{
fixed (byte* bytePtr = Encoding.UTF8.GetBytes(host))
{
2024-10-16 21:59:35 +02:00
return new Connection(ConnectionNative.sp_connection_open(bytePtr));
2024-05-13 00:17:40 +02:00
}
}
}
public bool Send(Packet packet)
2024-05-13 00:17:40 +02:00
{
unsafe
{
2024-10-16 22:46:34 +02:00
return Instance->SendPacket(packet.Into());
}
}
public bool Send(Command command)
{
unsafe
{
2024-10-16 22:46:34 +02:00
return Instance->SendCommand(command.Into());
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
2024-10-16 22:46:34 +02:00
private unsafe Connection(BindGen.Connection* instance) : base(instance)
2024-05-13 00:17:40 +02:00
{
}
}