4e54310539fba6eca229d626be3c76240fd48fe8
[ldk-java] / src / main / java / org / ldk / structs / WriteableScore.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  * Refers to a scorer that is accessible under lock and also writeable to disk
12  * 
13  * We need this trait to be able to pass in a scorer to `lightning-background-processor` that will enable us to
14  * use the Persister to persist it.
15  */
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class WriteableScore extends CommonBase {
18         final bindings.LDKWriteableScore bindings_instance;
19         WriteableScore(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
20         private WriteableScore(bindings.LDKWriteableScore arg, bindings.LDKLockableScore LockableScore) {
21                 super(bindings.LDKWriteableScore_new(arg, LockableScore));
22                 this.ptrs_to.add(arg);
23                 this.ptrs_to.add(LockableScore);
24                 this.bindings_instance = arg;
25         }
26         @Override @SuppressWarnings("deprecation")
27         protected void finalize() throws Throwable {
28                 if (ptr != 0) { bindings.WriteableScore_free(ptr); } super.finalize();
29         }
30
31         public static interface WriteableScoreInterface {
32                 /**
33                  * Serialize the object into a byte array
34                  */
35                 byte[] write();
36         }
37         private static class LDKWriteableScoreHolder { WriteableScore held; }
38         public static WriteableScore new_impl(WriteableScoreInterface arg, LockableScore.LockableScoreInterface LockableScore_impl) {
39                 final LDKWriteableScoreHolder impl_holder = new LDKWriteableScoreHolder();
40                 impl_holder.held = new WriteableScore(new bindings.LDKWriteableScore() {
41                         @Override public byte[] write() {
42                                 byte[] ret = arg.write();
43                                 Reference.reachabilityFence(arg);
44                                 return ret;
45                         }
46                 }, LockableScore.new_impl(LockableScore_impl).bindings_instance);
47                 return impl_holder.held;
48         }
49
50         /**
51          * Gets the underlying LockableScore.
52          */
53         public LockableScore get_lockable_score() {
54                 LockableScore res = new LockableScore(null, bindings.LDKWriteableScore_get_LockableScore(this.ptr));
55                 this.ptrs_to.add(res);
56                 return res;
57         }
58
59         /**
60          * Serialize the object into a byte array
61          */
62         public byte[] write() {
63                 byte[] ret = bindings.WriteableScore_write(this.ptr);
64                 Reference.reachabilityFence(this);
65                 return ret;
66         }
67
68 }