[C#] Update auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / CustomMessageReader.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 CustomMessageReader */
12 public interface CustomMessageReaderInterface {
13         /**Decodes a custom message to `CustomMessageType`. If the given message type is known to the
14          * implementation and the message could be decoded, must return `Ok(Some(message))`. If the
15          * message type is unknown to the implementation, must return `Ok(None)`. If a decoding error
16          * occur, must return `Err(DecodeError::X)` where `X` details the encountered error.
17          */
18         Result_COption_TypeZDecodeErrorZ read(short message_type, byte[] buffer);
19 }
20
21 /**
22  * Trait to be implemented by custom message (unrelated to the channel/gossip LN layers)
23  * decoders.
24  */
25 public class CustomMessageReader : CommonBase {
26         internal bindings.LDKCustomMessageReader bindings_instance;
27         internal long instance_idx;
28
29         internal CustomMessageReader(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
30         ~CustomMessageReader() {
31                 if (ptr != 0) { bindings.CustomMessageReader_free(ptr); }
32         }
33
34         private class LDKCustomMessageReaderHolder { internal CustomMessageReader held; }
35         private class LDKCustomMessageReaderImpl : bindings.LDKCustomMessageReader {
36                 internal LDKCustomMessageReaderImpl(CustomMessageReaderInterface arg, LDKCustomMessageReaderHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
37                 private CustomMessageReaderInterface arg;
38                 private LDKCustomMessageReaderHolder impl_holder;
39                 public long read(short _message_type, long _buffer) {
40                         byte[] _buffer_conv = InternalUtils.decodeUint8Array(_buffer);
41                         Result_COption_TypeZDecodeErrorZ ret = arg.read(_message_type, _buffer_conv);
42                                 GC.KeepAlive(arg);
43                         long result = ret == null ? 0 : ret.clone_ptr();
44                         return result;
45                 }
46         }
47
48         /** Creates a new instance of CustomMessageReader from a given implementation */
49         public static CustomMessageReader new_impl(CustomMessageReaderInterface arg) {
50                 LDKCustomMessageReaderHolder impl_holder = new LDKCustomMessageReaderHolder();
51                 LDKCustomMessageReaderImpl impl = new LDKCustomMessageReaderImpl(arg, impl_holder);
52                 long[] ptr_idx = bindings.LDKCustomMessageReader_new(impl);
53
54                 impl_holder.held = new CustomMessageReader(null, ptr_idx[0]);
55                 impl_holder.held.instance_idx = ptr_idx[1];
56                 impl_holder.held.bindings_instance = impl;
57                 return impl_holder.held;
58         }
59
60         /**
61          * Decodes a custom message to `CustomMessageType`. If the given message type is known to the
62          * implementation and the message could be decoded, must return `Ok(Some(message))`. If the
63          * message type is unknown to the implementation, must return `Ok(None)`. If a decoding error
64          * occur, must return `Err(DecodeError::X)` where `X` details the encountered error.
65          */
66         public Result_COption_TypeZDecodeErrorZ read(short message_type, byte[] buffer) {
67                 long ret = bindings.CustomMessageReader_read(this.ptr, message_type, InternalUtils.encodeUint8Array(buffer));
68                 GC.KeepAlive(this);
69                 GC.KeepAlive(message_type);
70                 GC.KeepAlive(buffer);
71                 if (ret >= 0 && ret <= 4096) { return null; }
72                 Result_COption_TypeZDecodeErrorZ ret_hu_conv = Result_COption_TypeZDecodeErrorZ.constr_from_ptr(ret);
73                 return ret_hu_conv;
74         }
75
76 }
77 } } }