Skip to content

Commit

Permalink
Remove KnownEncoding enum and replace it with consts
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets committed Feb 16, 2024
1 parent f09fcc2 commit 3f901b5
Show file tree
Hide file tree
Showing 14 changed files with 302 additions and 249 deletions.
49 changes: 49 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ libloading = "0.8"
log = "0.4.17"
lz4_flex = "0.11"
nix = { version = "0.27", features = ["fs"] }
num_cpus = "1.15.0"
num_cpus = "1.16.0"
ordered-float = "4.1.1"
panic-message = "0.3.0"
paste = "1.0.12"
petgraph = "0.6.3"
phf = { version = "0.11.2", features = ["macros"] }
pnet = "0.34"
pnet_datalink = "0.34"
proc-macro2 = "1.0.51"
Expand Down
10 changes: 5 additions & 5 deletions commons/zenoh-codec/src/core/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use zenoh_buffers::{
reader::{DidntRead, Reader},
writer::{DidntWrite, Writer},
};
use zenoh_protocol::core::Encoding;
use zenoh_protocol::core::{Encoding, EncodingPrefix};

impl LCodec<&Encoding> for Zenoh080 {
fn w_len(self, x: &Encoding) -> usize {
Expand All @@ -32,8 +32,8 @@ where
type Output = Result<(), DidntWrite>;

fn write(self, writer: &mut W, x: &Encoding) -> Self::Output {
let zodec = Zenoh080Bounded::<u8>::new();
zodec.write(&mut *writer, *x.prefix() as u8)?;
let zodec = Zenoh080Bounded::<EncodingPrefix>::new();
zodec.write(&mut *writer, x.prefix())?;
zodec.write(&mut *writer, x.suffix())?;
Ok(())
}
Expand All @@ -46,8 +46,8 @@ where
type Error = DidntRead;

fn read(self, reader: &mut R) -> Result<Encoding, Self::Error> {
let zodec = Zenoh080Bounded::<u8>::new();
let prefix: u8 = zodec.read(&mut *reader)?;
let zodec = Zenoh080Bounded::<EncodingPrefix>::new();
let prefix: EncodingPrefix = zodec.read(&mut *reader)?;
let suffix: String = zodec.read(&mut *reader)?;
let encoding = Encoding::new(prefix, suffix).map_err(|_| DidntRead)?;
Ok(encoding)
Expand Down
1 change: 1 addition & 0 deletions commons/zenoh-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ complete_n = []
const_format = { workspace = true }
hex = { workspace = true, features = ["alloc"] }
rand = { workspace = true, features = ["alloc", "getrandom"], optional = true }
phf = { workspace = true }
serde = { workspace = true, features = ["alloc"] }
uhlc = { workspace = true, default-features = false }
uuid = { workspace = true } # Needs a getrandom::getrandom() custom implementation on embedded (in root crate)
Expand Down
2 changes: 1 addition & 1 deletion commons/zenoh-protocol/src/core/cowstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ enum CowStrInner<'a> {
}
pub struct CowStr<'a>(CowStrInner<'a>);
impl<'a> CowStr<'a> {
pub(crate) fn borrowed(s: &'a str) -> Self {
pub(crate) const fn borrowed(s: &'a str) -> Self {
Self(CowStrInner::Borrowed(s))
}
pub fn as_str(&self) -> &str {
Expand Down
Loading

0 comments on commit 3f901b5

Please sign in to comment.