[C#] Run tests against release library in determinism CI run
[ldk-java] / src / main / java / org / ldk / structs / DecodeError.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 error in decoding a message or struct.
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class DecodeError extends CommonBase {
16         private DecodeError(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.DecodeError_free(ptr); }
21         }
22         static DecodeError constr_from_ptr(long ptr) {
23                 bindings.LDKDecodeError raw_val = bindings.LDKDecodeError_ref_from_ptr(ptr);
24                 if (raw_val.getClass() == bindings.LDKDecodeError.UnknownVersion.class) {
25                         return new UnknownVersion(ptr, (bindings.LDKDecodeError.UnknownVersion)raw_val);
26                 }
27                 if (raw_val.getClass() == bindings.LDKDecodeError.UnknownRequiredFeature.class) {
28                         return new UnknownRequiredFeature(ptr, (bindings.LDKDecodeError.UnknownRequiredFeature)raw_val);
29                 }
30                 if (raw_val.getClass() == bindings.LDKDecodeError.InvalidValue.class) {
31                         return new InvalidValue(ptr, (bindings.LDKDecodeError.InvalidValue)raw_val);
32                 }
33                 if (raw_val.getClass() == bindings.LDKDecodeError.ShortRead.class) {
34                         return new ShortRead(ptr, (bindings.LDKDecodeError.ShortRead)raw_val);
35                 }
36                 if (raw_val.getClass() == bindings.LDKDecodeError.BadLengthDescriptor.class) {
37                         return new BadLengthDescriptor(ptr, (bindings.LDKDecodeError.BadLengthDescriptor)raw_val);
38                 }
39                 if (raw_val.getClass() == bindings.LDKDecodeError.Io.class) {
40                         return new Io(ptr, (bindings.LDKDecodeError.Io)raw_val);
41                 }
42                 if (raw_val.getClass() == bindings.LDKDecodeError.UnsupportedCompression.class) {
43                         return new UnsupportedCompression(ptr, (bindings.LDKDecodeError.UnsupportedCompression)raw_val);
44                 }
45                 if (raw_val.getClass() == bindings.LDKDecodeError.DangerousValue.class) {
46                         return new DangerousValue(ptr, (bindings.LDKDecodeError.DangerousValue)raw_val);
47                 }
48                 assert false; return null; // Unreachable without extending the (internal) bindings interface
49         }
50
51         /**
52          * A version byte specified something we don't know how to handle.
53          * 
54          * Includes unknown realm byte in an onion hop data packet.
55          */
56         public final static class UnknownVersion extends DecodeError {
57                 private UnknownVersion(long ptr, bindings.LDKDecodeError.UnknownVersion obj) {
58                         super(null, ptr);
59                 }
60         }
61         /**
62          * Unknown feature mandating we fail to parse message (e.g., TLV with an even, unknown type)
63          */
64         public final static class UnknownRequiredFeature extends DecodeError {
65                 private UnknownRequiredFeature(long ptr, bindings.LDKDecodeError.UnknownRequiredFeature obj) {
66                         super(null, ptr);
67                 }
68         }
69         /**
70          * Value was invalid.
71          * 
72          * For example, a byte which was supposed to be a bool was something other than a 0
73          * or 1, a public key/private key/signature was invalid, text wasn't UTF-8, TLV was
74          * syntactically incorrect, etc.
75          */
76         public final static class InvalidValue extends DecodeError {
77                 private InvalidValue(long ptr, bindings.LDKDecodeError.InvalidValue obj) {
78                         super(null, ptr);
79                 }
80         }
81         /**
82          * The buffer to be read was too short.
83          */
84         public final static class ShortRead extends DecodeError {
85                 private ShortRead(long ptr, bindings.LDKDecodeError.ShortRead obj) {
86                         super(null, ptr);
87                 }
88         }
89         /**
90          * A length descriptor in the packet didn't describe the later data correctly.
91          */
92         public final static class BadLengthDescriptor extends DecodeError {
93                 private BadLengthDescriptor(long ptr, bindings.LDKDecodeError.BadLengthDescriptor obj) {
94                         super(null, ptr);
95                 }
96         }
97         /**
98          * Error from [`std::io`].
99          */
100         public final static class Io extends DecodeError {
101                 public final org.ldk.enums.IOError io;
102                 private Io(long ptr, bindings.LDKDecodeError.Io obj) {
103                         super(null, ptr);
104                         this.io = obj.io;
105                 }
106         }
107         /**
108          * The message included zlib-compressed values, which we don't support.
109          */
110         public final static class UnsupportedCompression extends DecodeError {
111                 private UnsupportedCompression(long ptr, bindings.LDKDecodeError.UnsupportedCompression obj) {
112                         super(null, ptr);
113                 }
114         }
115         /**
116          * Value is validly encoded but is dangerous to use.
117          * 
118          * This is used for things like [`ChannelManager`] deserialization where we want to ensure
119          * that we don't use a [`ChannelManager`] which is in out of sync with the [`ChannelMonitor`].
120          * This indicates that there is a critical implementation flaw in the storage implementation
121          * and it's unsafe to continue.
122          * 
123          * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
124          * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
125          */
126         public final static class DangerousValue extends DecodeError {
127                 private DangerousValue(long ptr, bindings.LDKDecodeError.DangerousValue obj) {
128                         super(null, ptr);
129                 }
130         }
131         long clone_ptr() {
132                 long ret = bindings.DecodeError_clone_ptr(this.ptr);
133                 Reference.reachabilityFence(this);
134                 return ret;
135         }
136
137         /**
138          * Creates a copy of the DecodeError
139          */
140         public DecodeError clone() {
141                 long ret = bindings.DecodeError_clone(this.ptr);
142                 Reference.reachabilityFence(this);
143                 if (ret >= 0 && ret <= 4096) { return null; }
144                 org.ldk.structs.DecodeError ret_hu_conv = org.ldk.structs.DecodeError.constr_from_ptr(ret);
145                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
146                 return ret_hu_conv;
147         }
148
149         /**
150          * Utility method to constructs a new UnknownVersion-variant DecodeError
151          */
152         public static DecodeError unknown_version() {
153                 long ret = bindings.DecodeError_unknown_version();
154                 if (ret >= 0 && ret <= 4096) { return null; }
155                 org.ldk.structs.DecodeError ret_hu_conv = org.ldk.structs.DecodeError.constr_from_ptr(ret);
156                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
157                 return ret_hu_conv;
158         }
159
160         /**
161          * Utility method to constructs a new UnknownRequiredFeature-variant DecodeError
162          */
163         public static DecodeError unknown_required_feature() {
164                 long ret = bindings.DecodeError_unknown_required_feature();
165                 if (ret >= 0 && ret <= 4096) { return null; }
166                 org.ldk.structs.DecodeError ret_hu_conv = org.ldk.structs.DecodeError.constr_from_ptr(ret);
167                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
168                 return ret_hu_conv;
169         }
170
171         /**
172          * Utility method to constructs a new InvalidValue-variant DecodeError
173          */
174         public static DecodeError invalid_value() {
175                 long ret = bindings.DecodeError_invalid_value();
176                 if (ret >= 0 && ret <= 4096) { return null; }
177                 org.ldk.structs.DecodeError ret_hu_conv = org.ldk.structs.DecodeError.constr_from_ptr(ret);
178                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
179                 return ret_hu_conv;
180         }
181
182         /**
183          * Utility method to constructs a new ShortRead-variant DecodeError
184          */
185         public static DecodeError short_read() {
186                 long ret = bindings.DecodeError_short_read();
187                 if (ret >= 0 && ret <= 4096) { return null; }
188                 org.ldk.structs.DecodeError ret_hu_conv = org.ldk.structs.DecodeError.constr_from_ptr(ret);
189                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
190                 return ret_hu_conv;
191         }
192
193         /**
194          * Utility method to constructs a new BadLengthDescriptor-variant DecodeError
195          */
196         public static DecodeError bad_length_descriptor() {
197                 long ret = bindings.DecodeError_bad_length_descriptor();
198                 if (ret >= 0 && ret <= 4096) { return null; }
199                 org.ldk.structs.DecodeError ret_hu_conv = org.ldk.structs.DecodeError.constr_from_ptr(ret);
200                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
201                 return ret_hu_conv;
202         }
203
204         /**
205          * Utility method to constructs a new Io-variant DecodeError
206          */
207         public static DecodeError io(org.ldk.enums.IOError a) {
208                 long ret = bindings.DecodeError_io(a);
209                 Reference.reachabilityFence(a);
210                 if (ret >= 0 && ret <= 4096) { return null; }
211                 org.ldk.structs.DecodeError ret_hu_conv = org.ldk.structs.DecodeError.constr_from_ptr(ret);
212                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
213                 return ret_hu_conv;
214         }
215
216         /**
217          * Utility method to constructs a new UnsupportedCompression-variant DecodeError
218          */
219         public static DecodeError unsupported_compression() {
220                 long ret = bindings.DecodeError_unsupported_compression();
221                 if (ret >= 0 && ret <= 4096) { return null; }
222                 org.ldk.structs.DecodeError ret_hu_conv = org.ldk.structs.DecodeError.constr_from_ptr(ret);
223                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
224                 return ret_hu_conv;
225         }
226
227         /**
228          * Utility method to constructs a new DangerousValue-variant DecodeError
229          */
230         public static DecodeError dangerous_value() {
231                 long ret = bindings.DecodeError_dangerous_value();
232                 if (ret >= 0 && ret <= 4096) { return null; }
233                 org.ldk.structs.DecodeError ret_hu_conv = org.ldk.structs.DecodeError.constr_from_ptr(ret);
234                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
235                 return ret_hu_conv;
236         }
237
238         /**
239          * Generates a non-cryptographic 64-bit hash of the DecodeError.
240          */
241         public long hash() {
242                 long ret = bindings.DecodeError_hash(this.ptr);
243                 Reference.reachabilityFence(this);
244                 return ret;
245         }
246
247         @Override public int hashCode() {
248                 return (int)this.hash();
249         }
250         /**
251          * Checks if two DecodeErrors contain equal inner contents.
252          * This ignores pointers and is_owned flags and looks at the values in fields.
253          */
254         public boolean eq(org.ldk.structs.DecodeError b) {
255                 boolean ret = bindings.DecodeError_eq(this.ptr, b.ptr);
256                 Reference.reachabilityFence(this);
257                 Reference.reachabilityFence(b);
258                 return ret;
259         }
260
261         @Override public boolean equals(Object o) {
262                 if (!(o instanceof DecodeError)) return false;
263                 return this.eq((DecodeError)o);
264         }
265 }