Skip to content

C / C++

The C ABI hub. A single wickra_shazam.h header + prebuilt library links from C, C++, or any C-capable language. Drive a matcher with the JSON command protocol.

bash
# prebuilt wickra_shazam.h + library per platform:
# github.com/wickra-lib/wickra-shazam/releases
c
#include "wickra_shazam.h"

const char *spec = "{\"features\":[{\"kind\":\"price\",\"field\":\"close\"}],"
                   "\"window\":10,\"metric\":\"euclid\"}";

WickraShazam *s = wickra_shazam_new(spec);

// length-out protocol: call with NULL to size, then fill the buffer.
const char *index_cmd = "{\"cmd\":\"index\",\"history\":[ /* candles */ ]}";
wickra_shazam_command(s, index_cmd, NULL, 0);

const char *match_cmd = "{\"cmd\":\"match\",\"current\":[ /* candles */ ],\"k\":5}";
int len = wickra_shazam_command(s, match_cmd, NULL, 0);
char *report = malloc((size_t)len + 1);
wickra_shazam_command(s, match_cmd, report, (size_t)len + 1);   // JSON response

printf("%s\n", report);
free(report);
wickra_shazam_free(s);

The header is generated by cbindgen and is the same ABI the C#, Go, Java and R bindings link against.

More