7 namespace org { namespace ldk { namespace structs {
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.
18 Result_COption_TypeZDecodeErrorZ read(short message_type, byte[] buffer);
22 * Trait to be implemented by custom message (unrelated to the channel/gossip LN layers)
25 public class CustomMessageReader : CommonBase {
26 internal bindings.LDKCustomMessageReader bindings_instance;
27 internal long instance_idx;
29 internal CustomMessageReader(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
30 ~CustomMessageReader() {
31 if (ptr != 0) { bindings.CustomMessageReader_free(ptr); }
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);
43 long result = ret == null ? 0 : ret.clone_ptr();
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);
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;
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.
66 public Result_COption_TypeZDecodeErrorZ read(short message_type, byte[] buffer) {
67 long ret = bindings.CustomMessageReader_read(this.ptr, message_type, InternalUtils.encodeUint8Array(buffer));
69 GC.KeepAlive(message_type);
71 if (ret >= 0 && ret <= 4096) { return null; }
72 Result_COption_TypeZDecodeErrorZ ret_hu_conv = Result_COption_TypeZDecodeErrorZ.constr_from_ptr(ret);