[Java] Print error stack trace when tests fail
[ldk-java] / src / main / java / org / ldk / structs / Type.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10 /**
11  * Defines a type identifier for sending messages over the wire.
12  * 
13  * Messages implementing this trait specify a type and must be [`Writeable`].
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class Type extends CommonBase {
17         final bindings.LDKType bindings_instance;
18         Type(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
19         private Type(bindings.LDKType arg) {
20                 super(bindings.LDKType_new(arg));
21                 this.ptrs_to.add(arg);
22                 this.bindings_instance = arg;
23         }
24         @Override @SuppressWarnings("deprecation")
25         protected void finalize() throws Throwable {
26                 if (ptr != 0) { bindings.Type_free(ptr); } super.finalize();
27         }
28         /**
29          * Destroys the object, freeing associated resources. After this call, any access
30          * to this object may result in a SEGFAULT or worse.
31          *
32          * You should generally NEVER call this method. You should let the garbage collector
33          * do this for you when it finalizes objects. However, it may be useful for types
34          * which represent locks and should be closed immediately to avoid holding locks
35          * until the GC runs.
36          */
37         public void destroy() {
38                 if (ptr != 0) { bindings.Type_free(ptr); }
39                 ptr = 0;
40         }
41         public static interface TypeInterface {
42                 /**
43                  * Returns the type identifying the message payload.
44                  */
45                 short type_id();
46                 /**
47                  * Return a human-readable "debug" string describing this object
48                  */
49                 String debug_str();
50                 /**
51                  * Serialize the object into a byte array
52                  */
53                 byte[] write();
54         }
55         private static class LDKTypeHolder { Type held; }
56         public static Type new_impl(TypeInterface arg) {
57                 final LDKTypeHolder impl_holder = new LDKTypeHolder();
58                 impl_holder.held = new Type(new bindings.LDKType() {
59                         @Override public short type_id() {
60                                 short ret = arg.type_id();
61                                 Reference.reachabilityFence(arg);
62                                 return ret;
63                         }
64                         @Override public String debug_str() {
65                                 String ret = arg.debug_str();
66                                 Reference.reachabilityFence(arg);
67                                 return ret;
68                         }
69                         @Override public byte[] write() {
70                                 byte[] ret = arg.write();
71                                 Reference.reachabilityFence(arg);
72                                 return ret;
73                         }
74                 });
75                 return impl_holder.held;
76         }
77         /**
78          * Returns the type identifying the message payload.
79          */
80         public short type_id() {
81                 short ret = bindings.Type_type_id(this.ptr);
82                 Reference.reachabilityFence(this);
83                 return ret;
84         }
85
86         /**
87          * Return a human-readable "debug" string describing this object
88          */
89         public String debug_str() {
90                 String ret = bindings.Type_debug_str(this.ptr);
91                 Reference.reachabilityFence(this);
92                 return ret;
93         }
94
95         /**
96          * Serialize the object into a byte array
97          */
98         public byte[] write() {
99                 byte[] ret = bindings.Type_write(this.ptr);
100                 Reference.reachabilityFence(this);
101                 return ret;
102         }
103
104         long clone_ptr() {
105                 long ret = bindings.Type_clone_ptr(this.ptr);
106                 Reference.reachabilityFence(this);
107                 return ret;
108         }
109
110         /**
111          * Creates a copy of a Type
112          */
113         public Type clone() {
114                 long ret = bindings.Type_clone(this.ptr);
115                 Reference.reachabilityFence(this);
116                 if (ret >= 0 && ret <= 4096) { return null; }
117                 Type ret_hu_conv = new Type(null, ret);
118                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
119                 return ret_hu_conv;
120         }
121
122 }