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;
11 * Defines a type identifier for sending messages over the wire.
13 * Messages implementing this trait specify a type and must be [`Writeable`].
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class Type extends CommonBase {
17 final bindings.LDKType bindings_instance;
18 Type(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
19 private Type(bindings.LDKType arg) {
20 super(bindings.LDKType_new(arg));
21 this.ptrs_to.add(arg);
22 this.bindings_instance = arg;
24 @Override @SuppressWarnings("deprecation")
25 protected void finalize() throws Throwable {
26 if (ptr != 0) { bindings.Type_free(ptr); } super.finalize();
29 public static interface TypeInterface {
31 * Returns the type identifying the message payload.
35 * Return a human-readable "debug" string describing this object
39 * Serialize the object into a byte array
43 private static class LDKTypeHolder { Type held; }
44 public static Type new_impl(TypeInterface arg) {
45 final LDKTypeHolder impl_holder = new LDKTypeHolder();
46 impl_holder.held = new Type(new bindings.LDKType() {
47 @Override public short type_id() {
48 short ret = arg.type_id();
51 @Override public String debug_str() {
52 String ret = arg.debug_str();
55 @Override public byte[] write() {
56 byte[] ret = arg.write();
60 return impl_holder.held;
63 * Returns the type identifying the message payload.
65 public short type_id() {
66 short ret = bindings.Type_type_id(this.ptr);
67 Reference.reachabilityFence(this);
72 * Return a human-readable "debug" string describing this object
74 public String debug_str() {
75 String ret = bindings.Type_debug_str(this.ptr);
76 Reference.reachabilityFence(this);
81 * Serialize the object into a byte array
83 public byte[] write() {
84 byte[] ret = bindings.Type_write(this.ptr);
85 Reference.reachabilityFence(this);
90 long ret = bindings.Type_clone_ptr(this.ptr);
91 Reference.reachabilityFence(this);
96 * Creates a copy of a Type
99 long ret = bindings.Type_clone(this.ptr);
100 Reference.reachabilityFence(this);
101 if (ret >= 0 && ret <= 4096) { return null; }
102 Type ret_hu_conv = new Type(null, ret);
103 ret_hu_conv.ptrs_to.add(this);