You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is symmetrical with what we already have for channel data.
The goal is to offer ready-made serializers for library integrators, taking care of backward compatibility when the model is updated, instead of pushing the work to integrators.
Initially I explored a json-based approach in branch [db-type-module](https://github.com/ACINQ/lightning-kmp/tree/db-type-module) (see module `lightning-kmp-db-types`). But it turned out to be tedious and verbose, with a lot of class definitions and boiler plate code to handle model migrations.
These binary codecs are much lighter to write and maintain, and probably faster (although it was not the main objective). The main drawbacks is that the serialized data is not human readable.
fun Output.writeNumber(o:Number): Unit=LightningCodecs.writeBigSize(o.toLong(), this)
13
+
14
+
fun Output.writeBoolean(o:Boolean): Unit=if (o) write(1) else write(0)
15
+
16
+
fun Output.writeString(o:String): Unit= writeDelimited(o.encodeToByteArray())
17
+
18
+
fun Output.writeByteVector32(o:ByteVector32) = write(o.toByteArray())
19
+
20
+
fun Output.writeByteVector64(o:ByteVector64) = write(o.toByteArray())
21
+
22
+
fun Output.writePublicKey(o:PublicKey) = write(o.value.toByteArray())
23
+
24
+
fun Output.writePrivateKey(o:PrivateKey) = write(o.value.toByteArray())
25
+
26
+
fun Output.writeTxId(o:TxId) = write(o.value.toByteArray())
27
+
28
+
fun Output.writeUuid(o:UUID) = o.run {
29
+
// NB: copied from kotlin source code (https://github.com/JetBrains/kotlin/blob/v2.1.0/libraries/stdlib/src/kotlin/uuid/Uuid.kt) in order to be forward compatible
30
+
fun Long.toByteArray(dst:ByteArray, dstOffset:Int) {
0 commit comments