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

Implement B64 encode payload #1

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ zenoh-ts/esm/
zenoh-plugin-remote-api/target/**
zenoh-plugin-remote-api/bindings/**
**/target/**
**/node_modules/**
**/node_modules/**
**/dist/**
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions zenoh-plugin-remote-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ tokio-tungstenite = "0.23.1"
tokio-rustls = { version = "0.26.0", default-features = false }
futures-util = "0.3.26"
rustls-pemfile = "2.1.2"

base64 = "0.22.1"
flume = "0.11"
futures = "0.3.5"
git-version = "0.3.5"
Expand All @@ -55,7 +55,7 @@ ts-rs = { version = "9.0", features = [
"serde-compat",
"uuid-impl",
"serde-json-impl",
"no-serde-warnings"
"no-serde-warnings",
] }
tracing = "0.1"
schemars = { version = "0.8.12", features = ["either"] }
Expand Down
39 changes: 34 additions & 5 deletions zenoh-plugin-remote-api/src/handle_control_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,18 @@ pub(crate) async fn handle_control_message(
add_if_some!(priority, get_builder);
add_if_some!(express, get_builder);
add_if_some!(encoding, get_builder);
add_if_some!(payload, get_builder);
add_if_some!(attachment, get_builder);
if let Some(payload_b64) = payload {
match payload_b64.b64_to_bytes() {
Ok(payload) => get_builder = get_builder.payload(payload),
Err(err) => warn!("Could not decode B64 encoded bytes {err}"),
}
}
if let Some(attachment_b64) = attachment {
match attachment_b64.b64_to_bytes() {
Ok(attachment) => get_builder = get_builder.attachment(attachment),
Err(err) => warn!("Could not decode B64 encoded bytes {err}"),
}
}

match handler {
HandlerChannel::Fifo(size) => {
Expand Down Expand Up @@ -130,12 +140,26 @@ pub(crate) async fn handle_control_message(
express,
attachment,
} => {
let mut put_builder = state_map.session.put(key_expr, payload);
let mut put_builder = match payload.b64_to_bytes() {
Ok(payload) => state_map.session.put(key_expr, payload),
Err(err) => {
warn!("ControlMsg::Put , could not decode B64 encoded bytes {err}");
return Ok(None);
}
};

add_if_some!(encoding, put_builder);
add_if_some!(congestion_control, put_builder);
add_if_some!(priority, put_builder);
add_if_some!(express, put_builder);
add_if_some!(attachment, put_builder);

if let Some(attachment_b64) = attachment {
match attachment_b64.b64_to_bytes() {
Ok(attachment) => put_builder = put_builder.attachment(attachment),
Err(err) => warn!("Could not decode B64 encoded bytes {err}"),
}
}

put_builder.await?;
}
ControlMsg::Delete {
Expand All @@ -149,7 +173,12 @@ pub(crate) async fn handle_control_message(
add_if_some!(congestion_control, delete_builder);
add_if_some!(priority, delete_builder);
add_if_some!(express, delete_builder);
add_if_some!(attachment, delete_builder);
if let Some(attachment_b64) = attachment {
match attachment_b64.b64_to_bytes() {
Ok(attachment) => delete_builder = delete_builder.attachment(attachment),
Err(err) => warn!("Could not decode B64 encoded bytes {err}"),
}
}

delete_builder.await?;
}
Expand Down
37 changes: 32 additions & 5 deletions zenoh-plugin-remote-api/src/handle_data_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,24 @@ pub async fn handle_data_message(
encoding,
} => {
if let Some(publisher) = state_map.publishers.get(&id) {
let mut put_builder = publisher.put(payload);
if let Some(payload) = attachment {
put_builder = put_builder.attachment(payload);
let mut put_builder = match payload.b64_to_bytes() {
Ok(payload) => publisher.put(payload),
Err(err) => {
warn!("DataMsg::PublisherPut : Could not decode B64 encoded bytes {err}");
return Err(Box::new(err));
}
};

if let Some(attachment_b64) = attachment {
match attachment_b64.b64_to_bytes() {
Ok(payload) => put_builder = put_builder.attachment(payload),
Err(err) => {
warn!(
"DataMsg::PublisherPut : Could not decode B64 encoded bytes {err}"
);
return Err(Box::new(err));
}
}
}
if let Some(encoding) = encoding {
put_builder = put_builder.encoding(encoding);
Expand All @@ -59,9 +74,21 @@ pub async fn handle_data_message(
if let Some(q) = query {
match reply.result {
QueryReplyVariant::Reply { key_expr, payload } => {
q.reply(key_expr, payload).await?
match payload.b64_to_bytes() {
Ok(payload) => q.reply(key_expr, payload).await?,
Err(err) => {
warn!("QueryReplyVariant::Reply : Could not decode B64 encoded bytes {err}");
return Err(Box::new(err));
}
}
}
QueryReplyVariant::ReplyErr { payload } => q.reply_err(payload).await?,
QueryReplyVariant::ReplyErr { payload } => match payload.b64_to_bytes() {
Ok(payload) => q.reply_err(payload).await?,
Err(err) => {
warn!("QueryReplyVariant::Reply : Could not decode B64 encoded bytes {err}");
return Err(Box::new(err));
}
},
QueryReplyVariant::ReplyDelete { key_expr } => {
q.reply_del(key_expr).await?
}
Expand Down
Loading
Loading