Files

133 lines
3.0 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 WriteBuf: IDisposable
{
private unsafe Raw.WriteBuf* _inner;
public VecU8 Filled
{
get
{
return GetFilled();
}
}
/// <summary>
/// Creates a managed <c>WriteBuf</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 WriteBuf(Raw.WriteBuf* handle)
{
_inner = handle;
}
/// <returns>
/// A <c>WriteBuf</c> allocated on Rust side.
/// </returns>
public static WriteBuf New()
{
unsafe
{
Raw.WriteBuf* retVal = Raw.WriteBuf.New();
return new WriteBuf(retVal);
}
}
public void Clear()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("WriteBuf");
}
Raw.WriteBuf.Clear(_inner);
}
}
/// <exception cref="IronRdpException"></exception>
public void ReadIntoBuf(byte[] buf)
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("WriteBuf");
}
nuint bufLength = (nuint)buf.Length;
fixed (byte* bufPtr = buf)
{
Raw.PduFfiResultVoidBoxIronRdpError result = Raw.WriteBuf.ReadIntoBuf(_inner, bufPtr, bufLength);
if (!result.isOk)
{
throw new IronRdpException(new IronRdpError(result.Err));
}
}
}
}
/// <returns>
/// A <c>VecU8</c> allocated on Rust side.
/// </returns>
public VecU8 GetFilled()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("WriteBuf");
}
Raw.VecU8* retVal = Raw.WriteBuf.GetFilled(_inner);
return new VecU8(retVal);
}
}
/// <summary>
/// Returns the underlying raw handle.
/// </summary>
public unsafe Raw.WriteBuf* AsFFI()
{
return _inner;
}
/// <summary>
/// Destroys the underlying object immediately.
/// </summary>
public void Dispose()
{
unsafe
{
if (_inner == null)
{
return;
}
Raw.WriteBuf.Destroy(_inner);
_inner = null;
GC.SuppressFinalize(this);
}
}
~WriteBuf()
{
Dispose();
}
}