[C#] Update auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / KVStore.cs
1
2 using org.ldk.impl;
3 using org.ldk.enums;
4 using org.ldk.util;
5 using System;
6
7 namespace org { namespace ldk { namespace structs {
8
9
10
11 /** An implementation of KVStore */
12 public interface KVStoreInterface {
13         /**Returns the data stored for the given `primary_namespace`, `secondary_namespace`, and
14          * `key`.
15          * 
16          * Returns an [`ErrorKind::NotFound`] if the given `key` could not be found in the given
17          * `primary_namespace` and `secondary_namespace`.
18          * 
19          * [`ErrorKind::NotFound`]: io::ErrorKind::NotFound
20          */
21         Result_CVec_u8ZIOErrorZ read(string primary_namespace, string secondary_namespace, string key);
22         /**Persists the given data under the given `key`.
23          * 
24          * Will create the given `primary_namespace` and `secondary_namespace` if not already present
25          * in the store.
26          */
27         Result_NoneIOErrorZ write(string primary_namespace, string secondary_namespace, string key, byte[] buf);
28         /**Removes any data that had previously been persisted under the given `key`.
29          * 
30          * If the `lazy` flag is set to `true`, the backend implementation might choose to lazily
31          * remove the given `key` at some point in time after the method returns, e.g., as part of an
32          * eventual batch deletion of multiple keys. As a consequence, subsequent calls to
33          * [`KVStore::list`] might include the removed key until the changes are actually persisted.
34          * 
35          * Note that while setting the `lazy` flag reduces the I/O burden of multiple subsequent
36          * `remove` calls, it also influences the atomicity guarantees as lazy `remove`s could
37          * potentially get lost on crash after the method returns. Therefore, this flag should only be
38          * set for `remove` operations that can be safely replayed at a later time.
39          * 
40          * Returns successfully if no data will be stored for the given `primary_namespace`,
41          * `secondary_namespace`, and `key`, independently of whether it was present before its
42          * invokation or not.
43          */
44         Result_NoneIOErrorZ remove(string primary_namespace, string secondary_namespace, string key, bool lazy);
45         /**Returns a list of keys that are stored under the given `secondary_namespace` in
46          * `primary_namespace`.
47          * 
48          * Returns the keys in arbitrary order, so users requiring a particular order need to sort the
49          * returned keys. Returns an empty list if `primary_namespace` or `secondary_namespace` is unknown.
50          */
51         Result_CVec_StrZIOErrorZ list(string primary_namespace, string secondary_namespace);
52 }
53
54 /**
55  * Provides an interface that allows storage and retrieval of persisted values that are associated
56  * with given keys.
57  * 
58  * In order to avoid collisions the key space is segmented based on the given `primary_namespace`s
59  * and `secondary_namespace`s. Implementations of this trait are free to handle them in different
60  * ways, as long as per-namespace key uniqueness is asserted.
61  * 
62  * Keys and namespaces are required to be valid ASCII strings in the range of
63  * [`KVSTORE_NAMESPACE_KEY_ALPHABET`] and no longer than [`KVSTORE_NAMESPACE_KEY_MAX_LEN`]. Empty
64  * primary namespaces and secondary namespaces (`\"\"`) are assumed to be a valid, however, if
65  * `primary_namespace` is empty, `secondary_namespace` is required to be empty, too. This means
66  * that concerns should always be separated by primary namespace first, before secondary
67  * namespaces are used. While the number of primary namespaces will be relatively small and is
68  * determined at compile time, there may be many secondary namespaces per primary namespace. Note
69  * that per-namespace uniqueness needs to also hold for keys *and* namespaces in any given
70  * namespace, i.e., conflicts between keys and equally named
71  * primary namespaces/secondary namespaces must be avoided.
72  * 
73  * Note:** Users migrating custom persistence backends from the pre-v0.0.117 `KVStorePersister`
74  * interface can use a concatenation of `[{primary_namespace}/[{secondary_namespace}/]]{key}` to
75  * recover a `key` compatible with the data model previously assumed by `KVStorePersister::persist`.
76  */
77 public class KVStore : CommonBase {
78         internal bindings.LDKKVStore bindings_instance;
79         internal long instance_idx;
80
81         internal KVStore(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
82         ~KVStore() {
83                 if (ptr != 0) { bindings.KVStore_free(ptr); }
84         }
85
86         private class LDKKVStoreHolder { internal KVStore held; }
87         private class LDKKVStoreImpl : bindings.LDKKVStore {
88                 internal LDKKVStoreImpl(KVStoreInterface arg, LDKKVStoreHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
89                 private KVStoreInterface arg;
90                 private LDKKVStoreHolder impl_holder;
91                 public long read(long _primary_namespace, long _secondary_namespace, long _key) {
92                         string _primary_namespace_conv = InternalUtils.decodeString(_primary_namespace);
93                         string _secondary_namespace_conv = InternalUtils.decodeString(_secondary_namespace);
94                         string _key_conv = InternalUtils.decodeString(_key);
95                         Result_CVec_u8ZIOErrorZ ret = arg.read(_primary_namespace_conv, _secondary_namespace_conv, _key_conv);
96                                 GC.KeepAlive(arg);
97                         long result = ret == null ? 0 : ret.clone_ptr();
98                         return result;
99                 }
100                 public long write(long _primary_namespace, long _secondary_namespace, long _key, long _buf) {
101                         string _primary_namespace_conv = InternalUtils.decodeString(_primary_namespace);
102                         string _secondary_namespace_conv = InternalUtils.decodeString(_secondary_namespace);
103                         string _key_conv = InternalUtils.decodeString(_key);
104                         byte[] _buf_conv = InternalUtils.decodeUint8Array(_buf);
105                         Result_NoneIOErrorZ ret = arg.write(_primary_namespace_conv, _secondary_namespace_conv, _key_conv, _buf_conv);
106                                 GC.KeepAlive(arg);
107                         long result = ret == null ? 0 : ret.clone_ptr();
108                         return result;
109                 }
110                 public long remove(long _primary_namespace, long _secondary_namespace, long _key, bool _lazy) {
111                         string _primary_namespace_conv = InternalUtils.decodeString(_primary_namespace);
112                         string _secondary_namespace_conv = InternalUtils.decodeString(_secondary_namespace);
113                         string _key_conv = InternalUtils.decodeString(_key);
114                         Result_NoneIOErrorZ ret = arg.remove(_primary_namespace_conv, _secondary_namespace_conv, _key_conv, _lazy);
115                                 GC.KeepAlive(arg);
116                         long result = ret == null ? 0 : ret.clone_ptr();
117                         return result;
118                 }
119                 public long list(long _primary_namespace, long _secondary_namespace) {
120                         string _primary_namespace_conv = InternalUtils.decodeString(_primary_namespace);
121                         string _secondary_namespace_conv = InternalUtils.decodeString(_secondary_namespace);
122                         Result_CVec_StrZIOErrorZ ret = arg.list(_primary_namespace_conv, _secondary_namespace_conv);
123                                 GC.KeepAlive(arg);
124                         long result = ret == null ? 0 : ret.clone_ptr();
125                         return result;
126                 }
127         }
128
129         /** Creates a new instance of KVStore from a given implementation */
130         public static KVStore new_impl(KVStoreInterface arg) {
131                 LDKKVStoreHolder impl_holder = new LDKKVStoreHolder();
132                 LDKKVStoreImpl impl = new LDKKVStoreImpl(arg, impl_holder);
133                 long[] ptr_idx = bindings.LDKKVStore_new(impl);
134
135                 impl_holder.held = new KVStore(null, ptr_idx[0]);
136                 impl_holder.held.instance_idx = ptr_idx[1];
137                 impl_holder.held.bindings_instance = impl;
138                 return impl_holder.held;
139         }
140
141         /**
142          * Returns the data stored for the given `primary_namespace`, `secondary_namespace`, and
143          * `key`.
144          * 
145          * Returns an [`ErrorKind::NotFound`] if the given `key` could not be found in the given
146          * `primary_namespace` and `secondary_namespace`.
147          * 
148          * [`ErrorKind::NotFound`]: io::ErrorKind::NotFound
149          */
150         public Result_CVec_u8ZIOErrorZ read(string primary_namespace, string secondary_namespace, string key) {
151                 long ret = bindings.KVStore_read(this.ptr, InternalUtils.encodeString(primary_namespace), InternalUtils.encodeString(secondary_namespace), InternalUtils.encodeString(key));
152                 GC.KeepAlive(this);
153                 GC.KeepAlive(primary_namespace);
154                 GC.KeepAlive(secondary_namespace);
155                 GC.KeepAlive(key);
156                 if (ret >= 0 && ret <= 4096) { return null; }
157                 Result_CVec_u8ZIOErrorZ ret_hu_conv = Result_CVec_u8ZIOErrorZ.constr_from_ptr(ret);
158                 return ret_hu_conv;
159         }
160
161         /**
162          * Persists the given data under the given `key`.
163          * 
164          * Will create the given `primary_namespace` and `secondary_namespace` if not already present
165          * in the store.
166          */
167         public Result_NoneIOErrorZ write(string primary_namespace, string secondary_namespace, string key, byte[] buf) {
168                 long ret = bindings.KVStore_write(this.ptr, InternalUtils.encodeString(primary_namespace), InternalUtils.encodeString(secondary_namespace), InternalUtils.encodeString(key), InternalUtils.encodeUint8Array(buf));
169                 GC.KeepAlive(this);
170                 GC.KeepAlive(primary_namespace);
171                 GC.KeepAlive(secondary_namespace);
172                 GC.KeepAlive(key);
173                 GC.KeepAlive(buf);
174                 if (ret >= 0 && ret <= 4096) { return null; }
175                 Result_NoneIOErrorZ ret_hu_conv = Result_NoneIOErrorZ.constr_from_ptr(ret);
176                 return ret_hu_conv;
177         }
178
179         /**
180          * Removes any data that had previously been persisted under the given `key`.
181          * 
182          * If the `lazy` flag is set to `true`, the backend implementation might choose to lazily
183          * remove the given `key` at some point in time after the method returns, e.g., as part of an
184          * eventual batch deletion of multiple keys. As a consequence, subsequent calls to
185          * [`KVStore::list`] might include the removed key until the changes are actually persisted.
186          * 
187          * Note that while setting the `lazy` flag reduces the I/O burden of multiple subsequent
188          * `remove` calls, it also influences the atomicity guarantees as lazy `remove`s could
189          * potentially get lost on crash after the method returns. Therefore, this flag should only be
190          * set for `remove` operations that can be safely replayed at a later time.
191          * 
192          * Returns successfully if no data will be stored for the given `primary_namespace`,
193          * `secondary_namespace`, and `key`, independently of whether it was present before its
194          * invokation or not.
195          */
196         public Result_NoneIOErrorZ remove(string primary_namespace, string secondary_namespace, string key, bool lazy) {
197                 long ret = bindings.KVStore_remove(this.ptr, InternalUtils.encodeString(primary_namespace), InternalUtils.encodeString(secondary_namespace), InternalUtils.encodeString(key), lazy);
198                 GC.KeepAlive(this);
199                 GC.KeepAlive(primary_namespace);
200                 GC.KeepAlive(secondary_namespace);
201                 GC.KeepAlive(key);
202                 GC.KeepAlive(lazy);
203                 if (ret >= 0 && ret <= 4096) { return null; }
204                 Result_NoneIOErrorZ ret_hu_conv = Result_NoneIOErrorZ.constr_from_ptr(ret);
205                 return ret_hu_conv;
206         }
207
208         /**
209          * Returns a list of keys that are stored under the given `secondary_namespace` in
210          * `primary_namespace`.
211          * 
212          * Returns the keys in arbitrary order, so users requiring a particular order need to sort the
213          * returned keys. Returns an empty list if `primary_namespace` or `secondary_namespace` is unknown.
214          */
215         public Result_CVec_StrZIOErrorZ list(string primary_namespace, string secondary_namespace) {
216                 long ret = bindings.KVStore_list(this.ptr, InternalUtils.encodeString(primary_namespace), InternalUtils.encodeString(secondary_namespace));
217                 GC.KeepAlive(this);
218                 GC.KeepAlive(primary_namespace);
219                 GC.KeepAlive(secondary_namespace);
220                 if (ret >= 0 && ret <= 4096) { return null; }
221                 Result_CVec_StrZIOErrorZ ret_hu_conv = Result_CVec_StrZIOErrorZ.constr_from_ptr(ret);
222                 return ret_hu_conv;
223         }
224
225 }
226 } } }