Initial import

This commit is contained in:
2026-02-14 15:51:55 +01:00
parent 6dc82aed11
commit 6b523e16a2
5 changed files with 570 additions and 0 deletions

29
compat.go Normal file
View File

@@ -0,0 +1,29 @@
package main
/*
#include <mosquitto_plugin.h>
typedef const char const_char;
struct mosquitto_opt* accessArray( struct mosquitto_opt* arrptr, int i)
{
return arrptr + i;
}
*/
import "C"
// Using //export in a file places a restriction on the preamble: it must not contain any definitions, only declarations.
// extractOptions coverts a C mosquitto option array into a GO map
func extractOptions(arrptr *C.struct_mosquitto_opt, length C.int) map[string]string {
opts := make(map[string]string, length)
var i C.int
for i = 0; i < length; i++ {
c_opt := C.accessArray(arrptr, i)
opts[C.GoString(c_opt.key)] = C.GoString(c_opt.value)
}
return opts
}
// goStringFromConstant converts a constant C string into a GO string
func goStringFromConstant(cstr *C.const_char) string {
return C.GoString((*C.char)(cstr))
}