C / C++ / C#

The AMMC zip contains libammc.h and one shared library per platform: windows64\ammc.dll, linux_x86-64/libammc.so, apple_m/libammc.dylib.

The C surface is two functions:

char *p3_to_json(const char *msg);
void  p3_free_string(char *ptr);

p3_to_json takes the decoder's bytes as a hex string and returns the JSON as a NUL-terminated string.

Memory ownership

The returned string is allocated by the library and owned by the caller: release it with p3_free_string when you are done, or it leaks. Do not call free() on it — it was not allocated by your allocator.

Passing NULL to p3_to_json returns NULL; passing NULL to p3_free_string does nothing. p3_to_json returns NULL rather than crashing if the JSON cannot be represented as a C string, so always check before use.

char *json = p3_to_json(msg);
if (json != NULL) {
    printf("%s\n", json);
    p3_free_string(json);
}

Both functions are thread safe and hold no state between calls.

C#

Declare the two functions with DllImport and copy the string out before freeing it, so the marshaller does not free the pointer for you:

using System;
using System.Runtime.InteropServices;

static class Ammc
{
    [DllImport("ammc", CallingConvention = CallingConvention.Cdecl)]
    private static extern IntPtr p3_to_json(string msg);

    [DllImport("ammc", CallingConvention = CallingConvention.Cdecl)]
    private static extern void p3_free_string(IntPtr ptr);

    public static string ToJson(string p3Hex)
    {
        IntPtr ptr = p3_to_json(p3Hex);
        if (ptr == IntPtr.Zero) return null;
        try { return Marshal.PtrToStringAnsi(ptr); }
        finally { p3_free_string(ptr); }
    }
}

class Demo
{
    static void Main()
    {
        Console.WriteLine(Ammc.ToJson(
            "8e023300e5630000010001047a00000003041fd855000408589514394cd8" +
            "040005026d0006025000080200008104501304008f"));
    }
}

DllImport("ammc") finds ammc.dll on Windows and libammc.so / libammc.dylib elsewhere, as long as the file sits next to your executable or on the library search path.