fd91adc0b9a19823c8bdab978b6b469d8f2c744f
[ldk-java] / src / main / java / org / ldk / structs / Init.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 /**
12  * An init message to be sent or received from a peer
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class Init extends CommonBase {
16         Init(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.Init_free(ptr); }
21         }
22
23         /**
24          * The relevant features which the sender supports
25          */
26         public InitFeatures get_features() {
27                 long ret = bindings.Init_get_features(this.ptr);
28                 Reference.reachabilityFence(this);
29                 if (ret >= 0 && ret <= 4096) { return null; }
30                 InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new InitFeatures(null, ret); }
31                 ret_hu_conv.ptrs_to.add(this);
32                 return ret_hu_conv;
33         }
34
35         /**
36          * The relevant features which the sender supports
37          */
38         public void set_features(InitFeatures val) {
39                 bindings.Init_set_features(this.ptr, val == null ? 0 : val.ptr & ~1);
40                 Reference.reachabilityFence(this);
41                 Reference.reachabilityFence(val);
42         }
43
44         /**
45          * Constructs a new Init given each field
46          */
47         public static Init of(InitFeatures features_arg) {
48                 long ret = bindings.Init_new(features_arg == null ? 0 : features_arg.ptr & ~1);
49                 Reference.reachabilityFence(features_arg);
50                 if (ret >= 0 && ret <= 4096) { return null; }
51                 Init ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Init(null, ret); }
52                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
53                 return ret_hu_conv;
54         }
55
56         long clone_ptr() {
57                 long ret = bindings.Init_clone_ptr(this.ptr);
58                 Reference.reachabilityFence(this);
59                 return ret;
60         }
61
62         /**
63          * Creates a copy of the Init
64          */
65         public Init clone() {
66                 long ret = bindings.Init_clone(this.ptr);
67                 Reference.reachabilityFence(this);
68                 if (ret >= 0 && ret <= 4096) { return null; }
69                 Init ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Init(null, ret); }
70                 ret_hu_conv.ptrs_to.add(this);
71                 return ret_hu_conv;
72         }
73
74         /**
75          * Serialize the Init object into a byte array which can be read by Init_read
76          */
77         public byte[] write() {
78                 byte[] ret = bindings.Init_write(this.ptr);
79                 Reference.reachabilityFence(this);
80                 return ret;
81         }
82
83         /**
84          * Read a Init from a byte array, created by Init_write
85          */
86         public static Result_InitDecodeErrorZ read(byte[] ser) {
87                 long ret = bindings.Init_read(ser);
88                 Reference.reachabilityFence(ser);
89                 if (ret >= 0 && ret <= 4096) { return null; }
90                 Result_InitDecodeErrorZ ret_hu_conv = Result_InitDecodeErrorZ.constr_from_ptr(ret);
91                 return ret_hu_conv;
92         }
93
94 }