Files

106 lines
2.6 KiB
C#

// <auto-generated/> by Diplomat
#pragma warning disable 0105
using System;
using System.Runtime.InteropServices;
using Devolutions.IronRdp.Diplomat;
#pragma warning restore 0105
namespace Devolutions.IronRdp;
#nullable enable
public partial class IronRdpPdu: IDisposable
{
private unsafe Raw.IronRdpPdu* _inner;
/// <summary>
/// Creates a managed <c>IronRdpPdu</c> from a raw handle.
/// </summary>
/// <remarks>
/// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free).
/// <br/>
/// This constructor assumes the raw struct is allocated on Rust side.
/// If implemented, the custom Drop implementation on Rust side WILL run on destruction.
/// </remarks>
public unsafe IronRdpPdu(Raw.IronRdpPdu* handle)
{
_inner = handle;
}
/// <returns>
/// A <c>IronRdpPdu</c> allocated on Rust side.
/// </returns>
public static IronRdpPdu New()
{
unsafe
{
Raw.IronRdpPdu* retVal = Raw.IronRdpPdu.New();
return new IronRdpPdu(retVal);
}
}
/// <exception cref="IronRdpException"></exception>
/// <returns>
/// A <c>PduInfo</c> allocated on Rust side.
/// </returns>
public PduInfo FindSize(byte[] bytes)
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("IronRdpPdu");
}
nuint bytesLength = (nuint)bytes.Length;
fixed (byte* bytesPtr = bytes)
{
Raw.PduFfiResultOptBoxPduInfoBoxIronRdpError result = Raw.IronRdpPdu.FindSize(_inner, bytesPtr, bytesLength);
if (!result.isOk)
{
throw new IronRdpException(new IronRdpError(result.Err));
}
Raw.PduInfo* retVal = result.Ok;
if (retVal == null)
{
return null;
}
return new PduInfo(retVal);
}
}
}
/// <summary>
/// Returns the underlying raw handle.
/// </summary>
public unsafe Raw.IronRdpPdu* AsFFI()
{
return _inner;
}
/// <summary>
/// Destroys the underlying object immediately.
/// </summary>
public void Dispose()
{
unsafe
{
if (_inner == null)
{
return;
}
Raw.IronRdpPdu.Destroy(_inner);
_inner = null;
GC.SuppressFinalize(this);
}
}
~IronRdpPdu()
{
Dispose();
}
}