Skip to content

Commit

Permalink
Fix UTF8Marshaler for FFmpeg.AutoGen (#248)
Browse files Browse the repository at this point in the history
Co-authored-by: Ruslan Balanukhin <[email protected]>
  • Loading branch information
Ruslan-B and Ruslan Balanukhin authored Mar 16, 2023
1 parent 046fe44 commit 91b5ebe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<PackageId>$(AssemblyName)</PackageId>
<Version>5.1.2</Version>
<Version>5.1.2.1</Version>
<Authors>Ruslan Balanukhin</Authors>
<Company>Rationale One</Company>
<Product>FFmpeg.AutoGen</Product>
Expand Down
8 changes: 6 additions & 2 deletions FFmpeg.AutoGen/UTF8Marshaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");

Expand All @@ -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)
Expand Down

0 comments on commit 91b5ebe

Please sign in to comment.