mirror of
https://github.com/netbirdio/IronRDP.git
synced 2026-05-22 18:43:12 -07:00
134 lines
3.0 KiB
C#
134 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 VecU8: IDisposable
|
|
{
|
|
private unsafe Raw.VecU8* _inner;
|
|
|
|
public nuint Size
|
|
{
|
|
get
|
|
{
|
|
return GetSize();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a managed <c>VecU8</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 VecU8(Raw.VecU8* handle)
|
|
{
|
|
_inner = handle;
|
|
}
|
|
|
|
/// <returns>
|
|
/// A <c>VecU8</c> allocated on Rust side.
|
|
/// </returns>
|
|
public static VecU8 FromBytes(byte[] bytes)
|
|
{
|
|
unsafe
|
|
{
|
|
nuint bytesLength = (nuint)bytes.Length;
|
|
fixed (byte* bytesPtr = bytes)
|
|
{
|
|
Raw.VecU8* retVal = Raw.VecU8.FromBytes(bytesPtr, bytesLength);
|
|
return new VecU8(retVal);
|
|
}
|
|
}
|
|
}
|
|
|
|
public nuint GetSize()
|
|
{
|
|
unsafe
|
|
{
|
|
if (_inner == null)
|
|
{
|
|
throw new ObjectDisposedException("VecU8");
|
|
}
|
|
nuint retVal = Raw.VecU8.GetSize(_inner);
|
|
return retVal;
|
|
}
|
|
}
|
|
|
|
/// <exception cref="IronRdpException"></exception>
|
|
public void Fill(byte[] buffer)
|
|
{
|
|
unsafe
|
|
{
|
|
if (_inner == null)
|
|
{
|
|
throw new ObjectDisposedException("VecU8");
|
|
}
|
|
nuint bufferLength = (nuint)buffer.Length;
|
|
fixed (byte* bufferPtr = buffer)
|
|
{
|
|
Raw.UtilsFfiResultVoidBoxIronRdpError result = Raw.VecU8.Fill(_inner, bufferPtr, bufferLength);
|
|
if (!result.isOk)
|
|
{
|
|
throw new IronRdpException(new IronRdpError(result.Err));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <returns>
|
|
/// A <c>VecU8</c> allocated on Rust side.
|
|
/// </returns>
|
|
public static VecU8 NewEmpty()
|
|
{
|
|
unsafe
|
|
{
|
|
Raw.VecU8* retVal = Raw.VecU8.NewEmpty();
|
|
return new VecU8(retVal);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the underlying raw handle.
|
|
/// </summary>
|
|
public unsafe Raw.VecU8* AsFFI()
|
|
{
|
|
return _inner;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Destroys the underlying object immediately.
|
|
/// </summary>
|
|
public void Dispose()
|
|
{
|
|
unsafe
|
|
{
|
|
if (_inner == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Raw.VecU8.Destroy(_inner);
|
|
_inner = null;
|
|
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|
|
|
|
~VecU8()
|
|
{
|
|
Dispose();
|
|
}
|
|
}
|