9199d7fd928eced227e03d7e52b3d6b6e32d3fff
[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 or received from a peer
13  */
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 {
19                 super.finalize();
20                 if (ptr != 0) { bindings.ErrorMessage_free(ptr); }
21         }
22
23         /**
24          * The channel ID involved in the error
25          */
26         public byte[] get_channel_id() {
27                 byte[] ret = bindings.ErrorMessage_get_channel_id(this.ptr);
28                 Reference.reachabilityFence(this);
29                 return ret;
30         }
31
32         /**
33          * The channel ID involved in the error
34          */
35         public void set_channel_id(byte[] val) {
36                 bindings.ErrorMessage_set_channel_id(this.ptr, InternalUtils.check_arr_len(val, 32));
37                 Reference.reachabilityFence(this);
38                 Reference.reachabilityFence(val);
39         }
40
41         /**
42          * A possibly human-readable error description.
43          * The string should be sanitized before it is used (e.g. emitted to logs
44          * or printed to stdout).  Otherwise, a well crafted error message may trigger a security
45          * vulnerability in the terminal emulator or the logging subsystem.
46          */
47         public String get_data() {
48                 String ret = bindings.ErrorMessage_get_data(this.ptr);
49                 Reference.reachabilityFence(this);
50                 return ret;
51         }
52
53         /**
54          * A possibly human-readable error description.
55          * The string should be sanitized before it is used (e.g. emitted to logs
56          * or printed to stdout).  Otherwise, a well crafted error message may trigger a security
57          * vulnerability in the terminal emulator or the logging subsystem.
58          */
59         public void set_data(java.lang.String val) {
60                 bindings.ErrorMessage_set_data(this.ptr, val);
61                 Reference.reachabilityFence(this);
62                 Reference.reachabilityFence(val);
63         }
64
65         /**
66          * Constructs a new ErrorMessage given each field
67          */
68         public static ErrorMessage of(byte[] channel_id_arg, java.lang.String data_arg) {
69                 long ret = bindings.ErrorMessage_new(InternalUtils.check_arr_len(channel_id_arg, 32), data_arg);
70                 Reference.reachabilityFence(channel_id_arg);
71                 Reference.reachabilityFence(data_arg);
72                 if (ret >= 0 && ret <= 4096) { return null; }
73                 ErrorMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ErrorMessage(null, ret); }
74                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
75                 return ret_hu_conv;
76         }
77
78         long clone_ptr() {
79                 long ret = bindings.ErrorMessage_clone_ptr(this.ptr);
80                 Reference.reachabilityFence(this);
81                 return ret;
82         }
83
84         /**
85          * Creates a copy of the ErrorMessage
86          */
87         public ErrorMessage clone() {
88                 long ret = bindings.ErrorMessage_clone(this.ptr);
89                 Reference.reachabilityFence(this);
90                 if (ret >= 0 && ret <= 4096) { return null; }
91                 ErrorMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ErrorMessage(null, ret); }
92                 ret_hu_conv.ptrs_to.add(this);
93                 return ret_hu_conv;
94         }
95
96         /**
97          * Serialize the ErrorMessage object into a byte array which can be read by ErrorMessage_read
98          */
99         public byte[] write() {
100                 byte[] ret = bindings.ErrorMessage_write(this.ptr);
101                 Reference.reachabilityFence(this);
102                 return ret;
103         }
104
105         /**
106          * Read a ErrorMessage from a byte array, created by ErrorMessage_write
107          */
108         public static Result_ErrorMessageDecodeErrorZ read(byte[] ser) {
109                 long ret = bindings.ErrorMessage_read(ser);
110                 Reference.reachabilityFence(ser);
111                 if (ret >= 0 && ret <= 4096) { return null; }
112                 Result_ErrorMessageDecodeErrorZ ret_hu_conv = Result_ErrorMessageDecodeErrorZ.constr_from_ptr(ret);
113                 return ret_hu_conv;
114         }
115
116 }