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