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 if (raw_val.getClass() == bindings.LDKDecodeError.DangerousValue.class) {
46 return new DangerousValue(ptr, (bindings.LDKDecodeError.DangerousValue)raw_val);
48 assert false; return null; // Unreachable without extending the (internal) bindings interface
52 * A version byte specified something we don't know how to handle.
54 * Includes unknown realm byte in an onion hop data packet.
56 public final static class UnknownVersion extends DecodeError {
57 private UnknownVersion(long ptr, bindings.LDKDecodeError.UnknownVersion obj) {
62 * Unknown feature mandating we fail to parse message (e.g., TLV with an even, unknown type)
64 public final static class UnknownRequiredFeature extends DecodeError {
65 private UnknownRequiredFeature(long ptr, bindings.LDKDecodeError.UnknownRequiredFeature obj) {
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.
76 public final static class InvalidValue extends DecodeError {
77 private InvalidValue(long ptr, bindings.LDKDecodeError.InvalidValue obj) {
82 * The buffer to be read was too short.
84 public final static class ShortRead extends DecodeError {
85 private ShortRead(long ptr, bindings.LDKDecodeError.ShortRead obj) {
90 * A length descriptor in the packet didn't describe the later data correctly.
92 public final static class BadLengthDescriptor extends DecodeError {
93 private BadLengthDescriptor(long ptr, bindings.LDKDecodeError.BadLengthDescriptor obj) {
98 * Error from [`std::io`].
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) {
108 * The message included zlib-compressed values, which we don't support.
110 public final static class UnsupportedCompression extends DecodeError {
111 private UnsupportedCompression(long ptr, bindings.LDKDecodeError.UnsupportedCompression obj) {
116 * Value is validly encoded but is dangerous to use.
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.
123 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
124 * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
126 public final static class DangerousValue extends DecodeError {
127 private DangerousValue(long ptr, bindings.LDKDecodeError.DangerousValue obj) {
132 long ret = bindings.DecodeError_clone_ptr(this.ptr);
133 Reference.reachabilityFence(this);
138 * Creates a copy of the DecodeError
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); };
150 * Utility method to constructs a new UnknownVersion-variant DecodeError
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); };
161 * Utility method to constructs a new UnknownRequiredFeature-variant DecodeError
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); };
172 * Utility method to constructs a new InvalidValue-variant DecodeError
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); };
183 * Utility method to constructs a new ShortRead-variant DecodeError
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); };
194 * Utility method to constructs a new BadLengthDescriptor-variant DecodeError
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); };
205 * Utility method to constructs a new Io-variant DecodeError
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); };
217 * Utility method to constructs a new UnsupportedCompression-variant DecodeError
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); };
228 * Utility method to constructs a new DangerousValue-variant DecodeError
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); };
239 * Generates a non-cryptographic 64-bit hash of the DecodeError.
242 long ret = bindings.DecodeError_hash(this.ptr);
243 Reference.reachabilityFence(this);
247 @Override public int hashCode() {
248 return (int)this.hash();
251 * Checks if two DecodeErrors contain equal inner contents.
252 * This ignores pointers and is_owned flags and looks at the values in fields.
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);
261 @Override public boolean equals(Object o) {
262 if (!(o instanceof DecodeError)) return false;
263 return this.eq((DecodeError)o);