6bcc9e22a2167a707bf3e816bf98a39f5a8e060e
[ldk-java] / src / main / java / org / ldk / structs / ErrorMessage.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`] message to be sent to or received from a peer.
13  * 
14  * [`error`]: https://github.com/lightning/bolts/blob/master/01-messaging.md#the-error-and-warning-messages
15  */
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class ErrorMessage extends CommonBase {
18         ErrorMessage(Object _dummy, long ptr) { super(ptr); }
19         @Override @SuppressWarnings("deprecation")
20         protected void finalize() throws Throwable {
21                 super.finalize();
22                 if (ptr != 0) { bindings.ErrorMessage_free(ptr); }
23         }
24
25         /**
26          * The channel ID involved in the error.
27          * 
28          * All-0s indicates a general error unrelated to a specific channel, after which all channels
29          * with the sending peer should be closed.
30          */
31         public byte[] get_channel_id() {
32                 byte[] ret = bindings.ErrorMessage_get_channel_id(this.ptr);
33                 Reference.reachabilityFence(this);
34                 return ret;
35         }
36
37         /**
38          * The channel ID involved in the error.
39          * 
40          * All-0s indicates a general error unrelated to a specific channel, after which all channels
41          * with the sending peer should be closed.
42          */
43         public void set_channel_id(byte[] val) {
44                 bindings.ErrorMessage_set_channel_id(this.ptr, InternalUtils.check_arr_len(val, 32));
45                 Reference.reachabilityFence(this);
46                 Reference.reachabilityFence(val);
47         }
48
49         /**
50          * A possibly human-readable error description.
51          * 
52          * The string should be sanitized before it is used (e.g., emitted to logs or printed to
53          * `stdout`). Otherwise, a well crafted error message may trigger a security vulnerability in
54          * the terminal emulator or the logging subsystem.
55          */
56         public String get_data() {
57                 String ret = bindings.ErrorMessage_get_data(this.ptr);
58                 Reference.reachabilityFence(this);
59                 return ret;
60         }
61
62         /**
63          * A possibly human-readable error description.
64          * 
65          * The string should be sanitized before it is used (e.g., emitted to logs or printed to
66          * `stdout`). Otherwise, a well crafted error message may trigger a security vulnerability in
67          * the terminal emulator or the logging subsystem.
68          */
69         public void set_data(java.lang.String val) {
70                 bindings.ErrorMessage_set_data(this.ptr, val);
71                 Reference.reachabilityFence(this);
72                 Reference.reachabilityFence(val);
73         }
74
75         /**
76          * Constructs a new ErrorMessage given each field
77          */
78         public static ErrorMessage of(byte[] channel_id_arg, java.lang.String data_arg) {
79                 long ret = bindings.ErrorMessage_new(InternalUtils.check_arr_len(channel_id_arg, 32), data_arg);
80                 Reference.reachabilityFence(channel_id_arg);
81                 Reference.reachabilityFence(data_arg);
82                 if (ret >= 0 && ret <= 4096) { return null; }
83                 org.ldk.structs.ErrorMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ErrorMessage(null, ret); }
84                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
85                 return ret_hu_conv;
86         }
87
88         long clone_ptr() {
89                 long ret = bindings.ErrorMessage_clone_ptr(this.ptr);
90                 Reference.reachabilityFence(this);
91                 return ret;
92         }
93
94         /**
95          * Creates a copy of the ErrorMessage
96          */
97         public ErrorMessage clone() {
98                 long ret = bindings.ErrorMessage_clone(this.ptr);
99                 Reference.reachabilityFence(this);
100                 if (ret >= 0 && ret <= 4096) { return null; }
101                 org.ldk.structs.ErrorMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ErrorMessage(null, ret); }
102                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
103                 return ret_hu_conv;
104         }
105
106         /**
107          * Checks if two ErrorMessages contain equal inner contents.
108          * This ignores pointers and is_owned flags and looks at the values in fields.
109          * Two objects with NULL inner values will be considered "equal" here.
110          */
111         public boolean eq(org.ldk.structs.ErrorMessage b) {
112                 boolean ret = bindings.ErrorMessage_eq(this.ptr, b == null ? 0 : b.ptr);
113                 Reference.reachabilityFence(this);
114                 Reference.reachabilityFence(b);
115                 if (this != null) { this.ptrs_to.add(b); };
116                 return ret;
117         }
118
119         @Override public boolean equals(Object o) {
120                 if (!(o instanceof ErrorMessage)) return false;
121                 return this.eq((ErrorMessage)o);
122         }
123         /**
124          * Serialize the ErrorMessage object into a byte array which can be read by ErrorMessage_read
125          */
126         public byte[] write() {
127                 byte[] ret = bindings.ErrorMessage_write(this.ptr);
128                 Reference.reachabilityFence(this);
129                 return ret;
130         }
131
132         /**
133          * Read a ErrorMessage from a byte array, created by ErrorMessage_write
134          */
135         public static Result_ErrorMessageDecodeErrorZ read(byte[] ser) {
136                 long ret = bindings.ErrorMessage_read(ser);
137                 Reference.reachabilityFence(ser);
138                 if (ret >= 0 && ret <= 4096) { return null; }
139                 Result_ErrorMessageDecodeErrorZ ret_hu_conv = Result_ErrorMessageDecodeErrorZ.constr_from_ptr(ret);
140                 return ret_hu_conv;
141         }
142
143 }