1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#include "helpers.h"
#include <cstdlib>
#include <cstring>
extern "C" {
#include "_cgo_export.h"
}
namespace gounityscopes {
namespace internal {
std::string from_gostring(void *str) {
GoString *s = static_cast<GoString*>(str);
return std::string(s->p, s->n);
}
void *as_bytes(const std::string &str, int *length) {
*length = str.size();
void *data = malloc(str.size());
if (data == nullptr) {
return nullptr;
}
memcpy(data, str.data(), str.size());
return data;
}
}
}
|