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 * A [`ping`] message to be sent to or received from a peer.
14 * [`ping`]: https://github.com/lightning/bolts/blob/master/01-messaging.md#the-ping-and-pong-messages
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class Ping extends CommonBase {
18 Ping(Object _dummy, long ptr) { super(ptr); }
19 @Override @SuppressWarnings("deprecation")
20 protected void finalize() throws Throwable {
22 if (ptr != 0) { bindings.Ping_free(ptr); }
26 * The desired response length.
28 public short get_ponglen() {
29 short ret = bindings.Ping_get_ponglen(this.ptr);
30 Reference.reachabilityFence(this);
35 * The desired response length.
37 public void set_ponglen(short val) {
38 bindings.Ping_set_ponglen(this.ptr, val);
39 Reference.reachabilityFence(this);
40 Reference.reachabilityFence(val);
44 * The ping packet size.
46 * This field is not sent on the wire. byteslen zeros are sent.
48 public short get_byteslen() {
49 short ret = bindings.Ping_get_byteslen(this.ptr);
50 Reference.reachabilityFence(this);
55 * The ping packet size.
57 * This field is not sent on the wire. byteslen zeros are sent.
59 public void set_byteslen(short val) {
60 bindings.Ping_set_byteslen(this.ptr, val);
61 Reference.reachabilityFence(this);
62 Reference.reachabilityFence(val);
66 * Constructs a new Ping given each field
68 public static Ping of(short ponglen_arg, short byteslen_arg) {
69 long ret = bindings.Ping_new(ponglen_arg, byteslen_arg);
70 Reference.reachabilityFence(ponglen_arg);
71 Reference.reachabilityFence(byteslen_arg);
72 if (ret >= 0 && ret <= 4096) { return null; }
73 org.ldk.structs.Ping ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Ping(null, ret); }
74 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
79 long ret = bindings.Ping_clone_ptr(this.ptr);
80 Reference.reachabilityFence(this);
85 * Creates a copy of the Ping
88 long ret = bindings.Ping_clone(this.ptr);
89 Reference.reachabilityFence(this);
90 if (ret >= 0 && ret <= 4096) { return null; }
91 org.ldk.structs.Ping ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Ping(null, ret); }
92 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
97 * Generates a non-cryptographic 64-bit hash of the Ping.
100 long ret = bindings.Ping_hash(this.ptr);
101 Reference.reachabilityFence(this);
105 @Override public int hashCode() {
106 return (int)this.hash();
109 * Checks if two Pings contain equal inner contents.
110 * This ignores pointers and is_owned flags and looks at the values in fields.
111 * Two objects with NULL inner values will be considered "equal" here.
113 public boolean eq(org.ldk.structs.Ping b) {
114 boolean ret = bindings.Ping_eq(this.ptr, b.ptr);
115 Reference.reachabilityFence(this);
116 Reference.reachabilityFence(b);
117 if (this != null) { this.ptrs_to.add(b); };
121 @Override public boolean equals(Object o) {
122 if (!(o instanceof Ping)) return false;
123 return this.eq((Ping)o);
126 * Serialize the Ping object into a byte array which can be read by Ping_read
128 public byte[] write() {
129 byte[] ret = bindings.Ping_write(this.ptr);
130 Reference.reachabilityFence(this);
135 * Read a Ping from a byte array, created by Ping_write
137 public static Result_PingDecodeErrorZ read(byte[] ser) {
138 long ret = bindings.Ping_read(ser);
139 Reference.reachabilityFence(ser);
140 if (ret >= 0 && ret <= 4096) { return null; }
141 Result_PingDecodeErrorZ ret_hu_conv = Result_PingDecodeErrorZ.constr_from_ptr(ret);