servicepoint/crates/servicepoint_binding_cs/ServicePoint/Connection.cs

41 lines
949 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 21:59:35 +02:00
public sealed class Connection : SpNativeInstance<SPConnection>
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 21:59:35 +02:00
return ConnectionNative.sp_connection_send_packet(Instance, packet.Into());
}
}
public bool Send(Command command)
{
unsafe
{
2024-10-16 21:59:35 +02:00
return ConnectionNative.sp_connection_send_command(Instance, command.Into());
2024-05-13 00:17:40 +02:00
}
}
2024-10-16 21:59:35 +02:00
private protected override unsafe void Free() => ConnectionNative.sp_connection_free(Instance);
2024-05-13 00:17:40 +02:00
2024-10-16 21:59:35 +02:00
private unsafe Connection(SPConnection* instance) : base(instance)
2024-05-13 00:17:40 +02:00
{
}
}