Update auto-updated Java files
[ldk-java] / src / main / java / org / ldk / structs / NodeId.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 the compressed public key of a node
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class NodeId extends CommonBase {
16         NodeId(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.NodeId_free(ptr); }
21         }
22
23         long clone_ptr() {
24                 long ret = bindings.NodeId_clone_ptr(this.ptr);
25                 Reference.reachabilityFence(this);
26                 return ret;
27         }
28
29         /**
30          * Creates a copy of the NodeId
31          */
32         public NodeId clone() {
33                 long ret = bindings.NodeId_clone(this.ptr);
34                 Reference.reachabilityFence(this);
35                 if (ret >= 0 && ret <= 4096) { return null; }
36                 NodeId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new NodeId(null, ret); }
37                 ret_hu_conv.ptrs_to.add(this);
38                 return ret_hu_conv;
39         }
40
41         /**
42          * Create a new NodeId from a public key
43          */
44         public static NodeId from_pubkey(byte[] pubkey) {
45                 long ret = bindings.NodeId_from_pubkey(InternalUtils.check_arr_len(pubkey, 33));
46                 Reference.reachabilityFence(pubkey);
47                 if (ret >= 0 && ret <= 4096) { return null; }
48                 NodeId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new NodeId(null, ret); }
49                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
50                 return ret_hu_conv;
51         }
52
53         /**
54          * Get the public key slice from this NodeId
55          */
56         public byte[] as_slice() {
57                 byte[] ret = bindings.NodeId_as_slice(this.ptr);
58                 Reference.reachabilityFence(this);
59                 return ret;
60         }
61
62         /**
63          * Checks if two NodeIds contain equal inner contents.
64          */
65         public long hash() {
66                 long ret = bindings.NodeId_hash(this.ptr);
67                 Reference.reachabilityFence(this);
68                 return ret;
69         }
70
71         @Override public int hashCode() {
72                 return (int)this.hash();
73         }
74         /**
75          * Serialize the NodeId object into a byte array which can be read by NodeId_read
76          */
77         public byte[] write() {
78                 byte[] ret = bindings.NodeId_write(this.ptr);
79                 Reference.reachabilityFence(this);
80                 return ret;
81         }
82
83         /**
84          * Read a NodeId from a byte array, created by NodeId_write
85          */
86         public static Result_NodeIdDecodeErrorZ read(byte[] ser) {
87                 long ret = bindings.NodeId_read(ser);
88                 Reference.reachabilityFence(ser);
89                 if (ret >= 0 && ret <= 4096) { return null; }
90                 Result_NodeIdDecodeErrorZ ret_hu_conv = Result_NodeIdDecodeErrorZ.constr_from_ptr(ret);
91                 return ret_hu_conv;
92         }
93
94 }