From f1c2222e587c17fff8cf4880a5ebf7f84ca8bbba Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Tue, 14 Nov 2023 23:06:48 +0200 Subject: [PATCH] Added back IParameterSpanData Corrected ToSpan for non string values --- src/BUTR.NativeAOT.Shared/Common.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/BUTR.NativeAOT.Shared/Common.cs b/src/BUTR.NativeAOT.Shared/Common.cs index 64233e9..97cdb3d 100644 --- a/src/BUTR.NativeAOT.Shared/Common.cs +++ b/src/BUTR.NativeAOT.Shared/Common.cs @@ -43,6 +43,12 @@ public unsafe interface IParameterSpanFormattable { static abstract ReadOnlySpan ToSpan(TSelf* ptr); } + public unsafe interface IParameterSpanData + where TSelf : unmanaged, IParameterSpanData + where TValue : unmanaged + { + static abstract ReadOnlySpan ToSpan(TSelf* ptr, int length); + } public unsafe interface IParameterNonPtr where TSelf : unmanaged, IParameterNonPtr { } public unsafe interface IParameterRawPtr where TSelf : unmanaged, IParameterRawPtr @@ -249,6 +255,7 @@ public bool TryFormat(Span utf8Destination, out int bytesWritten, ReadOnly public readonly unsafe struct param_data : IParameter, IParameterSpanFormattable, + IParameterSpanData, IParameterRawPtr, IParameterIntPtr, IFormattable @@ -257,7 +264,9 @@ public bool TryFormat(Span utf8Destination, out int bytesWritten, ReadOnly public static implicit operator byte*(param_data ptr) => (byte*) &ptr; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlySpan ToSpan(param_data* ptr) => $"[{new IntPtr(ptr->Value):x16}]"; + public static ReadOnlySpan ToSpan(param_data* ptr) => ptr->ToString(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlySpan ToSpan(param_data* ptr, int length) => new(ptr->Value, length); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IntPtr IParameterIntPtr.ToPtr(param_data* ptr) => new(ptr); [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -279,7 +288,7 @@ public bool TryFormat(Span utf8Destination, out int bytesWritten, ReadOnly public static implicit operator byte*(param_callback ptr) => (byte*) &ptr; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlySpan ToSpan(param_callback* ptr) => $"[{new IntPtr(ptr->CallbackPtr):x16}]"; + public static ReadOnlySpan ToSpan(param_callback* ptr) => ptr->ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IntPtr IParameterIntPtr.ToPtr(param_callback* ptr) => new(ptr); [MethodImpl(MethodImplOptions.AggressiveInlining)]