Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat!: support multiple arguments to the payload #384

Merged
merged 3 commits into from
Dec 11, 2023

Conversation

ctrlaltf24
Copy link
Collaborator

Added new payload variant called Text to support multiple arguments encoded in JSON. The old Payload::String is deprecated, and will be removed shortly. Use Payload::from(String) to mimic old behavior

Built on top of @SalahaldinBilal 's work #379

Also fixed running doc tests in the devcontainer

Added new payload variant to support multiple arguments.
The old Payload::String is deprecated, and will be removed shortly.

Also fixed running doc tests in the devcontainer
@ctrlaltf24 ctrlaltf24 requested a review from 1c3t3a December 5, 2023 18:05
Copy link

codecov bot commented Dec 5, 2023

Codecov Report

Attention: 15 lines in your changes are missing coverage. Please review.

Comparison is base (38f20fc) 90.78% compared to head (25e6e1a) 91.39%.

Files Patch % Lines
socketio/src/client/raw_client.rs 74.35% 10 Missing ⚠️
socketio/src/asynchronous/client/client.rs 89.18% 4 Missing ⚠️
socketio/src/packet.rs 99.03% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #384      +/-   ##
==========================================
+ Coverage   90.78%   91.39%   +0.61%     
==========================================
  Files          37       37              
  Lines        4708     4837     +129     
==========================================
+ Hits         4274     4421     +147     
+ Misses        434      416      -18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@1c3t3a 1c3t3a left a comment

Choose a reason for hiding this comment

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

LGTM, just nits! Thanks a lot Nathan :)

Do you think we still need the other PR? Probably we could just use this one, right?

@@ -14,8 +14,11 @@ async fn main() {
let callback = |payload: Payload, socket: Client| {
async move {
match payload {
Payload::String(str) => println!("Received: {}", str),
Payload::Text(values) => println!("Received: {:?}", values),
Copy link
Owner

Choose a reason for hiding this comment

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

nit: maybe switch formatting to {:#?} to be consistent with how we format bytes in the next line?

@@ -11,8 +11,11 @@ fn main() {
// socket to communicate with the server
let handle_test = |payload: Payload, socket: RawClient| {
match payload {
Payload::String(str) => println!("Received string: {}", str),
Payload::Text(text) => println!("Received json: {:?}", text),
Copy link
Owner

Choose a reason for hiding this comment

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

nit: maybe switch formatting to {:#?} to be consistent with how we format bytes in the next line?

Payload::String(str) => println!("Received: {}", str),
Payload::Text(text) => println!("Received json: {:?}", text),
Copy link
Owner

Choose a reason for hiding this comment

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

nit: Same as the others, maybe switch to {:#?}?

@@ -48,8 +48,10 @@ impl ClientBuilder {
/// let callback = |payload: Payload, socket: Client| {
/// async move {
/// match payload {
/// Payload::String(str) => println!("Received: {}", str),
/// Payload::Text(values) => println!("Received: {:?}", values),
Copy link
Owner

Choose a reason for hiding this comment

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

nit: same as the others

@@ -112,8 +114,10 @@ impl ClientBuilder {
/// .on("test", |payload: Payload, _| {
/// async move {
/// match payload {
/// Payload::String(str) => println!("Received: {}", str),
/// Payload::Binary(bin_data) => println!("Received bytes: {:#?}", bin_data),
/// Payload::Text(values) => println!("Received: {:?}", values),
Copy link
Owner

Choose a reason for hiding this comment

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

nit: same

@@ -456,6 +457,8 @@ mod test {
.on("test", |msg, _| {
async {
match msg {
Payload::Text(values) => println!("Received json: {:?}", values),
Copy link
Owner

Choose a reason for hiding this comment

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

nit: same. Note to myself: we really do format that a lot...

println!("Ack data: {}", str);
if let Payload::Text(json) = message {
println!("Received json Ack");
println!("Ack data: {:?}", json);
Copy link
Owner

Choose a reason for hiding this comment

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

nit: same

if let Payload::String(str) = payload {
println!("{event}: {str}");
if let Payload::Text(values) = payload {
println!("{event}: {values:?}");
Copy link
Owner

Choose a reason for hiding this comment

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

nit: same

/// Returns a packet for a payload, could be used for both binary and non binary
/// events and acks. Convenience method.
#[inline]
pub(crate) fn new_from_payload<'a>(
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe just name it new?
We take way more than just the payload to create it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There's a different new with args down here:

pub const fn new(

Copy link
Owner

Choose a reason for hiding this comment

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

Ack!

socketio/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Owner

@1c3t3a 1c3t3a left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks :)

@1c3t3a 1c3t3a merged commit e253f9e into 1c3t3a:main Dec 11, 2023
4 checks passed
shenjackyuanjie added a commit to shenjackyuanjie/rust-socketio that referenced this pull request Dec 11, 2023
shenjackyuanjie added a commit to shenjackyuanjie/rust-socketio that referenced this pull request Dec 11, 2023
shenjackyuanjie added a commit to shenjackyuanjie/rust-socketio that referenced this pull request Dec 11, 2023
@ctrlaltf24 ctrlaltf24 deleted the switch-to-serde-json-payload branch December 11, 2023 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants