1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
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.
18 * [`BOLT 7`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md
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 {
26 if (ptr != 0) { bindings.Hostname_free(ptr); }
30 long ret = bindings.Hostname_clone_ptr(this.ptr);
31 Reference.reachabilityFence(this);
36 * Creates a copy of the Hostname
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); };
48 * Generates a non-cryptographic 64-bit hash of the Hostname.
51 long ret = bindings.Hostname_hash(this.ptr);
52 Reference.reachabilityFence(this);
56 @Override public int hashCode() {
57 return (int)this.hash();
60 * Checks if two Hostnames contain equal inner contents.
61 * This ignores pointers and is_owned flags and looks at the values in fields.
62 * Two objects with NULL inner values will be considered "equal" here.
64 public boolean eq(org.ldk.structs.Hostname b) {
65 boolean ret = bindings.Hostname_eq(this.ptr, b.ptr);
66 Reference.reachabilityFence(this);
67 Reference.reachabilityFence(b);
68 if (this != null) { this.ptrs_to.add(b); };
72 @Override public boolean equals(Object o) {
73 if (!(o instanceof Hostname)) return false;
74 return this.eq((Hostname)o);
77 * Returns the length of the hostname.
80 byte ret = bindings.Hostname_len(this.ptr);
81 Reference.reachabilityFence(this);
86 * Get the string representation of a Hostname object
88 public String to_str() {
89 String ret = bindings.Hostname_to_str(this.ptr);
90 Reference.reachabilityFence(this);
95 * Serialize the Hostname object into a byte array which can be read by Hostname_read
97 public byte[] write() {
98 byte[] ret = bindings.Hostname_write(this.ptr);
99 Reference.reachabilityFence(this);
104 * Read a Hostname from a byte array, created by Hostname_write
106 public static Result_HostnameDecodeErrorZ read(byte[] ser) {
107 long ret = bindings.Hostname_read(ser);
108 Reference.reachabilityFence(ser);
109 if (ret >= 0 && ret <= 4096) { return null; }
110 Result_HostnameDecodeErrorZ ret_hu_conv = Result_HostnameDecodeErrorZ.constr_from_ptr(ret);