X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FHostname.java;h=c8344ae0a17ca4908eaeedcbe4c03ae8ff48992f;hb=5d91c4ade4b5f736d100428ccf84709ad29f971d;hp=fdf18a3a3f2758703f878dd9f2bd21f483c61a20;hpb=330ca992be304d0eac79bd59b411980dff294b03;p=ldk-java diff --git a/src/main/java/org/ldk/structs/Hostname.java b/src/main/java/org/ldk/structs/Hostname.java index fdf18a3a..c8344ae0 100644 --- a/src/main/java/org/ldk/structs/Hostname.java +++ b/src/main/java/org/ldk/structs/Hostname.java @@ -13,7 +13,9 @@ import javax.annotation.Nullable; * Only the character set and length will be validated. * The character set consists of ASCII alphanumeric characters, hyphens, and periods. * Its length is guaranteed to be representable by a single byte. - * This serialization is used by BOLT 7 hostnames. + * This serialization is used by [`BOLT 7`] hostnames. + * + * [`BOLT 7`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md */ @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class Hostname extends CommonBase { @@ -42,13 +44,25 @@ public class Hostname extends CommonBase { return ret_hu_conv; } + /** + * Generates a non-cryptographic 64-bit hash of the Hostname. + */ + public long hash() { + long ret = bindings.Hostname_hash(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + @Override public int hashCode() { + return (int)this.hash(); + } /** * Checks if two Hostnames contain equal inner contents. * This ignores pointers and is_owned flags and looks at the values in fields. * Two objects with NULL inner values will be considered "equal" here. */ public boolean eq(org.ldk.structs.Hostname b) { - boolean ret = bindings.Hostname_eq(this.ptr, b == null ? 0 : b.ptr); + boolean ret = bindings.Hostname_eq(this.ptr, b.ptr); Reference.reachabilityFence(this); Reference.reachabilityFence(b); if (this != null) { this.ptrs_to.add(b); }; @@ -68,4 +82,33 @@ public class Hostname extends CommonBase { return ret; } + /** + * Get the string representation of a Hostname object + */ + public String to_str() { + String ret = bindings.Hostname_to_str(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + /** + * Serialize the Hostname object into a byte array which can be read by Hostname_read + */ + public byte[] write() { + byte[] ret = bindings.Hostname_write(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + /** + * Read a Hostname from a byte array, created by Hostname_write + */ + public static Result_HostnameDecodeErrorZ read(byte[] ser) { + long ret = bindings.Hostname_read(ser); + Reference.reachabilityFence(ser); + if (ret >= 0 && ret <= 4096) { return null; } + Result_HostnameDecodeErrorZ ret_hu_conv = Result_HostnameDecodeErrorZ.constr_from_ptr(ret); + return ret_hu_conv; + } + }