[C#] Run tests against release library in determinism CI run
[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          * Destroys the object, freeing associated resources. After this call, any access
29          * to this object may result in a SEGFAULT or worse.
30          *
31          * You should generally NEVER call this method. You should let the garbage collector
32          * do this for you when it finalizes objects. However, it may be useful for types
33          * which represent locks and should be closed immediately to avoid holding locks
34          * until the GC runs.
35          */
36         public void destroy() {
37                 if (ptr != 0) { bindings.CustomMessageReader_free(ptr); }
38                 ptr = 0;
39         }
40         public static interface CustomMessageReaderInterface {
41                 /**
42                  * Decodes a custom message to `CustomMessageType`. If the given message type is known to the
43                  * implementation and the message could be decoded, must return `Ok(Some(message))`. If the
44                  * message type is unknown to the implementation, must return `Ok(None)`. If a decoding error
45                  * occur, must return `Err(DecodeError::X)` where `X` details the encountered error.
46                  */
47                 Result_COption_TypeZDecodeErrorZ read(short message_type, byte[] buffer);
48         }
49         private static class LDKCustomMessageReaderHolder { CustomMessageReader held; }
50         public static CustomMessageReader new_impl(CustomMessageReaderInterface arg) {
51                 final LDKCustomMessageReaderHolder impl_holder = new LDKCustomMessageReaderHolder();
52                 impl_holder.held = new CustomMessageReader(new bindings.LDKCustomMessageReader() {
53                         @Override public long read(short message_type, byte[] buffer) {
54                                 Result_COption_TypeZDecodeErrorZ ret = arg.read(message_type, buffer);
55                                 Reference.reachabilityFence(arg);
56                                 long result = ret.clone_ptr();
57                                 return result;
58                         }
59                 });
60                 return impl_holder.held;
61         }
62         /**
63          * Decodes a custom message to `CustomMessageType`. If the given message type is known to the
64          * implementation and the message could be decoded, must return `Ok(Some(message))`. If the
65          * message type is unknown to the implementation, must return `Ok(None)`. If a decoding error
66          * occur, must return `Err(DecodeError::X)` where `X` details the encountered error.
67          */
68         public Result_COption_TypeZDecodeErrorZ read(short message_type, byte[] buffer) {
69                 long ret = bindings.CustomMessageReader_read(this.ptr, message_type, buffer);
70                 Reference.reachabilityFence(this);
71                 Reference.reachabilityFence(message_type);
72                 Reference.reachabilityFence(buffer);
73                 if (ret >= 0 && ret <= 4096) { return null; }
74                 Result_COption_TypeZDecodeErrorZ ret_hu_conv = Result_COption_TypeZDecodeErrorZ.constr_from_ptr(ret);
75                 return ret_hu_conv;
76         }
77
78 }