955d60b1ba5a756346ef1fb89d37b58453b1e42c
[ldk-java] / c_sharp / src / org / ldk / structs / WarningMessage.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  * A [`warning`] message to be sent to or received from a peer.
11  * 
12  * [`warning`]: https://github.com/lightning/bolts/blob/master/01-messaging.md#the-error-and-warning-messages
13  */
14 public class WarningMessage : CommonBase {
15         internal WarningMessage(object _dummy, long ptr) : base(ptr) { }
16         ~WarningMessage() {
17                 if (ptr != 0) { bindings.WarningMessage_free(ptr); }
18         }
19
20         /**
21          * The channel ID involved in the warning.
22          * 
23          * All-0s indicates a warning unrelated to a specific channel.
24          */
25         public byte[] get_channel_id() {
26                 byte[] ret = bindings.WarningMessage_get_channel_id(this.ptr);
27                 GC.KeepAlive(this);
28                 return ret;
29         }
30
31         /**
32          * The channel ID involved in the warning.
33          * 
34          * All-0s indicates a warning unrelated to a specific channel.
35          */
36         public void set_channel_id(byte[] val) {
37                 bindings.WarningMessage_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 warning description.
44          * 
45          * The string should be sanitized before it is used (e.g. emitted to logs or printed to
46          * stdout). Otherwise, a well crafted error message may trigger a security vulnerability in
47          * the terminal emulator or the logging subsystem.
48          */
49         public string get_data() {
50                 string ret = bindings.WarningMessage_get_data(this.ptr);
51                 GC.KeepAlive(this);
52                 return ret;
53         }
54
55         /**
56          * A possibly human-readable warning description.
57          * 
58          * The string should be sanitized before it is used (e.g. emitted to logs or printed to
59          * stdout). Otherwise, a well crafted error message may trigger a security vulnerability in
60          * the terminal emulator or the logging subsystem.
61          */
62         public void set_data(string val) {
63                 bindings.WarningMessage_set_data(this.ptr, val);
64                 GC.KeepAlive(this);
65                 GC.KeepAlive(val);
66         }
67
68         /**
69          * Constructs a new WarningMessage given each field
70          */
71         public static WarningMessage of(byte[] channel_id_arg, string data_arg) {
72                 long ret = bindings.WarningMessage_new(InternalUtils.check_arr_len(channel_id_arg, 32), data_arg);
73                 GC.KeepAlive(channel_id_arg);
74                 GC.KeepAlive(data_arg);
75                 if (ret >= 0 && ret <= 4096) { return null; }
76                 org.ldk.structs.WarningMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.WarningMessage(null, ret); }
77                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
78                 return ret_hu_conv;
79         }
80
81         internal long clone_ptr() {
82                 long ret = bindings.WarningMessage_clone_ptr(this.ptr);
83                 GC.KeepAlive(this);
84                 return ret;
85         }
86
87         /**
88          * Creates a copy of the WarningMessage
89          */
90         public WarningMessage clone() {
91                 long ret = bindings.WarningMessage_clone(this.ptr);
92                 GC.KeepAlive(this);
93                 if (ret >= 0 && ret <= 4096) { return null; }
94                 org.ldk.structs.WarningMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.WarningMessage(null, ret); }
95                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
96                 return ret_hu_conv;
97         }
98
99         /**
100          * Checks if two WarningMessages contain equal inner contents.
101          * This ignores pointers and is_owned flags and looks at the values in fields.
102          * Two objects with NULL inner values will be considered "equal" here.
103          */
104         public bool eq(org.ldk.structs.WarningMessage b) {
105                 bool ret = bindings.WarningMessage_eq(this.ptr, b == null ? 0 : b.ptr);
106                 GC.KeepAlive(this);
107                 GC.KeepAlive(b);
108                 if (this != null) { this.ptrs_to.AddLast(b); };
109                 return ret;
110         }
111
112         public override bool Equals(object o) {
113                 if (!(o is WarningMessage)) return false;
114                 return this.eq((WarningMessage)o);
115         }
116         /**
117          * Serialize the WarningMessage object into a byte array which can be read by WarningMessage_read
118          */
119         public byte[] write() {
120                 byte[] ret = bindings.WarningMessage_write(this.ptr);
121                 GC.KeepAlive(this);
122                 return ret;
123         }
124
125         /**
126          * Read a WarningMessage from a byte array, created by WarningMessage_write
127          */
128         public static Result_WarningMessageDecodeErrorZ read(byte[] ser) {
129                 long ret = bindings.WarningMessage_read(ser);
130                 GC.KeepAlive(ser);
131                 if (ret >= 0 && ret <= 4096) { return null; }
132                 Result_WarningMessageDecodeErrorZ ret_hu_conv = Result_WarningMessageDecodeErrorZ.constr_from_ptr(ret);
133                 return ret_hu_conv;
134         }
135
136 }
137 } } }