Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

alignment(reply): aligning the Reply logic with the Rust api. #184

Merged
merged 2 commits into from
Sep 2, 2024

Conversation

DariusIMP
Copy link
Member

Replacing the reply logic from:

for (reply in channelReceiver) {
    when (reply) {
        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}')")
    }
}

to

 for (reply in channelReceiver) {
    reply.result.onSuccess { sample ->
        when (sample.kind) {
            SampleKind.PUT -> println("Received ('${sample.keyExpr}': '${sample.payload}')")
            SampleKind.DELETE -> println("Received (DELETE '${sample.keyExpr}')")
        }
    }.onFailure { error ->
        println("Received (ERROR: '${error.message}')")
    }
}

On Kotlin, the type of the error param from onFailure is always Throwable. With the changes introduced here, It can be downcasted into a ReplyError which allow accessing the payload as a ZBytes and the encoding.

For instance:

 for (reply in channelReceiver) {
    reply.result.onSuccess { sample ->
        when (sample.kind) {
            SampleKind.PUT -> println("Received ('${sample.keyExpr}': '${sample.payload}')")
            SampleKind.DELETE -> println("Received (DELETE '${sample.keyExpr}')")
        }
    }.onFailure { error ->
         error as ReplyError       
         println("Received (ERROR: '${error.payload}' with encoding '${error.encoding}')")
    }
}

@DariusIMP DariusIMP changed the base branch from dev/1.0.0 to main August 30, 2024 16:30
Copy link

PR missing one of the required labels: breaking-change bug dependencies documentation enhancement new feature internal

@DariusIMP DariusIMP added the release Part of the next release label Aug 30, 2024
Copy link

PR missing one of the required labels: breaking-change bug dependencies documentation enhancement new feature internal

@DariusIMP DariusIMP added the internal Changes not included in the changelog label Aug 30, 2024
Copy link
Member

@sashacmc sashacmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@fuzzypixelz fuzzypixelz merged commit 49bd15e into eclipse-zenoh:main Sep 2, 2024
7 of 9 checks passed
@DariusIMP DariusIMP deleted the api/fix-reply branch September 2, 2024 16:16
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
internal Changes not included in the changelog release Part of the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants