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