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