diff --git a/Directory.Build.props b/Directory.Build.props index 57d5919..ee449a0 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ $(AssemblyName) - 5.1.2 + 5.1.2.1 Ruslan Balanukhin Rationale One FFmpeg.AutoGen diff --git a/FFmpeg.AutoGen/UTF8Marshaler.cs b/FFmpeg.AutoGen/UTF8Marshaler.cs index ba02474..c33c75c 100644 --- a/FFmpeg.AutoGen/UTF8Marshaler.cs +++ b/FFmpeg.AutoGen/UTF8Marshaler.cs @@ -6,13 +6,15 @@ namespace FFmpeg.AutoGen; public class UTF8Marshaler : ICustomMarshaler { + private static readonly UTF8Marshaler Instance = new(); + public virtual object MarshalNativeToManaged(IntPtr pNativeData) => FromNative(Encoding.UTF8, pNativeData); public virtual IntPtr MarshalManagedToNative(object managedObj) { if (managedObj == null) return IntPtr.Zero; - + if (managedObj is not string str) throw new MarshalDirectiveException($"{GetType().Name} must be used on a string."); @@ -35,7 +37,9 @@ public void CleanUpManagedData(object managedObj) } public int GetNativeDataSize() => -1; // Not a value type - + + public static ICustomMarshaler GetInstance(string cookie) => Instance; + public static unsafe string FromNative(Encoding encoding, IntPtr pNativeData) => FromNative(encoding, (byte*)pNativeData); public static unsafe string FromNative(Encoding encoding, byte* pNativeData)