Swtich to cbor.

This commit is contained in:
James Pace 2024-09-28 04:34:46 +00:00
parent 628250161c
commit 7ab2defe05
7 changed files with 38 additions and 287 deletions

251
Cargo.lock generated
View File

@ -462,27 +462,6 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "errno"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
dependencies = [
"errno-dragonfly",
"libc",
"winapi",
]
[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "event-listener"
version = "5.3.1"
@ -494,15 +473,6 @@ dependencies = [
"pin-project-lite",
]
[[package]]
name = "fastrand"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499"
dependencies = [
"instant",
]
[[package]]
name = "fixedbitset"
version = "0.4.2"
@ -700,12 +670,6 @@ dependencies = [
"allocator-api2",
]
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "hermit-abi"
version = "0.3.9"
@ -782,25 +746,6 @@ dependencies = [
"generic-array",
]
[[package]]
name = "instant"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if",
]
[[package]]
name = "io-lifetimes"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e"
dependencies = [
"libc",
"windows-sys 0.42.0",
]
[[package]]
name = "ipnetwork"
version = "0.20.0"
@ -816,15 +761,6 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c397ca3ea05ad509c4ec451fea28b4771236a376ca1c69fd5143aae0cf8f93c4"
[[package]]
name = "itertools"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
dependencies = [
"either",
]
[[package]]
name = "itertools"
version = "0.13.0"
@ -929,12 +865,6 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "292a948cd991e376cf75541fe5b97a1081d713c618b4f1b9500f8844e49eb565"
[[package]]
name = "linux-raw-sys"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
[[package]]
name = "lock_api"
version = "0.4.9"
@ -1005,12 +935,6 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "multimap"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a"
[[package]]
name = "nanorand"
version = "0.7.0"
@ -1390,16 +1314,6 @@ version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
[[package]]
name = "prettyplease"
version = "0.2.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba"
dependencies = [
"proc-macro2",
"syn 2.0.79",
]
[[package]]
name = "proc-macro2"
version = "1.0.86"
@ -1409,59 +1323,6 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "prost"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b0487d90e047de87f984913713b85c601c05609aad5b0df4b4573fbf69aa13f"
dependencies = [
"bytes",
"prost-derive",
]
[[package]]
name = "prost-build"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c1318b19085f08681016926435853bbf7858f9c082d0999b80550ff5d9abe15"
dependencies = [
"bytes",
"heck",
"itertools 0.10.5",
"log",
"multimap",
"once_cell",
"petgraph",
"prettyplease",
"prost",
"prost-types",
"regex",
"syn 2.0.79",
"tempfile",
]
[[package]]
name = "prost-derive"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5"
dependencies = [
"anyhow",
"itertools 0.10.5",
"proc-macro2",
"quote",
"syn 2.0.79",
]
[[package]]
name = "prost-types"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4759aa0d3a6232fb8dbdb97b61de2c20047c68aca932c7ed76da9d788508d670"
dependencies = [
"prost",
]
[[package]]
name = "quinn"
version = "0.11.5"
@ -1710,20 +1571,6 @@ dependencies = [
"nom",
]
[[package]]
name = "rustix"
version = "0.36.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fdebc4b395b7fbb9ab11e462e20ed9051e7b16e42d24042c776eca0ac81b03"
dependencies = [
"bitflags 1.3.2",
"errno",
"io-lifetimes",
"libc",
"linux-raw-sys",
"windows-sys 0.42.0",
]
[[package]]
name = "rustls"
version = "0.23.13"
@ -2140,19 +1987,6 @@ dependencies = [
"syn 2.0.79",
]
[[package]]
name = "tempfile"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95"
dependencies = [
"cfg-if",
"fastrand",
"redox_syscall 0.2.16",
"rustix",
"windows-sys 0.42.0",
]
[[package]]
name = "thiserror"
version = "1.0.37"
@ -2682,21 +2516,6 @@ dependencies = [
"windows_x86_64_msvc 0.36.1",
]
[[package]]
name = "windows-sys"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
dependencies = [
"windows_aarch64_gnullvm 0.42.0",
"windows_aarch64_msvc 0.42.0",
"windows_i686_gnu 0.42.0",
"windows_i686_msvc 0.42.0",
"windows_x86_64_gnu 0.42.0",
"windows_x86_64_gnullvm 0.42.0",
"windows_x86_64_msvc 0.42.0",
]
[[package]]
name = "windows-sys"
version = "0.52.0"
@ -2721,22 +2540,16 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm 0.52.6",
"windows_aarch64_gnullvm",
"windows_aarch64_msvc 0.52.6",
"windows_i686_gnu 0.52.6",
"windows_i686_gnullvm",
"windows_i686_msvc 0.52.6",
"windows_x86_64_gnu 0.52.6",
"windows_x86_64_gnullvm 0.52.6",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc 0.52.6",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
@ -2749,12 +2562,6 @@ version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
@ -2767,12 +2574,6 @@ version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
[[package]]
name = "windows_i686_gnu"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
@ -2791,12 +2592,6 @@ version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
[[package]]
name = "windows_i686_msvc"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
@ -2809,24 +2604,12 @@ version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
@ -2839,12 +2622,6 @@ version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
@ -2879,7 +2656,7 @@ dependencies = [
"flume",
"futures",
"git-version",
"itertools 0.13.0",
"itertools",
"json5",
"lazy_static",
"once_cell",
@ -2987,18 +2764,6 @@ dependencies = [
"zenoh-result",
]
[[package]]
name = "zenoh-exp"
version = "0.1.0"
dependencies = [
"ciborium",
"prost",
"prost-build",
"serde",
"tokio",
"zenoh",
]
[[package]]
name = "zenoh-keyexpr"
version = "1.0.0-dev"
@ -3325,6 +3090,16 @@ dependencies = [
"zenoh-result",
]
[[package]]
name = "zenoh_exp"
version = "0.1.0"
dependencies = [
"ciborium",
"serde",
"tokio",
"zenoh",
]
[[package]]
name = "zerocopy"
version = "0.7.35"

View File

@ -1,5 +1,5 @@
[package]
name = "zenoh-exp"
name = "zenoh_exp"
version = "0.1.0"
edition = "2018"
@ -8,9 +8,5 @@ edition = "2018"
[dependencies]
zenoh = { git="https://github.com/eclipse-zenoh/zenoh.git", branch = "main" }
tokio = { version = "1", features = ["full"] }
prost = { version = "0.13" }
ciborium = { version = "0.2" }
serde = { version = "1.0" }
[build-dependencies]
prost-build = { version = "0.13" }

View File

@ -1,9 +0,0 @@
use std::io::Result;
fn main() -> Result<()> {
let mut config = prost_build::Config::new();
config.type_attribute(".", "#[derive(serde::Serialize)]");
config.type_attribute(".", "#[derive(serde::Deserialize)]");
config.type_attribute(".", "#[serde(rename_all = \"camelCase\")]");
config.compile_protos(&["src/proto/parrot.proto"], &["src/proto"])?;
Ok(())
}

View File

@ -1,10 +1,4 @@
// Copyright James Pace 2022
use std::time::Duration;
use prost::Message;
pub mod j7s {
include!(concat!(env!("OUT_DIR"), "/j7s.parrot.rs"));
}
#[tokio::main]
async fn main() {
@ -13,18 +7,12 @@ async fn main() {
let publisher = session.declare_publisher("test").await.unwrap();
loop {
let mut message = j7s::Message::default();
let mut message = zenoh_exp::Message::default();
message.sender = "pub".to_string();
message.message = "Hi sub!".to_string();
publisher.put(encode(&message)).await.unwrap();
let mut buff: Vec<u8> = Vec::new();
let _ = ciborium::into_writer(&message, &mut buff).unwrap();
publisher.put(&buff).await.unwrap();
tokio::time::sleep(Duration::from_secs(1)).await;
}
}
fn encode(message: &j7s::Message) -> Vec<u8> {
let mut buf = Vec::new();
buf.reserve(message.encoded_len());
message.encode(&mut buf).unwrap();
buf
}

View File

@ -1,12 +1,3 @@
// Copyright James Pace 2022
use prost::Message;
use std::io::Cursor;
use std::borrow::Cow;
pub mod j7s {
include!(concat!(env!("OUT_DIR"), "/j7s.parrot.rs"));
}
#[tokio::main]
async fn main() {
let config = zenoh::Config::default();
@ -16,8 +7,8 @@ async fn main() {
loop {
let sample = subscriber.recv_async().await.unwrap();
let payload = sample.payload();
let bytes = payload.deserialize::<Cow<[u8]>>().unwrap();
let message = j7s::Message::decode(Cursor::new(bytes)).unwrap();
let bytes: Vec<u8> = payload.into();
let message: zenoh_exp::Message = ciborium::from_reader(&bytes[..]).unwrap();
println!(
"Kind: {} Key: {} Value: {:?}",

18
src/lib.rs Normal file
View File

@ -0,0 +1,18 @@
use serde::{Deserialize, Serialize};
use std::string::String;
// A request for a plan.
#[derive(Serialize, Deserialize, Debug)]
pub struct Message {
pub sender: String,
pub message: String,
}
impl Message {
pub fn default() -> Self {
Self {
sender: "".to_string(),
message: "".to_string(),
}
}
}

View File

@ -1,8 +0,0 @@
syntax = "proto3";
package j7s.parrot;
message Message {
string sender = 1;
string message = 2;
}