1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * An error in decoding a message or struct.
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 {
20 if (ptr != 0) { bindings.DecodeError_free(ptr); }
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);
27 if (raw_val.getClass() == bindings.LDKDecodeError.UnknownRequiredFeature.class) {
28 return new UnknownRequiredFeature(ptr, (bindings.LDKDecodeError.UnknownRequiredFeature)raw_val);
30 if (raw_val.getClass() == bindings.LDKDecodeError.InvalidValue.class) {
31 return new InvalidValue(ptr, (bindings.LDKDecodeError.InvalidValue)raw_val);
33 if (raw_val.getClass() == bindings.LDKDecodeError.ShortRead.class) {
34 return new ShortRead(ptr, (bindings.LDKDecodeError.ShortRead)raw_val);
36 if (raw_val.getClass() == bindings.LDKDecodeError.BadLengthDescriptor.class) {
37 return new BadLengthDescriptor(ptr, (bindings.LDKDecodeError.BadLengthDescriptor)raw_val);
39 if (raw_val.getClass() == bindings.LDKDecodeError.Io.class) {
40 return new Io(ptr, (bindings.LDKDecodeError.Io)raw_val);
42 if (raw_val.getClass() == bindings.LDKDecodeError.UnsupportedCompression.class) {
43 return new UnsupportedCompression(ptr, (bindings.LDKDecodeError.UnsupportedCompression)raw_val);
45 assert false; return null; // Unreachable without extending the (internal) bindings interface
49 * A version byte specified something we don't know how to handle.
51 * Includes unknown realm byte in an onion hop data packet.
53 public final static class UnknownVersion extends DecodeError {
54 private UnknownVersion(long ptr, bindings.LDKDecodeError.UnknownVersion obj) {
59 * Unknown feature mandating we fail to parse message (e.g., TLV with an even, unknown type)
61 public final static class UnknownRequiredFeature extends DecodeError {
62 private UnknownRequiredFeature(long ptr, bindings.LDKDecodeError.UnknownRequiredFeature obj) {
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.
73 public final static class InvalidValue extends DecodeError {
74 private InvalidValue(long ptr, bindings.LDKDecodeError.InvalidValue obj) {
79 * The buffer to be read was too short.
81 public final static class ShortRead extends DecodeError {
82 private ShortRead(long ptr, bindings.LDKDecodeError.ShortRead obj) {
87 * A length descriptor in the packet didn't describe the later data correctly.
89 public final static class BadLengthDescriptor extends DecodeError {
90 private BadLengthDescriptor(long ptr, bindings.LDKDecodeError.BadLengthDescriptor obj) {
95 * Error from [`std::io`].
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) {
105 * The message included zlib-compressed values, which we don't support.
107 public final static class UnsupportedCompression extends DecodeError {
108 private UnsupportedCompression(long ptr, bindings.LDKDecodeError.UnsupportedCompression obj) {
113 long ret = bindings.DecodeError_clone_ptr(this.ptr);
114 Reference.reachabilityFence(this);
119 * Creates a copy of the DecodeError
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); };
131 * Utility method to constructs a new UnknownVersion-variant DecodeError
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); };
142 * Utility method to constructs a new UnknownRequiredFeature-variant DecodeError
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); };
153 * Utility method to constructs a new InvalidValue-variant DecodeError
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); };
164 * Utility method to constructs a new ShortRead-variant DecodeError
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); };
175 * Utility method to constructs a new BadLengthDescriptor-variant DecodeError
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); };
186 * Utility method to constructs a new Io-variant DecodeError
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); };
198 * Utility method to constructs a new UnsupportedCompression-variant DecodeError
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); };
209 * Checks if two DecodeErrors contain equal inner contents.
210 * This ignores pointers and is_owned flags and looks at the values in fields.
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);
219 @Override public boolean equals(Object o) {
220 if (!(o instanceof DecodeError)) return false;
221 return this.eq((DecodeError)o);