+static inline uint32_t init_arr(size_t arr_len, size_t elem_size, const char *type_desc) {
+ uint32_t *elems = (uint32_t*)MALLOC(arr_len * elem_size + 4, type_desc);
+ elems[0] = arr_len;
+ return (uint32_t)elems;
+}
+
+static inline 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;
+}
+static inline LDKStr str_ref_to_owned_c(jstring str) {
+ uint32_t *str_len = (uint32_t*)str;
+ char* newchars = MALLOC(*str_len + 1, "String chars");
+ memcpy(newchars, (const char*)(str + 4), *str_len);
+ newchars[*str_len] = 0;
+ LDKStr res= {
+ .chars = newchars,
+ .len = *str_len,
+ .chars_is_owned = true
+ };
+ return res;
+}