// 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 DecodedPointer: IDisposable
{
private unsafe Raw.DecodedPointer* _inner;
public BytesSlice Data
{
get
{
return GetData();
}
}
public ushort Height
{
get
{
return GetHeight();
}
}
public ushort HotspotX
{
get
{
return GetHotspotX();
}
}
public ushort HotspotY
{
get
{
return GetHotspotY();
}
}
public ushort Width
{
get
{
return GetWidth();
}
}
///
/// Creates a managed DecodedPointer from a raw handle.
///
///
/// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free).
///
/// This constructor assumes the raw struct is allocated on Rust side.
/// If implemented, the custom Drop implementation on Rust side WILL run on destruction.
///
public unsafe DecodedPointer(Raw.DecodedPointer* handle)
{
_inner = handle;
}
public ushort GetWidth()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("DecodedPointer");
}
ushort retVal = Raw.DecodedPointer.GetWidth(_inner);
return retVal;
}
}
public ushort GetHeight()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("DecodedPointer");
}
ushort retVal = Raw.DecodedPointer.GetHeight(_inner);
return retVal;
}
}
public ushort GetHotspotX()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("DecodedPointer");
}
ushort retVal = Raw.DecodedPointer.GetHotspotX(_inner);
return retVal;
}
}
public ushort GetHotspotY()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("DecodedPointer");
}
ushort retVal = Raw.DecodedPointer.GetHotspotY(_inner);
return retVal;
}
}
///
/// A BytesSlice allocated on Rust side.
///
public BytesSlice GetData()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("DecodedPointer");
}
Raw.BytesSlice* retVal = Raw.DecodedPointer.GetData(_inner);
return new BytesSlice(retVal);
}
}
///
/// Returns the underlying raw handle.
///
public unsafe Raw.DecodedPointer* AsFFI()
{
return _inner;
}
///
/// Destroys the underlying object immediately.
///
public void Dispose()
{
unsafe
{
if (_inner == null)
{
return;
}
Raw.DecodedPointer.Destroy(_inner);
_inner = null;
GC.SuppressFinalize(this);
}
}
~DecodedPointer()
{
Dispose();
}
}