2022-04-12 12:12:14 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
|
|
|
"unsafe"
|
2022-10-09 15:08:46 +00:00
|
|
|
|
2022-11-09 19:53:01 +00:00
|
|
|
mobile "github.com/waku-org/go-waku/mobile"
|
2022-04-12 12:12:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Decode a base64 string (useful for reading the payload from waku messages)
|
2022-10-09 15:08:46 +00:00
|
|
|
//
|
|
|
|
//export waku_utils_base64_decode
|
2022-04-12 12:12:14 +00:00
|
|
|
func waku_utils_base64_decode(data *C.char) *C.char {
|
|
|
|
b, err := base64.StdEncoding.DecodeString(C.GoString(data))
|
|
|
|
if err != nil {
|
2022-10-09 15:08:46 +00:00
|
|
|
return C.CString(mobile.MakeJSONResponse(err))
|
2022-04-12 12:12:14 +00:00
|
|
|
}
|
|
|
|
|
2022-10-10 22:08:35 +00:00
|
|
|
return C.CString(mobile.PrepareJSONResponse(string(b), nil))
|
2022-04-12 12:12:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Encode data to base64 (useful for creating the payload of a waku message in the
|
|
|
|
// format understood by waku_relay_publish)
|
2022-10-09 15:08:46 +00:00
|
|
|
//
|
|
|
|
//export waku_utils_base64_encode
|
2022-04-12 12:12:14 +00:00
|
|
|
func waku_utils_base64_encode(data *C.char) *C.char {
|
|
|
|
str := base64.StdEncoding.EncodeToString([]byte(C.GoString(data)))
|
|
|
|
return C.CString(string(str))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Frees a char* since all strings returned by gowaku are allocated in the C heap using malloc.
|
2022-10-09 15:08:46 +00:00
|
|
|
//
|
|
|
|
//export waku_utils_free
|
2022-04-12 12:12:14 +00:00
|
|
|
func waku_utils_free(data *C.char) {
|
|
|
|
C.free(unsafe.Pointer(data))
|
|
|
|
}
|