From 3731e64bb30a457d6e55a307a8c061594a0a889c Mon Sep 17 00:00:00 2001 From: Darius Maitia Date: Fri, 27 Sep 2024 17:34:09 -0300 Subject: [PATCH] serialization: updating zbytes kdoc --- .../kotlin/io/zenoh/bytes/ZBytes.kt | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) 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 2149253e9..bd77d3e7c 100644 --- a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/bytes/ZBytes.kt +++ b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/bytes/ZBytes.kt @@ -57,7 +57,7 @@ import kotlin.reflect.typeOf * * using the serialize syntax: * ```kotlin * val exampleInt: Int = 256 - * val zbytes: ZBytes = ZBytes.serialize(exampleInt).getOrThrow() + * val zbytes: ZBytes = serialize(exampleInt).getOrThrow() * ``` * This approach works as well for the other mentioned types. * @@ -72,7 +72,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 = serialize>(myList).getOrThrow() * ``` * * ## Maps @@ -85,7 +85,7 @@ import kotlin.reflect.typeOf * * ```kotlin * val myMap: Map = mapOf("foo" to 1, "bar" to 2) - * val zbytes = ZBytes.serialize>(myMap).getOrThrow() + * val zbytes = serialize>(myMap).getOrThrow() * ``` * * # Deserialization @@ -118,7 +118,7 @@ import kotlin.reflect.typeOf * ```kotlin * val exampleInt: Int = 256 * val zbytes: ZBytes = exampleInt.into() - * val deserializedInt = zbytes.deserialize().getOrThrow() + * val deserializedInt = deserialize(zbytes).getOrThrow() * ``` * * ## Lists @@ -131,8 +131,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 = deserialize>(payload).getOrThrow() * ``` * * ## Maps @@ -144,8 +144,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 = deserialize>(payload).getOrThrow() * check(inputMap == outputMap) * ``` * @@ -167,14 +167,14 @@ import kotlin.reflect.typeOf * This way, we can do: * ```kotlin * val foo = Foo("bar") - * val serialization = ZBytes.serialize(foo).getOrThrow() + * val serialization = serialize(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 = serialize>(list) * ``` * * ## Deserialization @@ -187,20 +187,20 @@ 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 = serialize>(inputListFoo).getOrThrow() + * val outputListFoo = deserialize>(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 = serialize>(inputMapFoo).getOrThrow() + * val outputMapFoo = deserialize>(payload).getOrThrow() * .map { (key, value) -> Foo.from(key) to Foo.from(value) }.toMap() * check(inputMapFoo == outputMapFoo) * ``` @@ -220,8 +220,8 @@ import kotlin.reflect.typeOf * } * * val foo = Foo("bar") - * val zbytes = ZBytes.serialize(foo) - * val deserialization = zbytes.deserialize(mapOf(typeOf() to ::deserializeFoo)).getOrThrow() + * val zbytes = serialize(foo) + * val deserialization = deserialize(zbytes, mapOf(typeOf() to ::deserializeFoo)).getOrThrow() * ``` */ class ZBytes internal constructor(internal val bytes: ByteArray) : IntoZBytes {