1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
10 * Trait to be implemented by custom message (unrelated to the channel/gossip LN layers)
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class CustomMessageReader extends CommonBase {
15 final bindings.LDKCustomMessageReader bindings_instance;
16 CustomMessageReader(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
17 private CustomMessageReader(bindings.LDKCustomMessageReader arg) {
18 super(bindings.LDKCustomMessageReader_new(arg));
19 this.ptrs_to.add(arg);
20 this.bindings_instance = arg;
22 @Override @SuppressWarnings("deprecation")
23 protected void finalize() throws Throwable {
24 if (ptr != 0) { bindings.CustomMessageReader_free(ptr); } super.finalize();
27 public static interface CustomMessageReaderInterface {
29 * Decodes a custom message to `CustomMessageType`. If the given message type is known to the
30 * implementation and the message could be decoded, must return `Ok(Some(message))`. If the
31 * message type is unknown to the implementation, must return `Ok(None)`. If a decoding error
32 * occur, must return `Err(DecodeError::X)` where `X` details the encountered error.
34 Result_COption_TypeZDecodeErrorZ read(short message_type, byte[] buffer);
36 private static class LDKCustomMessageReaderHolder { CustomMessageReader held; }
37 public static CustomMessageReader new_impl(CustomMessageReaderInterface arg) {
38 final LDKCustomMessageReaderHolder impl_holder = new LDKCustomMessageReaderHolder();
39 impl_holder.held = new CustomMessageReader(new bindings.LDKCustomMessageReader() {
40 @Override public long read(short message_type, byte[] buffer) {
41 Result_COption_TypeZDecodeErrorZ ret = arg.read(message_type, buffer);
42 long result = ret != null ? ret.ptr : 0;
46 return impl_holder.held;
49 * Decodes a custom message to `CustomMessageType`. If the given message type is known to the
50 * implementation and the message could be decoded, must return `Ok(Some(message))`. If the
51 * message type is unknown to the implementation, must return `Ok(None)`. If a decoding error
52 * occur, must return `Err(DecodeError::X)` where `X` details the encountered error.
54 public Result_COption_TypeZDecodeErrorZ read(short message_type, byte[] buffer) {
55 long ret = bindings.CustomMessageReader_read(this.ptr, message_type, buffer);
56 if (ret >= 0 && ret <= 4096) { return null; }
57 Result_COption_TypeZDecodeErrorZ ret_hu_conv = Result_COption_TypeZDecodeErrorZ.constr_from_ptr(ret);