dc9b2d9cd4e63c5936be92f1bb04029004587207
[ldk-java] / c_sharp / src / org / ldk / structs / ErrorMessage.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8
9 /**
10  * An error message to be sent or received from a peer
11  */
12 public class ErrorMessage : CommonBase {
13         internal ErrorMessage(object _dummy, long ptr) : base(ptr) { }
14         ~ErrorMessage() {
15                 if (ptr != 0) { bindings.ErrorMessage_free(ptr); }
16         }
17
18         /**
19          * The channel ID involved in the error.
20          * 
21          * All-0s indicates a general error unrelated to a specific channel, after which all channels
22          * with the sending peer should be closed.
23          */
24         public byte[] get_channel_id() {
25                 byte[] ret = bindings.ErrorMessage_get_channel_id(this.ptr);
26                 GC.KeepAlive(this);
27                 return ret;
28         }
29
30         /**
31          * The channel ID involved in the error.
32          * 
33          * All-0s indicates a general error unrelated to a specific channel, after which all channels
34          * with the sending peer should be closed.
35          */
36         public void set_channel_id(byte[] val) {
37                 bindings.ErrorMessage_set_channel_id(this.ptr, InternalUtils.check_arr_len(val, 32));
38                 GC.KeepAlive(this);
39                 GC.KeepAlive(val);
40         }
41
42         /**
43          * A possibly human-readable error description.
44          * The string should be sanitized before it is used (e.g. emitted to logs or printed to
45          * stdout). Otherwise, a well crafted error message may trigger a security vulnerability in
46          * the terminal emulator or the logging subsystem.
47          */
48         public string get_data() {
49                 string ret = bindings.ErrorMessage_get_data(this.ptr);
50                 GC.KeepAlive(this);
51                 return ret;
52         }
53
54         /**
55          * A possibly human-readable error description.
56          * The string should be sanitized before it is used (e.g. emitted to logs or printed to
57          * stdout). Otherwise, a well crafted error message may trigger a security vulnerability in
58          * the terminal emulator or the logging subsystem.
59          */
60         public void set_data(string val) {
61                 bindings.ErrorMessage_set_data(this.ptr, val);
62                 GC.KeepAlive(this);
63                 GC.KeepAlive(val);
64         }
65
66         /**
67          * Constructs a new ErrorMessage given each field
68          */
69         public static ErrorMessage of(byte[] channel_id_arg, string data_arg) {
70                 long ret = bindings.ErrorMessage_new(InternalUtils.check_arr_len(channel_id_arg, 32), data_arg);
71                 GC.KeepAlive(channel_id_arg);
72                 GC.KeepAlive(data_arg);
73                 if (ret >= 0 && ret <= 4096) { return null; }
74                 org.ldk.structs.ErrorMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ErrorMessage(null, ret); }
75                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
76                 return ret_hu_conv;
77         }
78
79         internal long clone_ptr() {
80                 long ret = bindings.ErrorMessage_clone_ptr(this.ptr);
81                 GC.KeepAlive(this);
82                 return ret;
83         }
84
85         /**
86          * Creates a copy of the ErrorMessage
87          */
88         public ErrorMessage clone() {
89                 long ret = bindings.ErrorMessage_clone(this.ptr);
90                 GC.KeepAlive(this);
91                 if (ret >= 0 && ret <= 4096) { return null; }
92                 org.ldk.structs.ErrorMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ErrorMessage(null, ret); }
93                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
94                 return ret_hu_conv;
95         }
96
97         /**
98          * Checks if two ErrorMessages contain equal inner contents.
99          * This ignores pointers and is_owned flags and looks at the values in fields.
100          * Two objects with NULL inner values will be considered "equal" here.
101          */
102         public bool eq(org.ldk.structs.ErrorMessage b) {
103                 bool ret = bindings.ErrorMessage_eq(this.ptr, b == null ? 0 : b.ptr);
104                 GC.KeepAlive(this);
105                 GC.KeepAlive(b);
106                 if (this != null) { this.ptrs_to.AddLast(b); };
107                 return ret;
108         }
109
110         public override bool Equals(object o) {
111                 if (!(o is ErrorMessage)) return false;
112                 return this.eq((ErrorMessage)o);
113         }
114         /**
115          * Serialize the ErrorMessage object into a byte array which can be read by ErrorMessage_read
116          */
117         public byte[] write() {
118                 byte[] ret = bindings.ErrorMessage_write(this.ptr);
119                 GC.KeepAlive(this);
120                 return ret;
121         }
122
123         /**
124          * Read a ErrorMessage from a byte array, created by ErrorMessage_write
125          */
126         public static Result_ErrorMessageDecodeErrorZ read(byte[] ser) {
127                 long ret = bindings.ErrorMessage_read(ser);
128                 GC.KeepAlive(ser);
129                 if (ret >= 0 && ret <= 4096) { return null; }
130                 Result_ErrorMessageDecodeErrorZ ret_hu_conv = Result_ErrorMessageDecodeErrorZ.constr_from_ptr(ret);
131                 return ret_hu_conv;
132         }
133
134 }
135 } } }