5b7823f6191f5a9fa9c592141b4d6fc26e7a59cc
[ldk-java] / src / main / java / org / ldk / structs / Pong.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  * A pong message to be sent or received from a peer
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class Pong extends CommonBase {
16         Pong(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.Pong_free(ptr); }
21         }
22
23         /**
24          * The pong packet size.
25          * This field is not sent on the wire. byteslen zeros are sent.
26          */
27         public short get_byteslen() {
28                 short ret = bindings.Pong_get_byteslen(this.ptr);
29                 Reference.reachabilityFence(this);
30                 return ret;
31         }
32
33         /**
34          * The pong packet size.
35          * This field is not sent on the wire. byteslen zeros are sent.
36          */
37         public void set_byteslen(short val) {
38                 bindings.Pong_set_byteslen(this.ptr, val);
39                 Reference.reachabilityFence(this);
40                 Reference.reachabilityFence(val);
41         }
42
43         /**
44          * Constructs a new Pong given each field
45          */
46         public static Pong of(short byteslen_arg) {
47                 long ret = bindings.Pong_new(byteslen_arg);
48                 Reference.reachabilityFence(byteslen_arg);
49                 if (ret >= 0 && ret <= 4096) { return null; }
50                 org.ldk.structs.Pong ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Pong(null, ret); }
51                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
52                 return ret_hu_conv;
53         }
54
55         long clone_ptr() {
56                 long ret = bindings.Pong_clone_ptr(this.ptr);
57                 Reference.reachabilityFence(this);
58                 return ret;
59         }
60
61         /**
62          * Creates a copy of the Pong
63          */
64         public Pong clone() {
65                 long ret = bindings.Pong_clone(this.ptr);
66                 Reference.reachabilityFence(this);
67                 if (ret >= 0 && ret <= 4096) { return null; }
68                 org.ldk.structs.Pong ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Pong(null, ret); }
69                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
70                 return ret_hu_conv;
71         }
72
73         /**
74          * Checks if two Pongs contain equal inner contents.
75          * This ignores pointers and is_owned flags and looks at the values in fields.
76          * Two objects with NULL inner values will be considered "equal" here.
77          */
78         public boolean eq(Pong b) {
79                 boolean ret = bindings.Pong_eq(this.ptr, b == null ? 0 : b.ptr);
80                 Reference.reachabilityFence(this);
81                 Reference.reachabilityFence(b);
82                 if (this != null) { this.ptrs_to.add(b); };
83                 return ret;
84         }
85
86         @Override public boolean equals(Object o) {
87                 if (!(o instanceof Pong)) return false;
88                 return this.eq((Pong)o);
89         }
90         /**
91          * Serialize the Pong object into a byte array which can be read by Pong_read
92          */
93         public byte[] write() {
94                 byte[] ret = bindings.Pong_write(this.ptr);
95                 Reference.reachabilityFence(this);
96                 return ret;
97         }
98
99         /**
100          * Read a Pong from a byte array, created by Pong_write
101          */
102         public static Result_PongDecodeErrorZ read(byte[] ser) {
103                 long ret = bindings.Pong_read(ser);
104                 Reference.reachabilityFence(ser);
105                 if (ret >= 0 && ret <= 4096) { return null; }
106                 Result_PongDecodeErrorZ ret_hu_conv = Result_PongDecodeErrorZ.constr_from_ptr(ret);
107                 return ret_hu_conv;
108         }
109
110 }