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