20799363b7ff28b691bdea7ebda6066d7de58a5c
[ldk-java] / c_sharp / src / org / ldk / structs / Type.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8 /**
9  * Defines a type identifier for sending messages over the wire.
10  * 
11  * Messages implementing this trait specify a type and must be [`Writeable`].
12  */
13 public class Type : CommonBase {
14         internal readonly bindings.LDKType bindings_instance;
15         internal Type(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
16         private Type(bindings.LDKType arg) : base(bindings.LDKType_new(arg)) {
17                 this.ptrs_to.AddLast(arg);
18                 this.bindings_instance = arg;
19         }
20         ~Type() {
21                 if (ptr != 0) { bindings.Type_free(ptr); }
22         }
23
24         public interface TypeInterface {
25                 /**
26                  * Returns the type identifying the message payload.
27                  */
28                 short type_id();
29                 /**
30                  * Return a human-readable "debug" string describing this object
31                  */
32                 string debug_str();
33                 /**
34                  * Serialize the object into a byte array
35                  */
36                 byte[] write();
37         }
38         private class LDKTypeHolder { internal Type held; }
39         private class LDKTypeImpl : bindings.LDKType {
40                 internal LDKTypeImpl(TypeInterface arg, LDKTypeHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
41                 private TypeInterface arg;
42                 private LDKTypeHolder impl_holder;
43                 public short type_id() {
44                         short ret = arg.type_id();
45                                 GC.KeepAlive(arg);
46                         return ret;
47                 }
48                 public string debug_str() {
49                         string ret = arg.debug_str();
50                                 GC.KeepAlive(arg);
51                         return ret;
52                 }
53                 public byte[] write() {
54                         byte[] ret = arg.write();
55                                 GC.KeepAlive(arg);
56                         return ret;
57                 }
58         }
59         public static Type new_impl(TypeInterface arg) {
60                 LDKTypeHolder impl_holder = new LDKTypeHolder();
61                 impl_holder.held = new Type(new LDKTypeImpl(arg, impl_holder));
62                 return impl_holder.held;
63         }
64         /**
65          * Returns the type identifying the message payload.
66          */
67         public short type_id() {
68                 short ret = bindings.Type_type_id(this.ptr);
69                 GC.KeepAlive(this);
70                 return ret;
71         }
72
73         /**
74          * Return a human-readable "debug" string describing this object
75          */
76         public string debug_str() {
77                 string ret = bindings.Type_debug_str(this.ptr);
78                 GC.KeepAlive(this);
79                 return ret;
80         }
81
82         /**
83          * Serialize the object into a byte array
84          */
85         public byte[] write() {
86                 byte[] ret = bindings.Type_write(this.ptr);
87                 GC.KeepAlive(this);
88                 return ret;
89         }
90
91         internal long clone_ptr() {
92                 long ret = bindings.Type_clone_ptr(this.ptr);
93                 GC.KeepAlive(this);
94                 return ret;
95         }
96
97         /**
98          * Creates a copy of a Type
99          */
100         public Type clone() {
101                 long ret = bindings.Type_clone(this.ptr);
102                 GC.KeepAlive(this);
103                 if (ret >= 0 && ret <= 4096) { return null; }
104                 Type ret_hu_conv = new Type(null, ret);
105                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
106                 return ret_hu_conv;
107         }
108
109 }
110 } } }