1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
10 * Defines a type identifier for sending messages over the wire.
12 * Messages implementing this trait specify a type and must be [`Writeable`].
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class Type extends CommonBase {
16 final bindings.LDKType bindings_instance;
17 Type(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
18 private Type(bindings.LDKType arg) {
19 super(bindings.LDKType_new(arg));
20 this.ptrs_to.add(arg);
21 this.bindings_instance = arg;
23 @Override @SuppressWarnings("deprecation")
24 protected void finalize() throws Throwable {
25 if (ptr != 0) { bindings.Type_free(ptr); } super.finalize();
28 public static interface TypeInterface {
30 * Returns the type identifying the message payload.
34 * Return a human-readable "debug" string describing this object
38 * Serialize the object into a byte array
42 private static class LDKTypeHolder { Type held; }
43 public static Type new_impl(TypeInterface arg) {
44 final LDKTypeHolder impl_holder = new LDKTypeHolder();
45 impl_holder.held = new Type(new bindings.LDKType() {
46 @Override public short type_id() {
47 short ret = arg.type_id();
50 @Override public String debug_str() {
51 String ret = arg.debug_str();
54 @Override public byte[] write() {
55 byte[] ret = arg.write();
59 return impl_holder.held;
62 * Returns the type identifying the message payload.
64 public short type_id() {
65 short ret = bindings.Type_type_id(this.ptr);
70 * Return a human-readable "debug" string describing this object
72 public String debug_str() {
73 String ret = bindings.Type_debug_str(this.ptr);
78 * Serialize the object into a byte array
80 public byte[] write() {
81 byte[] ret = bindings.Type_write(this.ptr);
86 * Creates a copy of a Type
89 long ret = bindings.Type_clone(this.ptr);
90 if (ret < 1024) { return null; }
91 Type ret_hu_conv = new Type(null, ret);
92 ret_hu_conv.ptrs_to.add(this);