-jstring str_ref_to_ts(const char* chars, size_t len) {
- char* err_buf = MALLOC(len + 4, "str conv buf");
- *((uint32_t*)err_buf) = len;
- memcpy(err_buf + 4, chars, len);
- return (uint32_t) err_buf;
+DECL_ARR_TYPE(int64_t, int64_t);
+DECL_ARR_TYPE(int8_t, int8_t);
+DECL_ARR_TYPE(uint32_t, uint32_t);
+DECL_ARR_TYPE(void*, ptr);
+DECL_ARR_TYPE(char, char);
+typedef charArray jstring;
+
+static inline jstring str_ref_to_ts(const char* chars, size_t len) {
+ charArray arr = init_charArray(len);
+ memcpy(arr->elems, chars, len);
+ return arr;
+}
+static inline LDKStr str_ref_to_owned_c(const jstring str) {
+ char* newchars = MALLOC(str->arr_len + 1, "String chars");
+ memcpy(newchars, str->elems, str->arr_len);
+ newchars[str->arr_len] = 0;
+ LDKStr res = {
+ .chars = newchars,
+ .len = str->arr_len,
+ .chars_is_owned = true
+ };
+ return res;