8bd84802e170a76e61486fa7636744215f884989
[ldk-java] / c_sharp / src / org / ldk / structs / OnionMessageContents.cs
1
2 using org.ldk.impl;
3 using org.ldk.enums;
4 using org.ldk.util;
5 using System;
6
7 namespace org { namespace ldk { namespace structs {
8
9
10
11 /** An implementation of OnionMessageContents */
12 public interface OnionMessageContentsInterface {
13         /**Returns the TLV type identifying the message contents. MUST be >= 64.
14          */
15         long tlv_type();
16         /**Serialize the object into a byte array
17          */
18         byte[] write();
19 }
20
21 /**
22  * The contents of an onion message.
23  */
24 public class OnionMessageContents : CommonBase {
25         internal bindings.LDKOnionMessageContents bindings_instance;
26         internal long instance_idx;
27
28         internal OnionMessageContents(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
29         ~OnionMessageContents() {
30                 if (ptr != 0) { bindings.OnionMessageContents_free(ptr); }
31         }
32
33         private class LDKOnionMessageContentsHolder { internal OnionMessageContents held; }
34         private class LDKOnionMessageContentsImpl : bindings.LDKOnionMessageContents {
35                 internal LDKOnionMessageContentsImpl(OnionMessageContentsInterface arg, LDKOnionMessageContentsHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
36                 private OnionMessageContentsInterface arg;
37                 private LDKOnionMessageContentsHolder impl_holder;
38                 public long tlv_type() {
39                         long ret = arg.tlv_type();
40                                 GC.KeepAlive(arg);
41                         return ret;
42                 }
43                 public long write() {
44                         byte[] ret = arg.write();
45                                 GC.KeepAlive(arg);
46                         long result = InternalUtils.encodeUint8Array(ret);
47                         return result;
48                 }
49         }
50
51         /** Creates a new instance of OnionMessageContents from a given implementation */
52         public static OnionMessageContents new_impl(OnionMessageContentsInterface arg) {
53                 LDKOnionMessageContentsHolder impl_holder = new LDKOnionMessageContentsHolder();
54                 LDKOnionMessageContentsImpl impl = new LDKOnionMessageContentsImpl(arg, impl_holder);
55                 long[] ptr_idx = bindings.LDKOnionMessageContents_new(impl);
56
57                 impl_holder.held = new OnionMessageContents(null, ptr_idx[0]);
58                 impl_holder.held.instance_idx = ptr_idx[1];
59                 impl_holder.held.bindings_instance = impl;
60                 return impl_holder.held;
61         }
62
63         /**
64          * Returns the TLV type identifying the message contents. MUST be >= 64.
65          */
66         public long tlv_type() {
67                 long ret = bindings.OnionMessageContents_tlv_type(this.ptr);
68                 GC.KeepAlive(this);
69                 return ret;
70         }
71
72         /**
73          * Serialize the object into a byte array
74          */
75         public byte[] write() {
76                 long ret = bindings.OnionMessageContents_write(this.ptr);
77                 GC.KeepAlive(this);
78                 if (ret >= 0 && ret <= 4096) { return null; }
79                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
80                 return ret_conv;
81         }
82
83         internal long clone_ptr() {
84                 long ret = bindings.OnionMessageContents_clone_ptr(this.ptr);
85                 GC.KeepAlive(this);
86                 return ret;
87         }
88
89         /**
90          * Creates a copy of a OnionMessageContents
91          */
92         public OnionMessageContents clone() {
93                 long ret = bindings.OnionMessageContents_clone(this.ptr);
94                 GC.KeepAlive(this);
95                 if (ret >= 0 && ret <= 4096) { return null; }
96                 OnionMessageContents ret_hu_conv = new OnionMessageContents(null, ret);
97                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
98                 return ret_hu_conv;
99         }
100
101 }
102 } } }