2e3e071f753e4132398853d1e35fdda5628e77a0
[ldk-java] / c_sharp / src / org / ldk / structs / Hostname.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  * Represents a hostname for serialization purposes.
11  * Only the character set and length will be validated.
12  * The character set consists of ASCII alphanumeric characters, hyphens, and periods.
13  * Its length is guaranteed to be representable by a single byte.
14  * This serialization is used by [`BOLT 7`] hostnames.
15  * 
16  * [`BOLT 7`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md
17  */
18 public class Hostname : CommonBase {
19         internal Hostname(object _dummy, long ptr) : base(ptr) { }
20         ~Hostname() {
21                 if (ptr != 0) { bindings.Hostname_free(ptr); }
22         }
23
24         internal long clone_ptr() {
25                 long ret = bindings.Hostname_clone_ptr(this.ptr);
26                 GC.KeepAlive(this);
27                 return ret;
28         }
29
30         /**
31          * Creates a copy of the Hostname
32          */
33         public Hostname clone() {
34                 long ret = bindings.Hostname_clone(this.ptr);
35                 GC.KeepAlive(this);
36                 if (ret >= 0 && ret <= 4096) { return null; }
37                 org.ldk.structs.Hostname ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Hostname(null, ret); }
38                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
39                 return ret_hu_conv;
40         }
41
42         /**
43          * Checks if two Hostnames contain equal inner contents.
44          * This ignores pointers and is_owned flags and looks at the values in fields.
45          * Two objects with NULL inner values will be considered "equal" here.
46          */
47         public bool eq(org.ldk.structs.Hostname b) {
48                 bool ret = bindings.Hostname_eq(this.ptr, b == null ? 0 : b.ptr);
49                 GC.KeepAlive(this);
50                 GC.KeepAlive(b);
51                 if (this != null) { this.ptrs_to.AddLast(b); };
52                 return ret;
53         }
54
55         public override bool Equals(object o) {
56                 if (!(o is Hostname)) return false;
57                 return this.eq((Hostname)o);
58         }
59         /**
60          * Returns the length of the hostname.
61          */
62         public byte len() {
63                 byte ret = bindings.Hostname_len(this.ptr);
64                 GC.KeepAlive(this);
65                 return ret;
66         }
67
68         /**
69          * Serialize the Hostname object into a byte array which can be read by Hostname_read
70          */
71         public byte[] write() {
72                 long ret = bindings.Hostname_write(this.ptr);
73                 GC.KeepAlive(this);
74                 if (ret >= 0 && ret <= 4096) { return null; }
75                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
76                 return ret_conv;
77         }
78
79         /**
80          * Read a Hostname from a byte array, created by Hostname_write
81          */
82         public static Result_HostnameDecodeErrorZ read(byte[] ser) {
83                 long ret = bindings.Hostname_read(InternalUtils.encodeUint8Array(ser));
84                 GC.KeepAlive(ser);
85                 if (ret >= 0 && ret <= 4096) { return null; }
86                 Result_HostnameDecodeErrorZ ret_hu_conv = Result_HostnameDecodeErrorZ.constr_from_ptr(ret);
87                 return ret_hu_conv;
88         }
89
90 }
91 } } }