Make slice-vec-len generic
[ldk-java] / genbindings.py
index a5e9ec41e38c62742b561606341f301aa0bd3b0c..9c647a6362c82b3ca9f095be9b8d65a841607881 100755 (executable)
@@ -544,7 +544,7 @@ void __attribute__((destructor)) check_leaks() {
        public static native void free_heap_ptr(long ptr);
        public static native byte[] get_u8_slice_bytes(long slice_ptr);
        public static native long bytes_to_u8_vec(byte[] bytes);
-       public static native long u8_vec_len(long vec);
+       public static native long vec_slice_len(long vec);
 
 """)
     out_c.write("""
@@ -576,7 +576,12 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_bytes_1to_1u8_1vec (JNIEnv * _
        (*_env)->GetByteArrayRegion (_env, bytes, 0, vec->datalen, vec->data);
        return (long)vec;
 }
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_u8_1vec_1len (JNIEnv * env, jclass _a, jlong ptr) {
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env, jclass _a, jlong ptr) {
+        // Check offsets of a few Vec types are all consistent as we're meant to be generic across types
+       _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_SignatureZ, datalen), "Vec<*> needs to be mapped identically");
+       _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_MessageSendEventZ, datalen), "Vec<*> needs to be mapped identically");
+       _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_EventZ, datalen), "Vec<*> needs to be mapped identically");
+       _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_C2Tuple_usizeTransactionZZ, datalen), "Vec<*> needs to be mapped identically");
        LDKCVec_u8Z *vec = (LDKCVec_u8Z*)ptr;
        return (long)vec->datalen;
 }