de9e7ae0c52bcec6f8ee18f5af767b23c4dc284d
[ldk-java] / src / main / java / org / ldk / structs / CustomOnionMessageContents.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  * The contents of a custom onion message.
12  */
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class CustomOnionMessageContents extends CommonBase {
15         final bindings.LDKCustomOnionMessageContents bindings_instance;
16         CustomOnionMessageContents(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
17         private CustomOnionMessageContents(bindings.LDKCustomOnionMessageContents arg) {
18                 super(bindings.LDKCustomOnionMessageContents_new(arg));
19                 this.ptrs_to.add(arg);
20                 this.bindings_instance = arg;
21         }
22         @Override @SuppressWarnings("deprecation")
23         protected void finalize() throws Throwable {
24                 if (ptr != 0) { bindings.CustomOnionMessageContents_free(ptr); } super.finalize();
25         }
26         /**
27          * Destroys the object, freeing associated resources. After this call, any access
28          * to this object may result in a SEGFAULT or worse.
29          *
30          * You should generally NEVER call this method. You should let the garbage collector
31          * do this for you when it finalizes objects. However, it may be useful for types
32          * which represent locks and should be closed immediately to avoid holding locks
33          * until the GC runs.
34          */
35         public void destroy() {
36                 if (ptr != 0) { bindings.CustomOnionMessageContents_free(ptr); }
37                 ptr = 0;
38         }
39         public static interface CustomOnionMessageContentsInterface {
40                 /**
41                  * Returns the TLV type identifying the message contents. MUST be >= 64.
42                  */
43                 long tlv_type();
44                 /**
45                  * Serialize the object into a byte array
46                  */
47                 byte[] write();
48         }
49         private static class LDKCustomOnionMessageContentsHolder { CustomOnionMessageContents held; }
50         public static CustomOnionMessageContents new_impl(CustomOnionMessageContentsInterface arg) {
51                 final LDKCustomOnionMessageContentsHolder impl_holder = new LDKCustomOnionMessageContentsHolder();
52                 impl_holder.held = new CustomOnionMessageContents(new bindings.LDKCustomOnionMessageContents() {
53                         @Override public long tlv_type() {
54                                 long ret = arg.tlv_type();
55                                 Reference.reachabilityFence(arg);
56                                 return ret;
57                         }
58                         @Override public byte[] write() {
59                                 byte[] ret = arg.write();
60                                 Reference.reachabilityFence(arg);
61                                 return ret;
62                         }
63                 });
64                 return impl_holder.held;
65         }
66         /**
67          * Returns the TLV type identifying the message contents. MUST be >= 64.
68          */
69         public long tlv_type() {
70                 long ret = bindings.CustomOnionMessageContents_tlv_type(this.ptr);
71                 Reference.reachabilityFence(this);
72                 return ret;
73         }
74
75         /**
76          * Serialize the object into a byte array
77          */
78         public byte[] write() {
79                 byte[] ret = bindings.CustomOnionMessageContents_write(this.ptr);
80                 Reference.reachabilityFence(this);
81                 return ret;
82         }
83
84         long clone_ptr() {
85                 long ret = bindings.CustomOnionMessageContents_clone_ptr(this.ptr);
86                 Reference.reachabilityFence(this);
87                 return ret;
88         }
89
90         /**
91          * Creates a copy of a CustomOnionMessageContents
92          */
93         public CustomOnionMessageContents clone() {
94                 long ret = bindings.CustomOnionMessageContents_clone(this.ptr);
95                 Reference.reachabilityFence(this);
96                 if (ret >= 0 && ret <= 4096) { return null; }
97                 CustomOnionMessageContents ret_hu_conv = new CustomOnionMessageContents(null, ret);
98                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
99                 return ret_hu_conv;
100         }
101
102 }