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 message to be sent or received from a peer
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class ErrorMessage extends CommonBase {
16 ErrorMessage(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.ErrorMessage_free(ptr); }
24 * The channel ID involved in the error.
26 * All-0s indicates a general error unrelated to a specific channel, after which all channels
27 * with the sending peer should be closed.
29 public byte[] get_channel_id() {
30 byte[] ret = bindings.ErrorMessage_get_channel_id(this.ptr);
31 Reference.reachabilityFence(this);
36 * The channel ID involved in the error.
38 * All-0s indicates a general error unrelated to a specific channel, after which all channels
39 * with the sending peer should be closed.
41 public void set_channel_id(byte[] val) {
42 bindings.ErrorMessage_set_channel_id(this.ptr, InternalUtils.check_arr_len(val, 32));
43 Reference.reachabilityFence(this);
44 Reference.reachabilityFence(val);
48 * A possibly human-readable error description.
49 * The string should be sanitized before it is used (e.g. emitted to logs or printed to
50 * stdout). Otherwise, a well crafted error message may trigger a security vulnerability in
51 * the terminal emulator or the logging subsystem.
53 public String get_data() {
54 String ret = bindings.ErrorMessage_get_data(this.ptr);
55 Reference.reachabilityFence(this);
60 * A possibly human-readable error description.
61 * The string should be sanitized before it is used (e.g. emitted to logs or printed to
62 * stdout). Otherwise, a well crafted error message may trigger a security vulnerability in
63 * the terminal emulator or the logging subsystem.
65 public void set_data(java.lang.String val) {
66 bindings.ErrorMessage_set_data(this.ptr, val);
67 Reference.reachabilityFence(this);
68 Reference.reachabilityFence(val);
72 * Constructs a new ErrorMessage given each field
74 public static ErrorMessage of(byte[] channel_id_arg, java.lang.String data_arg) {
75 long ret = bindings.ErrorMessage_new(InternalUtils.check_arr_len(channel_id_arg, 32), data_arg);
76 Reference.reachabilityFence(channel_id_arg);
77 Reference.reachabilityFence(data_arg);
78 if (ret >= 0 && ret <= 4096) { return null; }
79 org.ldk.structs.ErrorMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ErrorMessage(null, ret); }
80 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
85 long ret = bindings.ErrorMessage_clone_ptr(this.ptr);
86 Reference.reachabilityFence(this);
91 * Creates a copy of the ErrorMessage
93 public ErrorMessage clone() {
94 long ret = bindings.ErrorMessage_clone(this.ptr);
95 Reference.reachabilityFence(this);
96 if (ret >= 0 && ret <= 4096) { return null; }
97 org.ldk.structs.ErrorMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ErrorMessage(null, ret); }
98 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
103 * Checks if two ErrorMessages contain equal inner contents.
104 * This ignores pointers and is_owned flags and looks at the values in fields.
105 * Two objects with NULL inner values will be considered "equal" here.
107 public boolean eq(ErrorMessage b) {
108 boolean ret = bindings.ErrorMessage_eq(this.ptr, b == null ? 0 : b.ptr);
109 Reference.reachabilityFence(this);
110 Reference.reachabilityFence(b);
111 if (this != null) { this.ptrs_to.add(b); };
115 @Override public boolean equals(Object o) {
116 if (!(o instanceof ErrorMessage)) return false;
117 return this.eq((ErrorMessage)o);
120 * Serialize the ErrorMessage object into a byte array which can be read by ErrorMessage_read
122 public byte[] write() {
123 byte[] ret = bindings.ErrorMessage_write(this.ptr);
124 Reference.reachabilityFence(this);
129 * Read a ErrorMessage from a byte array, created by ErrorMessage_write
131 public static Result_ErrorMessageDecodeErrorZ read(byte[] ser) {
132 long ret = bindings.ErrorMessage_read(ser);
133 Reference.reachabilityFence(ser);
134 if (ret >= 0 && ret <= 4096) { return null; }
135 Result_ErrorMessageDecodeErrorZ ret_hu_conv = Result_ErrorMessageDecodeErrorZ.constr_from_ptr(ret);