6 namespace org { namespace ldk { namespace structs {
9 * Trait to be implemented by custom message (unrelated to the channel/gossip LN layers)
12 public class CustomMessageReader : CommonBase {
13 internal readonly bindings.LDKCustomMessageReader bindings_instance;
14 internal CustomMessageReader(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
15 private CustomMessageReader(bindings.LDKCustomMessageReader arg) : base(bindings.LDKCustomMessageReader_new(arg)) {
16 this.ptrs_to.AddLast(arg);
17 this.bindings_instance = arg;
19 ~CustomMessageReader() {
20 if (ptr != 0) { bindings.CustomMessageReader_free(ptr); }
23 public interface CustomMessageReaderInterface {
25 * Decodes a custom message to `CustomMessageType`. If the given message type is known to the
26 * implementation and the message could be decoded, must return `Ok(Some(message))`. If the
27 * message type is unknown to the implementation, must return `Ok(None)`. If a decoding error
28 * occur, must return `Err(DecodeError::X)` where `X` details the encountered error.
30 Result_COption_TypeZDecodeErrorZ read(short _message_type, byte[] _buffer);
32 private class LDKCustomMessageReaderHolder { internal CustomMessageReader held; }
33 private class LDKCustomMessageReaderImpl : bindings.LDKCustomMessageReader {
34 internal LDKCustomMessageReaderImpl(CustomMessageReaderInterface arg, LDKCustomMessageReaderHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
35 private CustomMessageReaderInterface arg;
36 private LDKCustomMessageReaderHolder impl_holder;
37 public long read(short _message_type, byte[] _buffer) {
38 Result_COption_TypeZDecodeErrorZ ret = arg.read(_message_type, _buffer);
40 long result = ret == null ? 0 : ret.clone_ptr();
44 public static CustomMessageReader new_impl(CustomMessageReaderInterface arg) {
45 LDKCustomMessageReaderHolder impl_holder = new LDKCustomMessageReaderHolder();
46 impl_holder.held = new CustomMessageReader(new LDKCustomMessageReaderImpl(arg, impl_holder));
47 return impl_holder.held;
50 * Decodes a custom message to `CustomMessageType`. If the given message type is known to the
51 * implementation and the message could be decoded, must return `Ok(Some(message))`. If the
52 * message type is unknown to the implementation, must return `Ok(None)`. If a decoding error
53 * occur, must return `Err(DecodeError::X)` where `X` details the encountered error.
55 public Result_COption_TypeZDecodeErrorZ read(short message_type, byte[] buffer) {
56 long ret = bindings.CustomMessageReader_read(this.ptr, message_type, buffer);
58 GC.KeepAlive(message_type);
60 if (ret >= 0 && ret <= 4096) { return null; }
61 Result_COption_TypeZDecodeErrorZ ret_hu_conv = Result_COption_TypeZDecodeErrorZ.constr_from_ptr(ret);