421d9e6b5b9d6ebba3f09b17c135aa71cd27049e
[ldk-java] / src / main / java / org / ldk / structs / BigSize.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  * Lightning TLV uses a custom variable-length integer called `BigSize`. It is similar to Bitcoin's
13  * variable-length integers except that it is serialized in big-endian instead of little-endian.
14  * 
15  * Like Bitcoin's variable-length integer, it exhibits ambiguity in that certain values can be
16  * encoded in several different ways, which we must check for at deserialization-time. Thus, if
17  * you're looking for an example of a variable-length integer to use for your own project, move
18  * along, this is a rather poor design.
19  */
20 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
21 public class BigSize extends CommonBase {
22         BigSize(Object _dummy, long ptr) { super(ptr); }
23         @Override @SuppressWarnings("deprecation")
24         protected void finalize() throws Throwable {
25                 super.finalize();
26                 if (ptr != 0) { bindings.BigSize_free(ptr); }
27         }
28
29         public long get_a() {
30                 long ret = bindings.BigSize_get_a(this.ptr);
31                 Reference.reachabilityFence(this);
32                 return ret;
33         }
34
35         public void set_a(long val) {
36                 bindings.BigSize_set_a(this.ptr, val);
37                 Reference.reachabilityFence(this);
38                 Reference.reachabilityFence(val);
39         }
40
41         /**
42          * Constructs a new BigSize given each field
43          */
44         public static BigSize of(long a_arg) {
45                 long ret = bindings.BigSize_new(a_arg);
46                 Reference.reachabilityFence(a_arg);
47                 if (ret >= 0 && ret <= 4096) { return null; }
48                 org.ldk.structs.BigSize ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BigSize(null, ret); }
49                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
50                 return ret_hu_conv;
51         }
52
53         long clone_ptr() {
54                 long ret = bindings.BigSize_clone_ptr(this.ptr);
55                 Reference.reachabilityFence(this);
56                 return ret;
57         }
58
59         /**
60          * Creates a copy of the BigSize
61          */
62         public BigSize clone() {
63                 long ret = bindings.BigSize_clone(this.ptr);
64                 Reference.reachabilityFence(this);
65                 if (ret >= 0 && ret <= 4096) { return null; }
66                 org.ldk.structs.BigSize ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BigSize(null, ret); }
67                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
68                 return ret_hu_conv;
69         }
70
71         /**
72          * Generates a non-cryptographic 64-bit hash of the BigSize.
73          */
74         public long hash() {
75                 long ret = bindings.BigSize_hash(this.ptr);
76                 Reference.reachabilityFence(this);
77                 return ret;
78         }
79
80         @Override public int hashCode() {
81                 return (int)this.hash();
82         }
83         /**
84          * Checks if two BigSizes contain equal inner contents.
85          * This ignores pointers and is_owned flags and looks at the values in fields.
86          * Two objects with NULL inner values will be considered "equal" here.
87          */
88         public boolean eq(org.ldk.structs.BigSize b) {
89                 boolean ret = bindings.BigSize_eq(this.ptr, b == null ? 0 : b.ptr);
90                 Reference.reachabilityFence(this);
91                 Reference.reachabilityFence(b);
92                 if (this != null) { this.ptrs_to.add(b); };
93                 return ret;
94         }
95
96         @Override public boolean equals(Object o) {
97                 if (!(o instanceof BigSize)) return false;
98                 return this.eq((BigSize)o);
99         }
100         /**
101          * Serialize the BigSize object into a byte array which can be read by BigSize_read
102          */
103         public byte[] write() {
104                 byte[] ret = bindings.BigSize_write(this.ptr);
105                 Reference.reachabilityFence(this);
106                 return ret;
107         }
108
109         /**
110          * Read a BigSize from a byte array, created by BigSize_write
111          */
112         public static Result_BigSizeDecodeErrorZ read(byte[] ser) {
113                 long ret = bindings.BigSize_read(ser);
114                 Reference.reachabilityFence(ser);
115                 if (ret >= 0 && ret <= 4096) { return null; }
116                 Result_BigSizeDecodeErrorZ ret_hu_conv = Result_BigSizeDecodeErrorZ.constr_from_ptr(ret);
117                 return ret_hu_conv;
118         }
119
120 }