2024-10-16 21:59:35 +02:00
|
|
|
// <auto-generated>
|
|
|
|
// This code is generated by csbindgen.
|
|
|
|
// DON'T CHANGE THIS DIRECTLY.
|
|
|
|
// </auto-generated>
|
|
|
|
#pragma warning disable CS8500
|
|
|
|
#pragma warning disable CS8981
|
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
2024-10-19 14:21:50 +02:00
|
|
|
namespace ServicePoint
|
2024-10-16 21:59:35 +02:00
|
|
|
{
|
2024-10-19 14:21:50 +02:00
|
|
|
|
|
|
|
public unsafe sealed partial class Packet: IDisposable
|
2024-10-16 21:59:35 +02:00
|
|
|
{
|
2024-10-19 14:21:50 +02:00
|
|
|
#nullable enable
|
2024-10-19 14:35:03 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Turns a [SPCommand] into a [SPPacket].
|
|
|
|
/// The [SPCommand] gets consumed.
|
|
|
|
///
|
|
|
|
/// Will never return NULL.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// - when `command` is NULL
|
|
|
|
///
|
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// The caller has to make sure that:
|
|
|
|
///
|
|
|
|
/// - [SPCommand] points to a valid instance of [SPCommand]
|
|
|
|
/// - [SPCommand] is not used concurrently or after this call
|
|
|
|
/// - the returned [SPPacket] instance is freed in some way, either by using a consuming function or
|
|
|
|
/// by explicitly calling `sp_packet_free`.
|
2024-10-19 15:31:54 +02:00
|
|
|
///
|
|
|
|
/// servicepoint_csbindgen_consumes: command
|
2024-10-19 14:35:03 +02:00
|
|
|
/// </summary>
|
2024-10-19 14:21:50 +02:00
|
|
|
public static Packet FromCommand(Command command)
|
|
|
|
{
|
2024-10-19 15:31:54 +02:00
|
|
|
return new Packet(Packet.sp_packet_from_command(command.Into()));
|
2024-10-19 14:21:50 +02:00
|
|
|
}
|
|
|
|
|
2024-10-19 14:35:03 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Tries to load a [SPPacket] from the passed array with the specified length.
|
|
|
|
///
|
|
|
|
/// returns: NULL in case of an error, pointer to the allocated packet otherwise
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// - when `data` is NULL
|
|
|
|
///
|
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// The caller has to make sure that:
|
|
|
|
///
|
|
|
|
/// - `data` points to a valid memory region of at least `length` bytes
|
|
|
|
/// - `data` is not written to concurrently
|
|
|
|
/// - the returned [SPPacket] instance is freed in some way, either by using a consuming function or
|
|
|
|
/// by explicitly calling `sp_packet_free`.
|
|
|
|
/// </summary>
|
2024-10-19 14:21:50 +02:00
|
|
|
public static Packet? TryLoad(byte* data, nuint length)
|
|
|
|
{
|
|
|
|
var native = Packet.sp_packet_try_load(data, length);
|
|
|
|
return native == null ? null : new Packet(native);
|
|
|
|
}
|
|
|
|
|
2024-10-19 14:35:03 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Clones a [SPPacket].
|
|
|
|
///
|
|
|
|
/// Will never return NULL.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// - when `packet` is NULL
|
|
|
|
///
|
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// The caller has to make sure that:
|
|
|
|
///
|
|
|
|
/// - `packet` points to a valid [SPPacket]
|
|
|
|
/// - `packet` is not written to concurrently
|
|
|
|
/// - the returned instance is freed in some way, either by using a consuming function or
|
|
|
|
/// by explicitly calling `sp_packet_free`.
|
|
|
|
/// </summary>
|
2024-10-19 14:21:50 +02:00
|
|
|
public Packet Clone()
|
|
|
|
{
|
2024-10-19 15:31:54 +02:00
|
|
|
return new Packet(Packet.sp_packet_clone(this.Instance));
|
2024-10-19 14:21:50 +02:00
|
|
|
}
|
|
|
|
|
2024-10-16 21:59:35 +02:00
|
|
|
|
2024-10-19 15:31:54 +02:00
|
|
|
#region internal machinery
|
2024-10-19 14:21:50 +02:00
|
|
|
private SPPacket* _instance;
|
|
|
|
internal SPPacket* Instance
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (_instance == null)
|
|
|
|
throw new NullReferenceException("instance is null");
|
|
|
|
return _instance;
|
|
|
|
}
|
|
|
|
}
|
2024-10-16 21:59:35 +02:00
|
|
|
|
2024-10-19 14:21:50 +02:00
|
|
|
private Packet(SPPacket* instance)
|
|
|
|
{
|
|
|
|
ArgumentNullException.ThrowIfNull(instance);
|
|
|
|
_instance = instance;
|
|
|
|
}
|
2024-10-16 21:59:35 +02:00
|
|
|
|
2024-10-19 14:21:50 +02:00
|
|
|
internal SPPacket* Into()
|
|
|
|
{
|
|
|
|
var instance = Instance;
|
|
|
|
_instance = null;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Free()
|
|
|
|
{
|
|
|
|
if (_instance != null)
|
|
|
|
Packet.sp_packet_free(Into());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
Free();
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
~Packet() => Free();
|
|
|
|
|
2024-10-19 15:31:54 +02:00
|
|
|
#endregion
|
|
|
|
|
2024-10-19 14:21:50 +02:00
|
|
|
#nullable restore
|
2024-10-19 15:31:54 +02:00
|
|
|
#region native methods
|
|
|
|
const string __DllName = "servicepoint_binding_c";
|
2024-10-16 21:59:35 +02:00
|
|
|
[DllImport(__DllName, EntryPoint = "sp_packet_from_command", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
2024-10-19 14:21:50 +02:00
|
|
|
private static extern SPPacket* sp_packet_from_command(SPCommand* command);
|
2024-10-16 21:59:35 +02:00
|
|
|
|
|
|
|
[DllImport(__DllName, EntryPoint = "sp_packet_try_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
2024-10-19 14:21:50 +02:00
|
|
|
private static extern SPPacket* sp_packet_try_load(byte* data, nuint length);
|
2024-10-16 21:59:35 +02:00
|
|
|
|
|
|
|
[DllImport(__DllName, EntryPoint = "sp_packet_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
2024-10-19 14:21:50 +02:00
|
|
|
private static extern SPPacket* sp_packet_clone(SPPacket* packet);
|
2024-10-16 21:59:35 +02:00
|
|
|
|
|
|
|
[DllImport(__DllName, EntryPoint = "sp_packet_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
2024-10-19 14:21:50 +02:00
|
|
|
private static extern void sp_packet_free(SPPacket* packet);
|
2024-10-16 21:59:35 +02:00
|
|
|
|
|
|
|
|
2024-10-19 15:31:54 +02:00
|
|
|
#endregion
|
2024-10-16 21:59:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
2024-10-19 14:21:50 +02:00
|
|
|
public unsafe partial struct SPPacket
|
2024-10-16 21:59:35 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|