69d91e70bdc7a671fbfde9d8cedf841d506c036f
[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                 assert false; return null; // Unreachable without extending the (internal) bindings interface
46         }
47
48         /**
49          * A version byte specified something we don't know how to handle.
50          * Includes unknown realm byte in an OnionHopData packet
51          */
52         public final static class UnknownVersion extends DecodeError {
53                 private UnknownVersion(long ptr, bindings.LDKDecodeError.UnknownVersion obj) {
54                         super(null, ptr);
55                 }
56         }
57         /**
58          * Unknown feature mandating we fail to parse message (eg TLV with an even, unknown type)
59          */
60         public final static class UnknownRequiredFeature extends DecodeError {
61                 private UnknownRequiredFeature(long ptr, bindings.LDKDecodeError.UnknownRequiredFeature obj) {
62                         super(null, ptr);
63                 }
64         }
65         /**
66          * Value was invalid, eg a byte which was supposed to be a bool was something other than a 0
67          * or 1, a public key/private key/signature was invalid, text wasn't UTF-8, TLV was
68          * syntactically incorrect, etc
69          */
70         public final static class InvalidValue extends DecodeError {
71                 private InvalidValue(long ptr, bindings.LDKDecodeError.InvalidValue obj) {
72                         super(null, ptr);
73                 }
74         }
75         /**
76          * Buffer too short
77          */
78         public final static class ShortRead extends DecodeError {
79                 private ShortRead(long ptr, bindings.LDKDecodeError.ShortRead obj) {
80                         super(null, ptr);
81                 }
82         }
83         /**
84          * A length descriptor in the packet didn't describe the later data correctly
85          */
86         public final static class BadLengthDescriptor extends DecodeError {
87                 private BadLengthDescriptor(long ptr, bindings.LDKDecodeError.BadLengthDescriptor obj) {
88                         super(null, ptr);
89                 }
90         }
91         /**
92          * Error from std::io
93          */
94         public final static class Io extends DecodeError {
95                 public final org.ldk.enums.IOError io;
96                 private Io(long ptr, bindings.LDKDecodeError.Io obj) {
97                         super(null, ptr);
98                         this.io = obj.io;
99                 }
100         }
101         /**
102          * The message included zlib-compressed values, which we don't support.
103          */
104         public final static class UnsupportedCompression extends DecodeError {
105                 private UnsupportedCompression(long ptr, bindings.LDKDecodeError.UnsupportedCompression obj) {
106                         super(null, ptr);
107                 }
108         }
109         long clone_ptr() {
110                 long ret = bindings.DecodeError_clone_ptr(this.ptr);
111                 Reference.reachabilityFence(this);
112                 return ret;
113         }
114
115         /**
116          * Creates a copy of the DecodeError
117          */
118         public DecodeError clone() {
119                 long ret = bindings.DecodeError_clone(this.ptr);
120                 Reference.reachabilityFence(this);
121                 if (ret >= 0 && ret <= 4096) { return null; }
122                 org.ldk.structs.DecodeError ret_hu_conv = org.ldk.structs.DecodeError.constr_from_ptr(ret);
123                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
124                 return ret_hu_conv;
125         }
126
127         /**
128          * Utility method to constructs a new UnknownVersion-variant DecodeError
129          */
130         public static DecodeError unknown_version() {
131                 long ret = bindings.DecodeError_unknown_version();
132                 if (ret >= 0 && ret <= 4096) { return null; }
133                 org.ldk.structs.DecodeError ret_hu_conv = org.ldk.structs.DecodeError.constr_from_ptr(ret);
134                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
135                 return ret_hu_conv;
136         }
137
138         /**
139          * Utility method to constructs a new UnknownRequiredFeature-variant DecodeError
140          */
141         public static DecodeError unknown_required_feature() {
142                 long ret = bindings.DecodeError_unknown_required_feature();
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(ret_hu_conv); };
146                 return ret_hu_conv;
147         }
148
149         /**
150          * Utility method to constructs a new InvalidValue-variant DecodeError
151          */
152         public static DecodeError invalid_value() {
153                 long ret = bindings.DecodeError_invalid_value();
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 ShortRead-variant DecodeError
162          */
163         public static DecodeError short_read() {
164                 long ret = bindings.DecodeError_short_read();
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 BadLengthDescriptor-variant DecodeError
173          */
174         public static DecodeError bad_length_descriptor() {
175                 long ret = bindings.DecodeError_bad_length_descriptor();
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 Io-variant DecodeError
184          */
185         public static DecodeError io(org.ldk.enums.IOError a) {
186                 long ret = bindings.DecodeError_io(a);
187                 Reference.reachabilityFence(a);
188                 if (ret >= 0 && ret <= 4096) { return null; }
189                 org.ldk.structs.DecodeError ret_hu_conv = org.ldk.structs.DecodeError.constr_from_ptr(ret);
190                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
191                 return ret_hu_conv;
192         }
193
194         /**
195          * Utility method to constructs a new UnsupportedCompression-variant DecodeError
196          */
197         public static DecodeError unsupported_compression() {
198                 long ret = bindings.DecodeError_unsupported_compression();
199                 if (ret >= 0 && ret <= 4096) { return null; }
200                 org.ldk.structs.DecodeError ret_hu_conv = org.ldk.structs.DecodeError.constr_from_ptr(ret);
201                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
202                 return ret_hu_conv;
203         }
204
205         /**
206          * Checks if two DecodeErrors contain equal inner contents.
207          * This ignores pointers and is_owned flags and looks at the values in fields.
208          */
209         public boolean eq(DecodeError b) {
210                 boolean ret = bindings.DecodeError_eq(this.ptr, b == null ? 0 : b.ptr);
211                 Reference.reachabilityFence(this);
212                 Reference.reachabilityFence(b);
213                 return ret;
214         }
215
216         @Override public boolean equals(Object o) {
217                 if (!(o instanceof DecodeError)) return false;
218                 return this.eq((DecodeError)o);
219         }
220 }