Skip to content

Commit

Permalink
Removing Value + Encoding modifications (#179)
Browse files Browse the repository at this point in the history
* Removing Value + refactor Encoding (WIP)

* issue(encoding): removing ID enum

* issue(encoding): updating encoding list
  • Loading branch information
DariusIMP authored Aug 29, 2024
1 parent a2ebeb2 commit 0604b8a
Show file tree
Hide file tree
Showing 24 changed files with 312 additions and 428 deletions.
5 changes: 2 additions & 3 deletions examples/src/main/kotlin/io.zenoh/ZGet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import io.zenoh.protocol.into
import io.zenoh.query.QueryTarget
import io.zenoh.query.Reply
import io.zenoh.selector.intoSelector
import io.zenoh.value.Value
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.runBlocking
import java.time.Duration
Expand All @@ -38,15 +37,15 @@ class ZGet(private val emptyArgs: Boolean) : CliktCommand(
selector.intoSelector().onSuccess { selector ->
session.get(selector,
channel = Channel(),
value = payload?.let { Value(it) },
payload = payload?.into(),
target = target?.let { QueryTarget.valueOf(it.uppercase()) } ?: QueryTarget.BEST_MATCHING,
attachment = attachment?.into(),
timeout = Duration.ofMillis(timeout))
.onSuccess { channelReceiver ->
runBlocking {
for (reply in channelReceiver) {
when (reply) {
is Reply.Success -> println("Received ('${reply.sample.keyExpr}': '${reply.sample.value}')")
is Reply.Success -> println("Received ('${reply.sample.keyExpr}': '${reply.sample.payload}')")
is Reply.Error -> println("Received (ERROR: '${reply.error}')")
is Reply.Delete -> println("Received (DELETE '${reply.keyExpr}')")
}
Expand Down
7 changes: 3 additions & 4 deletions examples/src/main/kotlin/io.zenoh/ZPubThr.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ import com.github.ajalt.clikt.parameters.types.int
import com.github.ajalt.clikt.parameters.types.ulong
import io.zenoh.keyexpr.intoKeyExpr
import io.zenoh.prelude.CongestionControl
import io.zenoh.prelude.Encoding
import io.zenoh.prelude.Priority
import io.zenoh.prelude.QoS
import io.zenoh.value.Value
import io.zenoh.protocol.into

class ZPubThr(private val emptyArgs: Boolean) : CliktCommand(
help = "Zenoh Throughput example"
Expand All @@ -37,7 +36,7 @@ class ZPubThr(private val emptyArgs: Boolean) : CliktCommand(
for (i in 0..<payloadSize) {
data[i] = (i % 10).toByte()
}
val value = Value(data, Encoding(Encoding.ID.ZENOH_BYTES))
val payload = data.into()

val config = loadConfig(emptyArgs, configFile, connect, listen, noMulticastScouting, mode)

Expand All @@ -55,7 +54,7 @@ class ZPubThr(private val emptyArgs: Boolean) : CliktCommand(
val number = number.toLong()
println("Press CTRL-C to quit...")
while (true) {
pub.put(value).getOrThrow()
pub.put(payload).getOrThrow()
if (statsPrint) {
if (count < number) {
count++
Expand Down
2 changes: 1 addition & 1 deletion examples/src/main/kotlin/io.zenoh/ZPut.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ZPut(private val emptyArgs: Boolean) : CliktCommand(
session.use {
key.intoKeyExpr().onSuccess { keyExpr ->
keyExpr.use {
session.put(keyExpr, value, attachment = attachment?.into())
session.put(keyExpr, value.into(), attachment = attachment?.into())
.onSuccess { println("Putting Data ('$keyExpr': '$value')...") }
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/src/main/kotlin/io.zenoh/ZQueryable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package io.zenoh
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.*
import io.zenoh.keyexpr.intoKeyExpr
import io.zenoh.value.Value
import io.zenoh.protocol.into
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.runBlocking
import org.apache.commons.net.ntp.TimeStamp
Expand All @@ -36,11 +36,11 @@ class ZQueryable(private val emptyArgs: Boolean) : CliktCommand(
session.declareQueryable(keyExpr, Channel()).onSuccess { queryable ->
runBlocking {
for (query in queryable.receiver) {
val valueInfo = query.value?.let { value -> " with value '$value'" } ?: ""
val valueInfo = query.payload?.let { value -> " with value '$value'" } ?: ""
println(">> [Queryable] Received Query '${query.selector}' $valueInfo")
query.replySuccess(
keyExpr,
value = Value(value),
payload = value.into(),
timestamp = TimeStamp.getCurrentTime()
).onFailure { println(">> [Queryable ] Error sending reply: $it") }
}
Expand Down
3 changes: 1 addition & 2 deletions examples/src/main/kotlin/io.zenoh/ZSub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ZSub(private val emptyArgs: Boolean) : CliktCommand(
session.declareSubscriber(keyExpr, Channel()).onSuccess { subscriber ->
runBlocking {
for (sample in subscriber.receiver) {
println(">> [Subscriber] Received ${sample.kind} ('${sample.keyExpr}': '${sample.value}'" + "${
println(">> [Subscriber] Received ${sample.kind} ('${sample.keyExpr}': '${sample.payload}'" + "${
sample.attachment?.let {
", with attachment: $it"
} ?: ""
Expand Down Expand Up @@ -73,4 +73,3 @@ class ZSub(private val emptyArgs: Boolean) : CliktCommand(
}

fun main(args: Array<String>) = ZSub(args.isEmpty()).main(args)

Loading

0 comments on commit 0604b8a

Please sign in to comment.