diff --git a/examples/src/main/kotlin/io.zenoh/ZBytes.kt b/examples/src/main/kotlin/io.zenoh/ZBytes.kt index 03130550d..7aace67a8 100644 --- a/examples/src/main/kotlin/io.zenoh/ZBytes.kt +++ b/examples/src/main/kotlin/io.zenoh/ZBytes.kt @@ -1,11 +1,8 @@ package io.zenoh -import io.zenoh.bytes.IntoZBytes -import io.zenoh.bytes.ZBytes -import io.zenoh.bytes.into -import java.nio.ByteBuffer -import java.nio.ByteOrder -import kotlin.reflect.typeOf +import io.zenoh.bytes.* +import io.zenoh.ext.zDeserialize +import io.zenoh.ext.zSerialize fun main() { @@ -16,23 +13,23 @@ fun main() { /** Numeric: byte, short, int, float, double */ val intInput = 1234 var payload = ZBytes.from(intInput) - var intOutput = payload.deserialize().getOrThrow() + var intOutput = zDeserialize(payload).getOrThrow() check(intInput == intOutput) // Alternatively you can serialize into the type. - payload = ZBytes.serialize(intInput).getOrThrow() - intOutput = payload.deserialize().getOrThrow() + payload = zSerialize(intInput).getOrThrow() + intOutput = zDeserialize(payload).getOrThrow() check(intInput == intOutput) // Alternatively, `Numeric.into()`: ZBytes can be used payload = intInput.into() - intOutput = payload.deserialize().getOrThrow() + intOutput = zDeserialize(payload).getOrThrow() check(intInput == intOutput) // Another example with float val floatInput = 3.1415f payload = ZBytes.from(floatInput) - val floatOutput = payload.deserialize().getOrThrow() + val floatOutput = zDeserialize(payload).getOrThrow() check(floatInput == floatOutput) /** String serialization and deserialization. */ @@ -41,7 +38,7 @@ fun main() { // Alternatively, you can also call `String.into()` to convert // a string into a ZBytes object: // payload = stringInput.into() - var stringOutput = payload.deserialize().getOrThrow() + var stringOutput = zDeserialize(payload).getOrThrow() check(stringInput == stringOutput) // For the case of strings, ZBytes::toString() is equivalent: @@ -51,7 +48,7 @@ fun main() { /** ByteArray serialization and deserialization. */ val byteArrayInput = "example".toByteArray() payload = ZBytes.from(byteArrayInput) // Equivalent to `byteArrayInput.into()` - var byteArrayOutput = payload.deserialize().getOrThrow() + var byteArrayOutput = zDeserialize(payload).getOrThrow() check(byteArrayInput.contentEquals(byteArrayOutput)) // Alternatively, we can directly access the bytes of property of ZBytes: byteArrayOutput = payload.toByteArray() @@ -62,18 +59,18 @@ fun main() { * Supported types: String, ByteArray, ZBytes, Byte, Short, Int, Long, Float and Double. */ val inputList = listOf("sample1", "sample2", "sample3") - payload = ZBytes.serialize(inputList).getOrThrow() - val outputList = payload.deserialize>().getOrThrow() + payload = zSerialize(inputList).getOrThrow() + val outputList = zDeserialize>(payload).getOrThrow() check(inputList == outputList) val inputListZBytes = inputList.map { value -> value.into() } - payload = ZBytes.serialize(inputListZBytes).getOrThrow() - val outputListZBytes = payload.deserialize>().getOrThrow() + payload = zSerialize(inputListZBytes).getOrThrow() + val outputListZBytes = zDeserialize>(payload).getOrThrow() check(inputListZBytes == outputListZBytes) val inputListByteArray = inputList.map { value -> value.toByteArray() } - payload = ZBytes.serialize(inputListByteArray).getOrThrow() - val outputListByteArray = payload.deserialize>().getOrThrow() + payload = zSerialize(inputListByteArray).getOrThrow() + val outputListByteArray = zDeserialize>(payload).getOrThrow() check(compareByteArrayLists(inputListByteArray, outputListByteArray)) /** @@ -82,13 +79,13 @@ fun main() { * Maps with the following Type combinations are supported: String, ByteArray, ZBytes, Byte, Short, Int, Long, Float and Double. */ val inputMap = mapOf("key1" to "value1", "key2" to "value2", "key3" to "value3") - payload = ZBytes.serialize(inputMap).getOrThrow() - val outputMap = payload.deserialize>().getOrThrow() + payload = zSerialize(inputMap).getOrThrow() + val outputMap = zDeserialize>(payload).getOrThrow() check(inputMap == outputMap) val combinedInputMap = mapOf("key1" to ZBytes.from("zbytes1"), "key2" to ZBytes.from("zbytes2")) - payload = ZBytes.serialize(combinedInputMap).getOrThrow() - val combinedOutputMap = payload.deserialize>().getOrThrow() + payload = zSerialize(combinedInputMap).getOrThrow() + val combinedOutputMap = zDeserialize>(payload).getOrThrow() check(combinedInputMap == combinedOutputMap) /********************************************* @@ -107,38 +104,23 @@ fun main() { * @see MyZBytes */ val inputMyZBytes = MyZBytes("example") - payload = ZBytes.serialize(inputMyZBytes).getOrThrow() + payload = zSerialize(inputMyZBytes).getOrThrow() val outputMyZBytes = MyZBytes.from(payload) check(inputMyZBytes == outputMyZBytes) /** List of MyZBytes. */ val inputListMyZBytes = inputList.map { value -> MyZBytes(value) } - payload = ZBytes.serialize>(inputListMyZBytes).getOrThrow() - val outputListMyZBytes = payload.deserialize>().getOrThrow().map { zbytes -> MyZBytes.from(zbytes) } + payload = zSerialize>(inputListMyZBytes).getOrThrow() + val outputListMyZBytes = zDeserialize>(payload).getOrThrow().map { zbytes -> MyZBytes.from(zbytes) } check(inputListMyZBytes == outputListMyZBytes) /** Map of MyZBytes. */ val inputMapMyZBytes = inputMap.map { (k, v) -> MyZBytes(k) to MyZBytes(v) }.toMap() - payload = ZBytes.serialize>(inputMapMyZBytes).getOrThrow() - val outputMapMyZBytes = payload.deserialize>().getOrThrow() + payload = zSerialize>(inputMapMyZBytes).getOrThrow() + val outputMapMyZBytes = zDeserialize>(payload).getOrThrow() .map { (key, value) -> MyZBytes.from(key) to MyZBytes.from(value) }.toMap() check(inputMapMyZBytes == outputMapMyZBytes) - /** - * Providing a map of deserializers. - * - * Alternatively, [ZBytes.deserialize] also accepts a deserializers parameter of type - * `Map>`. That is, a map of types that is associated - * to a function receiving a ByteArray, that returns Any. This way, you can provide a series - * of deserializer functions that extend the deserialization mechanisms we provide by default. - * - * For example, let's say we have a custom map serializer, with its own deserializer: - */ - val fooMap = mapOf(Foo("foo1") to Foo("bar1"), Foo("foo2") to Foo("bar2")) - val fooMapSerialized = ZBytes.from(serializeFooMap(fooMap)) - val deserializersMap = mapOf(typeOf>() to ::deserializeFooMap) - val deserializedFooMap = fooMapSerialized.deserialize>(deserializersMap).getOrThrow() - check(fooMap == deserializedFooMap) } data class MyZBytes(val content: String) : IntoZBytes { @@ -152,47 +134,6 @@ data class MyZBytes(val content: String) : IntoZBytes { } } -/** Example class for the deserialization map examples. */ -data class Foo(val content: String) - -/** Example serializer and deserializer. */ -private fun serializeFooMap(testMap: Map): ByteArray { - return testMap.map { - val key = it.key.content.toByteArray() - val keyLength = ByteBuffer.allocate(Int.SIZE_BYTES).order(ByteOrder.LITTLE_ENDIAN).putInt(key.size).array() - val value = it.value.content.toByteArray() - val valueLength = - ByteBuffer.allocate(Int.SIZE_BYTES).order(ByteOrder.LITTLE_ENDIAN).putInt(value.size).array() - keyLength + key + valueLength + value - }.reduce { acc, bytes -> acc + bytes } -} - -private fun deserializeFooMap(serializedMap: ZBytes): Map { - var idx = 0 - var sliceSize: Int - val bytes = serializedMap.toByteArray() - val decodedMap = mutableMapOf() - while (idx < bytes.size) { - sliceSize = ByteBuffer.wrap(bytes.sliceArray(IntRange(idx, idx + Int.SIZE_BYTES - 1))) - .order(ByteOrder.LITTLE_ENDIAN).int - idx += Int.SIZE_BYTES - - val key = bytes.sliceArray(IntRange(idx, idx + sliceSize - 1)) - idx += sliceSize - - sliceSize = ByteBuffer.wrap(bytes.sliceArray(IntRange(idx, idx + Int.SIZE_BYTES - 1))).order( - ByteOrder.LITTLE_ENDIAN - ).int - idx += Int.SIZE_BYTES - - val value = bytes.sliceArray(IntRange(idx, idx + sliceSize - 1)) - idx += sliceSize - - decodedMap[Foo(key.decodeToString())] = Foo(value.decodeToString()) - } - return decodedMap -} - /** Utils for this example. */ private fun compareByteArrayLists(list1: List, list2: List): Boolean { diff --git a/zenoh-jni/Cargo.lock b/zenoh-jni/Cargo.lock index bb8683468..96b19d02e 100644 --- a/zenoh-jni/Cargo.lock +++ b/zenoh-jni/Cargo.lock @@ -110,7 +110,7 @@ checksum = "965c2d33e53cb6b267e148a4cb0760bc01f4904c1cd4bb4002a085bb016d1490" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "synstructure", ] @@ -122,7 +122,7 @@ checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -133,13 +133,13 @@ checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" [[package]] name = "async-trait" -version = "0.1.82" +version = "0.1.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -155,9 +155,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "backtrace" @@ -239,9 +239,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "cache-padded" @@ -251,9 +251,9 @@ checksum = "981520c98f422fcc584dc1a95c334e6953900b9106bc47a9839b81790009eb21" [[package]] name = "cc" -version = "1.1.20" +version = "1.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45bcde016d64c21da4be18b655631e5ab6d3107607e71a73a9f53eb48aae23fb" +checksum = "812acba72f0a070b003d3697490d2b55b837230ae7c6c6497f05cc2ddbb8d938" dependencies = [ "shlex", ] @@ -477,7 +477,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -621,7 +621,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -700,7 +700,7 @@ checksum = "53010ccb100b96a67bc32c0175f0ed1426b31b655d562898e57325f81c023ac0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -771,9 +771,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.9.4" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] name = "humantime" @@ -933,11 +933,17 @@ dependencies = [ "spin", ] +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libloading" @@ -1172,9 +1178,12 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" +dependencies = [ + "portable-atomic", +] [[package]] name = "openssl-probe" @@ -1224,7 +1233,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.5.4", + "redox_syscall 0.5.7", "smallvec", "windows-targets 0.52.6", ] @@ -1252,9 +1261,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.12" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c73c26c01b8c87956cea613c907c9d6ecffd8d18a2a5908e5de0adfaa185cea" +checksum = "fdbef9d1d47087a895abd220ed25eb4ad973a5e26f6a4367b038c25e28dfc2d9" dependencies = [ "memchr", "thiserror", @@ -1263,9 +1272,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.7.12" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "664d22978e2815783adbdd2c588b455b1bd625299ce36b2a99881ac9627e6d8d" +checksum = "4d3a6e3394ec80feb3b6393c725571754c6188490265c61aaf260810d6b95aa0" dependencies = [ "pest", "pest_generator", @@ -1273,22 +1282,22 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.12" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2d5487022d5d33f4c30d91c22afa240ce2a644e87fe08caad974d4eab6badbe" +checksum = "94429506bde1ca69d1b5601962c73f4172ab4726571a59ea95931218cb0e930e" dependencies = [ "pest", "pest_meta", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "pest_meta" -version = "2.7.12" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0091754bbd0ea592c4deb3a122ce8ecbb0753b738aa82bc055fcc2eccc8d8174" +checksum = "ac8a071862e93690b6e34e9a5fb8e33ff3734473ac0245b27232222c4906a33f" dependencies = [ "once_cell", "pest", @@ -1335,7 +1344,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1364,7 +1373,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1432,6 +1441,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "portable-atomic" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" + [[package]] name = "powerfmt" version = "0.2.0" @@ -1555,9 +1570,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.4" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ "bitflags 2.6.0", ] @@ -1575,14 +1590,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.6" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.7", - "regex-syntax 0.8.4", + "regex-automata 0.4.8", + "regex-syntax 0.8.5", ] [[package]] @@ -1596,13 +1611,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.4", + "regex-syntax 0.8.5", ] [[package]] @@ -1613,9 +1628,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "ring" @@ -1734,19 +1749,18 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "2.1.3" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" dependencies = [ - "base64 0.22.1", "rustls-pki-types", ] [[package]] name = "rustls-pki-types" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" [[package]] name = "rustls-platform-verifier" @@ -1832,7 +1846,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1867,9 +1881,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.11.1" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" dependencies = [ "core-foundation-sys", "libc", @@ -1921,7 +1935,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1932,7 +1946,7 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2107,9 +2121,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.77" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -2124,7 +2138,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2144,22 +2158,22 @@ checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2251,7 +2265,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2312,7 +2326,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2403,9 +2417,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "ucd-trie" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" +checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" [[package]] name = "uhlc" @@ -2435,18 +2449,18 @@ checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-normalization" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" dependencies = [ "tinyvec", ] [[package]] name = "unicode-xid" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" [[package]] name = "unsafe-libyaml" @@ -2460,12 +2474,6 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" -[[package]] -name = "unwrap-infallible" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" - [[package]] name = "unzip-n" version = "0.1.2" @@ -2583,7 +2591,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-shared", ] @@ -2605,7 +2613,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2618,9 +2626,9 @@ checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "webpki-roots" -version = "0.26.5" +version = "0.26.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bd24728e5af82c6c4ec1b66ac4844bdf8156257fccda846ec58b42cd0cdbe6a" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" dependencies = [ "rustls-pki-types", ] @@ -2890,7 +2898,7 @@ dependencies = [ [[package]] name = "zenoh" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "ahash", "async-trait", @@ -2917,7 +2925,6 @@ dependencies = [ "tokio-util", "tracing", "uhlc", - "unwrap-infallible", "vec_map", "zenoh-buffers", "zenoh-codec", @@ -2940,7 +2947,7 @@ dependencies = [ [[package]] name = "zenoh-buffers" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "zenoh-collections", ] @@ -2948,7 +2955,7 @@ dependencies = [ [[package]] name = "zenoh-codec" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "tracing", "uhlc", @@ -2959,12 +2966,12 @@ dependencies = [ [[package]] name = "zenoh-collections" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" [[package]] name = "zenoh-config" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "json5", "num_cpus", @@ -2985,7 +2992,7 @@ dependencies = [ [[package]] name = "zenoh-core" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "lazy_static", "tokio", @@ -2996,7 +3003,7 @@ dependencies = [ [[package]] name = "zenoh-crypto" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "aes", "hmac", @@ -3009,11 +3016,12 @@ dependencies = [ [[package]] name = "zenoh-ext" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "bincode", "flume 0.11.0", "futures", + "leb128", "serde", "tokio", "tracing", @@ -3025,7 +3033,7 @@ dependencies = [ [[package]] name = "zenoh-keyexpr" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "hashbrown 0.14.5", "keyed-set", @@ -3039,7 +3047,7 @@ dependencies = [ [[package]] name = "zenoh-link" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "zenoh-config", "zenoh-link-commons", @@ -3056,7 +3064,7 @@ dependencies = [ [[package]] name = "zenoh-link-commons" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "async-trait", "flume 0.11.0", @@ -3079,7 +3087,7 @@ dependencies = [ [[package]] name = "zenoh-link-quic" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "async-trait", "base64 0.22.1", @@ -3104,7 +3112,7 @@ dependencies = [ [[package]] name = "zenoh-link-tcp" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "async-trait", "socket2", @@ -3121,7 +3129,7 @@ dependencies = [ [[package]] name = "zenoh-link-tls" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "async-trait", "base64 0.22.1", @@ -3148,7 +3156,7 @@ dependencies = [ [[package]] name = "zenoh-link-udp" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "async-trait", "socket2", @@ -3167,7 +3175,7 @@ dependencies = [ [[package]] name = "zenoh-link-unixsock_stream" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "async-trait", "nix", @@ -3185,7 +3193,7 @@ dependencies = [ [[package]] name = "zenoh-link-ws" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "async-trait", "futures-util", @@ -3205,18 +3213,18 @@ dependencies = [ [[package]] name = "zenoh-macros" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "zenoh-keyexpr", ] [[package]] name = "zenoh-plugin-trait" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "git-version", "libloading", @@ -3232,7 +3240,7 @@ dependencies = [ [[package]] name = "zenoh-protocol" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "const_format", "rand", @@ -3246,7 +3254,7 @@ dependencies = [ [[package]] name = "zenoh-result" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "anyhow", ] @@ -3254,7 +3262,7 @@ dependencies = [ [[package]] name = "zenoh-runtime" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "lazy_static", "ron", @@ -3267,7 +3275,7 @@ dependencies = [ [[package]] name = "zenoh-sync" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "event-listener", "futures", @@ -3280,7 +3288,7 @@ dependencies = [ [[package]] name = "zenoh-task" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "futures", "tokio", @@ -3293,7 +3301,7 @@ dependencies = [ [[package]] name = "zenoh-transport" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "async-trait", "crossbeam-utils", @@ -3326,7 +3334,7 @@ dependencies = [ [[package]] name = "zenoh-util" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#09d1d1d353b5fdc620ae61a925bd530676d34382" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#89efcce08fa7d3a50f520311b23308f175c8bd74" dependencies = [ "async-trait", "const_format", @@ -3384,7 +3392,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] diff --git a/zenoh-jni/Cargo.toml b/zenoh-jni/Cargo.toml index 447b67da0..a38606df3 100644 --- a/zenoh-jni/Cargo.toml +++ b/zenoh-jni/Cargo.toml @@ -24,7 +24,7 @@ description = "Zenoh: Zero Overhead Pub/sub, Store/Query and Compute." name = "zenoh_jni" [features] -default = ["zenoh/default", "zenoh-ext/default"] +default = ["zenoh/default", "zenoh-ext"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -36,8 +36,8 @@ flume = "0.10.14" uhlc = "0.8.0" json5 = "0.4.1" serde_yaml = "0.9.19" -zenoh = { version = "1.0.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", default-features = false } -zenoh-ext = { version = "1.0.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", default-features = false } +zenoh = { version = "1.0.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", features = ["unstable", "internal"], default-features = false } +zenoh-ext = { version = "1.0.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", default-features = false, optional = true } tracing = { version = "0.1" , features = ["log"] } [lib] name = "zenoh_jni" diff --git a/zenoh-jni/src/lib.rs b/zenoh-jni/src/lib.rs index 0b815ad66..6661ee551 100644 --- a/zenoh-jni/src/lib.rs +++ b/zenoh-jni/src/lib.rs @@ -23,6 +23,7 @@ mod scouting; mod session; mod subscriber; mod utils; +#[cfg(feature = "zenoh-ext")] mod zbytes; mod zenoh_id; diff --git a/zenoh-jni/src/utils.rs b/zenoh-jni/src/utils.rs index 36ed7449d..aa8d01769 100644 --- a/zenoh-jni/src/utils.rs +++ b/zenoh-jni/src/utils.rs @@ -119,13 +119,8 @@ pub(crate) fn decode_reliability(reliability: jint) -> ZResult { } pub(crate) fn bytes_to_java_array<'a>(env: &JNIEnv<'a>, slice: &ZBytes) -> ZResult> { - env.byte_array_from_slice( - slice - .deserialize::>() - .map_err(|err| zerror!("Unable to deserialize slice: {}", err))? - .as_ref(), - ) - .map_err(|err| zerror!(err)) + env.byte_array_from_slice(&slice.to_bytes()) + .map_err(|err| zerror!(err)) } pub(crate) fn slice_to_java_string<'a>(env: &JNIEnv<'a>, slice: &ZSlice) -> ZResult> { diff --git a/zenoh-jni/src/zbytes.rs b/zenoh-jni/src/zbytes.rs index aebf43fc2..978e0e448 100644 --- a/zenoh-jni/src/zbytes.rs +++ b/zenoh-jni/src/zbytes.rs @@ -20,6 +20,7 @@ use jni::{ JNIEnv, }; use zenoh::bytes::ZBytes; +use zenoh_ext::{z_deserialize, z_serialize}; use crate::{errors::ZResult, utils::bytes_to_java_array, zerror}; use crate::{throw_exception, utils::decode_byte_array}; @@ -64,7 +65,7 @@ fn java_map_to_zbytes(env: &mut JNIEnv, map: &JObject) -> jni::errors::Result jobject { || -> ZResult { let payload = decode_byte_array(&env, serialized_map)?; - let zbytes = ZBytes::new(payload); - let deserialization: HashMap, Vec> = zbytes - .deserialize::, Vec>>() - .map_err(|err| zerror!(err))?; + let zbytes = ZBytes::from(payload); + let deserialization: HashMap, Vec> = + z_deserialize(&zbytes).map_err(|err| zerror!(err))?; hashmap_to_java_map(&mut env, &deserialization).map_err(|err| zerror!(err)) }() .unwrap_or_else(|err| { @@ -154,7 +154,7 @@ fn java_list_to_zbytes(env: &mut JNIEnv, list: &JObject) -> jni::errors::Result< let value_bytes = env.convert_byte_array(value_bytes)?; rust_vec.push(value_bytes); } - let zbytes = ZBytes::from_iter(rust_vec); + let zbytes = z_serialize(&rust_vec); Ok(zbytes) } @@ -177,7 +177,7 @@ pub extern "C" fn Java_io_zenoh_jni_JNIZBytes_deserializeIntoListViaJNI( ) -> jobject { || -> ZResult { let payload = decode_byte_array(&env, serialized_list)?; - let zbytes = ZBytes::new(payload); + let zbytes = ZBytes::from(payload); zbytes_to_java_list(&mut env, &zbytes).map_err(|err| zerror!(err)) }() .unwrap_or_else(|err| { @@ -186,12 +186,17 @@ pub extern "C" fn Java_io_zenoh_jni_JNIZBytes_deserializeIntoListViaJNI( }) } -fn zbytes_to_java_list(env: &mut JNIEnv, zbytes: &ZBytes) -> jni::errors::Result { - let array_list = env.new_object("java/util/ArrayList", "()V", &[])?; - let jlist = JList::from_env(env, &array_list)?; - for value in zbytes.iter::>() { - let value = &mut env.byte_array_from_slice(value.unwrap().as_slice())?; //The unwrap is unfallible. - jlist.add(env, value)?; +fn zbytes_to_java_list(env: &mut JNIEnv, zbytes: &ZBytes) -> ZResult { + let array_list = env + .new_object("java/util/ArrayList", "()V", &[]) + .map_err(|err| zerror!(err))?; + let jlist = JList::from_env(env, &array_list).map_err(|err| zerror!(err))?; + let values: Vec> = z_deserialize(zbytes).map_err(|err| zerror!(err))?; + for value in values { + let value = &mut env + .byte_array_from_slice(&value) + .map_err(|err| zerror!(err))?; + jlist.add(env, value).map_err(|err| zerror!(err))?; } Ok(array_list.as_raw()) } diff --git a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/bytes/ZBytes.kt b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/bytes/ZBytes.kt index 1327fc1f4..3508e755f 100644 --- a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/bytes/ZBytes.kt +++ b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/bytes/ZBytes.kt @@ -15,14 +15,10 @@ package io.zenoh.bytes import io.zenoh.exceptions.ZError -import io.zenoh.jni.JNIZBytes import java.nio.ByteBuffer import java.nio.ByteOrder -import kotlin.reflect.KClass -import kotlin.reflect.KFunction1 import kotlin.reflect.KType import kotlin.reflect.full.* -import kotlin.reflect.jvm.jvmErasure import kotlin.reflect.typeOf /** @@ -57,7 +53,7 @@ import kotlin.reflect.typeOf * * using the serialize syntax: * ```kotlin * val exampleInt: Int = 256 - * val zbytes: ZBytes = ZBytes.serialize(exampleInt).getOrThrow() + * val zbytes: ZBytes = zSerialize(exampleInt).getOrThrow() * ``` * This approach works as well for the other mentioned types. * @@ -72,7 +68,7 @@ import kotlin.reflect.typeOf * The serialize syntax must be used: * ```kotlin * val myList = listOf(1, 2, 5, 8, 13, 21) - * val zbytes = ZBytes.serialize>(myList).getOrThrow() + * val zbytes = zSerialize>(myList).getOrThrow() * ``` * * ## Maps @@ -85,7 +81,7 @@ import kotlin.reflect.typeOf * * ```kotlin * val myMap: Map = mapOf("foo" to 1, "bar" to 2) - * val zbytes = ZBytes.serialize>(myMap).getOrThrow() + * val zbytes = zSerialize>(myMap).getOrThrow() * ``` * * # Deserialization @@ -118,7 +114,7 @@ import kotlin.reflect.typeOf * ```kotlin * val exampleInt: Int = 256 * val zbytes: ZBytes = exampleInt.into() - * val deserializedInt = zbytes.deserialize().getOrThrow() + * val deserializedInt = zDeserializeInt>(zbytes).getOrThrow() * ``` * * ## Lists @@ -131,8 +127,8 @@ import kotlin.reflect.typeOf * To deserialize into a list, we need to use the deserialize syntax as follows: * ```kotlin * val inputList = listOf("sample1", "sample2", "sample3") - * payload = ZBytes.serialize(inputList).getOrThrow() - * val outputList = payload.deserialize>().getOrThrow() + * payload = serialize(inputList).getOrThrow() + * val outputList = zDeserializeList>(payload).getOrThrow() * ``` * * ## Maps @@ -144,8 +140,8 @@ import kotlin.reflect.typeOf * * ```kotlin * val inputMap = mapOf("key1" to "value1", "key2" to "value2", "key3" to "value3") - * payload = ZBytes.serialize(inputMap).getOrThrow() - * val outputMap = payload.deserialize>().getOrThrow() + * payload = serialize(inputMap).getOrThrow() + * val outputMap = zDeserializeMap>(payload).getOrThrow() * check(inputMap == outputMap) * ``` * @@ -167,14 +163,14 @@ import kotlin.reflect.typeOf * This way, we can do: * ```kotlin * val foo = Foo("bar") - * val serialization = ZBytes.serialize(foo).getOrThrow() + * val serialization = zSerialize(foo).getOrThrow() * ``` * * Implementing the [IntoZBytes] interface on a class enables the possibility of serializing lists and maps * of that type, for instance: * ```kotlin * val list = listOf(Foo("bar"), Foo("buz"), Foo("fizz")) - * val zbytes = ZBytes.serialize>(list) + * val zbytes = zSerialize>(list) * ``` * * ## Deserialization @@ -187,42 +183,23 @@ import kotlin.reflect.typeOf * * ```kotlin * val inputFoo = Foo("example") - * payload = ZBytes.serialize(inputFoo).getOrThrow() + * payload = serialize(inputFoo).getOrThrow() * val outputFoo = Foo.from(payload) * check(inputFoo == outputFoo) * * // List of Foo. * val inputListFoo = inputList.map { value -> Foo(value) } - * payload = ZBytes.serialize>(inputListFoo).getOrThrow() - * val outputListFoo = payload.deserialize>().getOrThrow().map { zbytes -> Foo.from(zbytes) } + * payload = zSerialize>(inputListFoo).getOrThrow() + * val outputListFoo = zDeserializeList>(payload).getOrThrow().map { zbytes -> Foo.from(zbytes) } * check(inputListFoo == outputListFoo) * * // Map of Foo. * val inputMapFoo = inputMap.map { (k, v) -> Foo(k) to Foo(v) }.toMap() - * payload = ZBytes.serialize>(inputMapFoo).getOrThrow() - * val outputMapFoo = payload.deserialize>().getOrThrow() + * payload = zSerialize>(inputMapFoo).getOrThrow() + * val outputMapFoo = zDeserializeMap>(payload).getOrThrow() * .map { (key, value) -> Foo.from(key) to Foo.from(value) }.toMap() * check(inputMapFoo == outputMapFoo) * ``` - * - * ### Deserialization functions: - * - * The [deserialize] function admits an argument which by default is an emptyMap, consisting - * of a `Map>` map. This allows to specify types in a map, associating - * functions for deserialization for each of the types in the map. - * - * For instance, let's stick to the previous implementation of our example Foo class. - * We could provide directly the deserialization function as follows: - * - * ```kotlin - * fun deserializeFoo(zbytes: ZBytes): Foo { - * return Foo(zbytes.toString()) - * } - * - * val foo = Foo("bar") - * val zbytes = ZBytes.serialize(foo) - * val deserialization = zbytes.deserialize(mapOf(typeOf() to ::deserializeFoo)).getOrThrow() - * ``` */ class ZBytes internal constructor(internal val bytes: ByteArray) : IntoZBytes { @@ -263,178 +240,9 @@ class ZBytes internal constructor(internal val bytes: ByteArray) : IntoZBytes { return ZBytes(byteArray) } - /** - * Serialize an element of type [T] into a [ZBytes]. - * - * Supported types: - * - [Number]: Byte, Short, Int, Long, Float, Double - * - [String] - * - [ByteArray] - * - [IntoZBytes] - * - Lists and Maps of the above-mentioned types. - * - * @see ZBytes - * @return a [Result] with the serialized [ZBytes]. - */ - inline fun serialize(t: T): Result = runCatching { - return serialize(t, T::class) - } - - fun serialize(t: T, clazz: KClass): Result = runCatching { - val type: KType = when (clazz) { - List::class -> typeOf>() - Map::class -> typeOf>() - else -> clazz.createType() - } - when { - typeOf>().isSupertypeOf(type) -> { - val list = t as List<*> - val zbytesList = list.map { it.into() } - return Result.success(JNIZBytes.serializeIntoList(zbytesList)) - } - - typeOf>().isSupertypeOf(type) -> { - val map = t as Map<*, *> - val zbytesMap = map.map { (k, v) -> k.into() to v.into() }.toMap() - return Result.success(JNIZBytes.serializeIntoMap(zbytesMap)) - } - - typeOf().isSupertypeOf(type) -> { - return Result.success((t as Any).into()) - } - - else -> throw IllegalArgumentException("Unsupported type '$type' for serialization.") - } - } - } - - /** - * Deserialize the [ZBytes] instance into an element of type [T]. - * - * Supported types: - * - [Number]: Byte, Short, Int, Long, Float, Double - * - [String] - * - [ByteArray] - * - Lists and Maps of the above-mentioned types. - * - * - * A map of types and functions for deserialization can also be provided. - * - * For instance: - * ```kotlin - * fun deserializeFoo(zbytes: ZBytes): Foo { - * return Foo(zbytes.toString()) - * } - * - * val foo = Foo("bar") - * val zbytes = ZBytes.serialize(foo) - * val deserialization = zbytes.deserialize(mapOf(typeOf() to ::deserializeFoo)).getOrThrow() - * ``` - * - * In case the provided type isn't associated with any of the functions provided in the [deserializers] map - * (if provided), the deserialization will carry on with the default behavior. - * - * @see ZBytes - * @return a [Result] with the deserialization. - */ - inline fun deserialize( - deserializers: Map> = emptyMap() - ): Result { - val type = typeOf() - val deserializer = deserializers[type] - if (deserializer != null) { - return Result.success(deserializer(this) as T) - } - when { - typeOf>().isSupertypeOf(type) -> { - val itemsClass = type.arguments.firstOrNull()?.type?.jvmErasure - return deserialize(T::class, arg1clazz = itemsClass) - } - typeOf>().isSupertypeOf(type) -> { - val keyClass = type.arguments.getOrNull(0)?.type?.jvmErasure - val valueClass = type.arguments.getOrNull(1)?.type?.jvmErasure - return deserialize(T::class, arg1clazz = keyClass, arg2clazz = valueClass) - } - typeOf().isSupertypeOf(type) -> { - return deserialize(T::class) - } - } - throw IllegalArgumentException("Unsupported type for deserialization: '$type'.") - } - /** - * Deserialize the [ZBytes] into an element of class [clazz]. - * - * It's generally preferable to use the [ZBytes.deserialize] function with reification, however - * this function is exposed for cases when reification needs to be avoided. - * - * Example: - * ```kotlin - * val list = listOf("value1", "value2", "value3") - * val zbytes = ZBytes.serialize(list).getOrThrow() - * val deserializedList = zbytes.deserialize(clazz = List::class, arg1clazz = String::class).getOrThrow() - * check(list == deserializedList) - * ``` - * - * Supported types: - * - [Number]: Byte, Short, Int, Long, Float, Double - * - [String] - * - [ByteArray] - * - Lists and Maps of the above-mentioned types. - * - * @see [ZBytes.deserialize] - * - * - * @param clazz: the [KClass] of the type to be serialized. - * @param arg1clazz Optional first nested parameter of the provided clazz, for instance when trying to deserialize - * into a `List`, arg1clazz should be set to `String::class`, when trying to deserialize into a - * `Map`, arg1clazz should be set to `Int::class`. Can be null if providing a basic type. - * @param arg2clazz Optional second nested parameter of the provided clazz, to be used for the cases of maps. - * For instance, when trying to deserialize into a `Map`, arg2clazz should be set to `String::class`. - * Can be null if providing a basic type. - */ - @Suppress("UNCHECKED_CAST") - fun deserialize( - clazz: KClass, - arg1clazz: KClass<*>? = null, - arg2clazz: KClass<*>? = null, - ): Result { - val type: KType = when (clazz) { - List::class -> typeOf>() - Map::class -> typeOf>() - else -> clazz.createType() - } - return when { - typeOf>().isSupertypeOf(type) -> { - val typeElement = arg1clazz?.createType() - if (typeElement != null) { - Result.success(JNIZBytes.deserializeIntoList(this).map { it.intoAny(typeElement) } as T) - } else { - Result.failure(IllegalArgumentException("Unsupported list type for deserialization: $type")) - } - } - - typeOf>().isSupertypeOf(type) -> { - val keyType = arg1clazz?.createType() - val valueType = arg2clazz?.createType() - if (keyType != null && valueType != null) { - Result.success(JNIZBytes.deserializeIntoMap(this) - .map { (k, v) -> k.intoAny(keyType) to v.intoAny(valueType) }.toMap() as T - ) - } else { - Result.failure(IllegalArgumentException("Unsupported map type for deserialization: $type")) - } - } - - typeOf().isSupertypeOf(type) -> { - Result.success(this.intoAny(type) as T) - } - - else -> Result.failure(IllegalArgumentException("Unsupported type for deserialization: $type")) - } } - fun toByteArray() = bytes fun toByte(): Byte { diff --git a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/ext/ZDeserialize.kt b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/ext/ZDeserialize.kt new file mode 100644 index 000000000..e39a49681 --- /dev/null +++ b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/ext/ZDeserialize.kt @@ -0,0 +1,117 @@ +package io.zenoh.ext + +import io.zenoh.bytes.ZBytes +import io.zenoh.bytes.intoAny +import io.zenoh.jni.JNIZBytes +import kotlin.reflect.KClass +import kotlin.reflect.KFunction1 +import kotlin.reflect.KType +import kotlin.reflect.full.createType +import kotlin.reflect.full.isSupertypeOf +import kotlin.reflect.jvm.jvmErasure +import kotlin.reflect.typeOf + +/** + * Deserialize the [ZBytes] instance into an element of type [T]. + * + * Supported types: + * - [Number]: Byte, Short, Int, Long, Float, Double + * - [String] + * - [ByteArray] + * - Lists and Maps of the above-mentioned types. + * + * @see ZBytes + * @return a [Result] with the deserialization. + */ +inline fun zDeserialize(zbytes: ZBytes): Result { + val type = typeOf() + when { + typeOf>().isSupertypeOf(type) -> { + val itemsClass = type.arguments.firstOrNull()?.type?.jvmErasure + return zDeserialize(zbytes, T::class, arg1clazz = itemsClass) + } + typeOf>().isSupertypeOf(type) -> { + val keyClass = type.arguments.getOrNull(0)?.type?.jvmErasure + val valueClass = type.arguments.getOrNull(1)?.type?.jvmErasure + return zDeserialize(zbytes, T::class, arg1clazz = keyClass, arg2clazz = valueClass) + } + typeOf().isSupertypeOf(type) -> { + return zDeserialize(zbytes, T::class) + } + } + throw IllegalArgumentException("Unsupported type for deserialization: '$type'.") +} + +/** + * Deserialize the [ZBytes] into an element of class [clazz]. + * + * It's generally preferable to use the [zDeserialize] function with reification, however + * this function is exposed for cases when reification needs to be avoided. + * + * Example: + * ```kotlin + * val list = listOf("value1", "value2", "value3") + * val zbytes = serialize(list).getOrThrow() + * val deserializedList = deserialize(zbytes, clazz = List::class, arg1clazz = String::class).getOrThrow() + * check(list == deserializedList) + * ``` + * + * Supported types: + * - [Number]: Byte, Short, Int, Long, Float, Double + * - [String] + * - [ByteArray] + * - Lists and Maps of the above-mentioned types. + * + * @see [zDeserialize] + * + * + * @param clazz: the [KClass] of the type to be serialized. + * @param arg1clazz Optional first nested parameter of the provided clazz, for instance when trying to deserialize + * into a `List`, arg1clazz should be set to `String::class`, when trying to deserialize into a + * `Map`, arg1clazz should be set to `Int::class`. Can be null if providing a basic type. + * @param arg2clazz Optional second nested parameter of the provided clazz, to be used for the cases of maps. + * For instance, when trying to deserialize into a `Map`, arg2clazz should be set to `String::class`. + * Can be null if providing a basic type. + */ +@Suppress("UNCHECKED_CAST") +fun zDeserialize( + zbytes: ZBytes, + clazz: KClass, + arg1clazz: KClass<*>? = null, + arg2clazz: KClass<*>? = null, +): Result { + val type: KType = when (clazz) { + List::class -> typeOf>() + Map::class -> typeOf>() + else -> clazz.createType() + } + return when { + typeOf>().isSupertypeOf(type) -> { + val typeElement = arg1clazz?.createType() + if (typeElement != null) { + Result.success(JNIZBytes.deserializeIntoList(zbytes).map { it.intoAny(typeElement) } as T) + } else { + Result.failure(IllegalArgumentException("Unsupported list type for deserialization: $type")) + } + } + + typeOf>().isSupertypeOf(type) -> { + val keyType = arg1clazz?.createType() + val valueType = arg2clazz?.createType() + if (keyType != null && valueType != null) { + Result.success( + JNIZBytes.deserializeIntoMap(zbytes) + .map { (k, v) -> k.intoAny(keyType) to v.intoAny(valueType) }.toMap() as T + ) + } else { + Result.failure(IllegalArgumentException("Unsupported map type for deserialization: $type")) + } + } + + typeOf().isSupertypeOf(type) -> { + Result.success(zbytes.intoAny(type) as T) + } + + else -> Result.failure(IllegalArgumentException("Unsupported type for deserialization: $type")) + } +} diff --git a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/ext/ZSerialize.kt b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/ext/ZSerialize.kt new file mode 100644 index 000000000..71a0a3243 --- /dev/null +++ b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/ext/ZSerialize.kt @@ -0,0 +1,54 @@ +package io.zenoh.ext + +import io.zenoh.bytes.ZBytes +import io.zenoh.bytes.into +import io.zenoh.jni.JNIZBytes +import kotlin.reflect.KClass +import kotlin.reflect.KType +import kotlin.reflect.full.createType +import kotlin.reflect.full.isSupertypeOf +import kotlin.reflect.typeOf + +/** + * Serialize an element of type [T] into a [ZBytes]. + * + * Supported types: + * - [Number]: Byte, Short, Int, Long, Float, Double + * - [String] + * - [ByteArray] + * - [IntoZBytes] + * - Lists and Maps of the above-mentioned types. + * + * @see ZBytes + * @return a [Result] with the serialized [ZBytes]. + */ +inline fun zSerialize(t: T): Result = runCatching { + return zSerialize(t, T::class) +} + +fun zSerialize(t: T, clazz: KClass): Result = runCatching { + val type: KType = when (clazz) { + List::class -> typeOf>() + Map::class -> typeOf>() + else -> clazz.createType() + } + when { + typeOf>().isSupertypeOf(type) -> { + val list = t as List<*> + val zbytesList = list.map { it.into() } + return Result.success(JNIZBytes.serializeIntoList(zbytesList)) + } + + typeOf>().isSupertypeOf(type) -> { + val map = t as Map<*, *> + val zbytesMap = map.map { (k, v) -> k.into() to v.into() }.toMap() + return Result.success(JNIZBytes.serializeIntoMap(zbytesMap)) + } + + typeOf().isSupertypeOf(type) -> { + return Result.success((t as Any).into()) + } + + else -> throw IllegalArgumentException("Unsupported type '$type' for serialization.") + } +} diff --git a/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/UserAttachmentTest.kt b/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/UserAttachmentTest.kt index 25355564b..98cb0eda2 100644 --- a/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/UserAttachmentTest.kt +++ b/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/UserAttachmentTest.kt @@ -17,6 +17,7 @@ package io.zenoh import io.zenoh.keyexpr.KeyExpr import io.zenoh.keyexpr.intoKeyExpr import io.zenoh.bytes.ZBytes +import io.zenoh.ext.zDeserialize import io.zenoh.bytes.into import io.zenoh.config.Config import io.zenoh.query.Reply @@ -79,7 +80,7 @@ class UserAttachmentTest { assertNotNull(receivedSample) { val receivedAttachment = it.attachment!! - assertEquals(attachment, receivedAttachment.deserialize().getOrNull()) + assertEquals(attachment, zDeserialize(receivedAttachment).getOrNull()) } } diff --git a/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/ZBytesTest.kt b/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/ZBytesTest.kt index bfc98b173..44c0b509e 100644 --- a/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/ZBytesTest.kt +++ b/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/ZBytesTest.kt @@ -15,7 +15,9 @@ package io.zenoh import io.zenoh.bytes.ZBytes +import io.zenoh.ext.zDeserialize import io.zenoh.bytes.into +import io.zenoh.ext.zSerialize import org.junit.jupiter.api.Assertions.assertArrayEquals import org.junit.jupiter.api.Assertions.assertEquals @@ -175,8 +177,8 @@ class ZBytesTests { val originalItem = testCase.originalItem val clazz = testCase.clazz - val bytes = ZBytes.serialize(originalItem, clazz = clazz).getOrThrow() - val deserializedItem = bytes.deserialize(clazz = clazz).getOrThrow() + val bytes = zSerialize(originalItem, clazz = clazz).getOrThrow() + val deserializedItem = zDeserialize(bytes, clazz = clazz).getOrThrow() if (originalItem is ByteArray) { assertArrayEquals(originalItem, deserializedItem as ByteArray) @@ -191,9 +193,9 @@ class ZBytesTests { val originalList = testCase.originalList val itemClass = testCase.itemclazz - val bytes = ZBytes.serialize(originalList).getOrThrow() + val bytes = zSerialize(originalList).getOrThrow() - val deserializedList = bytes.deserialize(clazz = List::class, arg1clazz = itemClass).getOrThrow() + val deserializedList = zDeserialize(bytes, clazz = List::class, arg1clazz = itemClass).getOrThrow() if (originalList.isNotEmpty() && originalList[0] is ByteArray) { originalList.forEachIndexed { index, value -> @@ -211,9 +213,10 @@ class ZBytesTests { val keyClass = testCase.keyclazz val valueClass = testCase.valueclazz - val bytes = ZBytes.serialize(originalMap).getOrThrow() + val bytes = zSerialize(originalMap).getOrThrow() - val deserializedMap = bytes.deserialize( + val deserializedMap = zDeserialize( + bytes, clazz = Map::class, arg1clazz = keyClass, arg2clazz = valueClass @@ -243,48 +246,10 @@ class ZBytesTests { assertEquals(originalMap, deserializedMap) } - @Test - fun deserializationWithMapOfDeserializationFunctionsTest() { - val stringMap = mapOf("key1" to "value1", "key2" to "value2") - val zbytesMap = stringMap.map { (k, v) -> k.into() to v.into() }.toMap() - val zbytesListOfPairs = stringMap.map { (k, v) -> k.into() to v.into() } - val intMap = mapOf(1 to 10, 2 to 20, 3 to 30) - val zbytesList = listOf(1.into(), 2.into(), 3.into()) - - val serializedBytes = serializeZBytesMap(zbytesMap) - - val customDeserializers = mapOf( - typeOf>() to ::deserializeIntoZBytesMap, - typeOf>() to ::deserializeIntoStringMap, - typeOf>() to ::deserializeIntoIntMap, - typeOf>() to ::deserializeIntoZBytesList, - typeOf>>() to ::deserializeIntoListOfPairs, - ) - - val deserializedMap = serializedBytes.deserialize>(customDeserializers).getOrThrow() - assertEquals(zbytesMap, deserializedMap) - - val deserializedMap2 = serializedBytes.deserialize>(customDeserializers).getOrThrow() - assertEquals(stringMap, deserializedMap2) - - val intMapBytes = serializeIntoIntMap(intMap) - val deserializedMap3 = intMapBytes.deserialize>(customDeserializers).getOrThrow() - assertEquals(intMap, deserializedMap3) - - val serializedZBytesList = serializeZBytesList(zbytesList) - val deserializedList = serializedZBytesList.deserialize>(customDeserializers).getOrThrow() - assertEquals(zbytesList, deserializedList) - - val serializedZBytesPairList = serializeZBytesMap(zbytesListOfPairs.toMap()) - val deserializedZBytesPairList = - serializedZBytesPairList.deserialize>>(customDeserializers).getOrThrow() - assertEquals(zbytesListOfPairs, deserializedZBytesPairList) - } - /** - * A series of tests to verify the correct functioning of the [ZBytes.deserialize] function. + * A series of tests to verify the correct functioning of the [zDeserialize] function. * - * The [ZBytes.deserialize] function with reification can not be tested in a parametrized fashion because + * The [zDeserialize] function with reification can not be tested in a parametrized fashion because * it uses reified parameters which causes the testing framework (designed for Java) to fail to properly * set up the tests. */ @@ -297,64 +262,51 @@ class ZBytesTests { /** Numeric: byte, short, int, float, double */ val intInput = 1234 var payload = ZBytes.from(intInput) - val intOutput = payload.deserialize().getOrThrow() + val intOutput = zDeserialize(payload).getOrThrow() assertEquals(intInput, intOutput) // Another example with float val floatInput = 3.1415f payload = ZBytes.from(floatInput) - val floatOutput = payload.deserialize().getOrThrow() + val floatOutput = zDeserialize(payload).getOrThrow() assertEquals(floatInput, floatOutput) /** String serialization and deserialization. */ val stringInput = "example" payload = ZBytes.from(stringInput) - val stringOutput = payload.deserialize().getOrThrow() + val stringOutput = zDeserialize(payload).getOrThrow() assertEquals(stringInput, stringOutput) /** ByteArray serialization and deserialization. */ val byteArrayInput = "example".toByteArray() payload = ZBytes.from(byteArrayInput) // Equivalent to `byteArrayInput.into()` - val byteArrayOutput = payload.deserialize().getOrThrow() + val byteArrayOutput = zDeserialize(payload).getOrThrow() assertTrue(byteArrayInput.contentEquals(byteArrayOutput)) val inputList = listOf("sample1", "sample2", "sample3") - payload = ZBytes.serialize(inputList).getOrThrow() - val outputList = payload.deserialize>().getOrThrow() + payload = zSerialize(inputList).getOrThrow() + val outputList = zDeserialize>(payload).getOrThrow() assertEquals(inputList, outputList) val inputListZBytes = inputList.map { value -> value.into() } - payload = ZBytes.serialize(inputListZBytes).getOrThrow() - val outputListZBytes = payload.deserialize>().getOrThrow() + payload = zSerialize(inputListZBytes).getOrThrow() + val outputListZBytes = zDeserialize>(payload).getOrThrow() assertEquals(inputListZBytes, outputListZBytes) val inputListByteArray = inputList.map { value -> value.toByteArray() } - payload = ZBytes.serialize(inputListByteArray).getOrThrow() - val outputListByteArray = payload.deserialize>().getOrThrow() + payload = zSerialize(inputListByteArray).getOrThrow() + val outputListByteArray = zDeserialize>(payload).getOrThrow() assertTrue(compareByteArrayLists(inputListByteArray, outputListByteArray)) val inputMap = mapOf("key1" to "value1", "key2" to "value2", "key3" to "value3") - payload = ZBytes.serialize(inputMap).getOrThrow() - val outputMap = payload.deserialize>().getOrThrow() + payload = zSerialize(inputMap).getOrThrow() + val outputMap = zDeserialize>(payload).getOrThrow() assertEquals(inputMap, outputMap) val combinedInputMap = mapOf("key1" to ZBytes.from("zbytes1"), "key2" to ZBytes.from("zbytes2")) - payload = ZBytes.serialize(combinedInputMap).getOrThrow() - val combinedOutputMap = payload.deserialize>().getOrThrow() + payload = zSerialize(combinedInputMap).getOrThrow() + val combinedOutputMap = zDeserialize>(payload).getOrThrow() assertEquals(combinedInputMap, combinedOutputMap) - - /********************************************* - * Custom serialization and deserialization. * - *********************************************/ - - /** - * Providing a map of deserializers. - */ - val fooMap = mapOf(Foo("foo1") to Foo("bar1"), Foo("foo2") to Foo("bar2")) - val fooMapSerialized = ZBytes.from(serializeFooMap(fooMap)) - val deserializersMap = mapOf(typeOf>() to ::deserializeFooMap) - val deserializedFooMap = fooMapSerialized.deserialize>(deserializersMap).getOrThrow() - assertEquals(fooMap, deserializedFooMap) } /***************** @@ -480,7 +432,7 @@ class ZBytesTests { private fun deserializeIntoIntMap(serializerMap: ZBytes): Map { return deserializeIntoZBytesMap(serializerMap).map { (k, v) -> - k.deserialize().getOrThrow() to v.deserialize().getOrThrow() + zDeserialize(k).getOrThrow() to zDeserialize(v).getOrThrow() }.toMap() }