From 775650c2d84f256e9f2c9088f17a466685573194 Mon Sep 17 00:00:00 2001 From: Dominik Werder Date: Wed, 4 May 2022 16:38:54 +0200 Subject: [PATCH] Support conversion from ca tags --- err/src/lib.rs | 6 ++++++ netpod/src/netpod.rs | 42 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/err/src/lib.rs b/err/src/lib.rs index 759c5e8..45efe48 100644 --- a/err/src/lib.rs +++ b/err/src/lib.rs @@ -295,6 +295,12 @@ impl From for Error { } } +impl From for Error { + fn from(k: std::str::Utf8Error) -> Self { + Self::with_msg(k.to_string()) + } +} + /* impl From> for Error { fn from(k: nom::Err) -> Self { diff --git a/netpod/src/netpod.rs b/netpod/src/netpod.rs index 98bde2f..2a6b961 100644 --- a/netpod/src/netpod.rs +++ b/netpod/src/netpod.rs @@ -80,7 +80,7 @@ impl ScalarType { 13 => STRING, //13 => return Err(Error::with_msg(format!("STRING not supported"))), 6 => return Err(Error::with_msg(format!("CHARACTER not supported"))), - _ => return Err(Error::with_msg(format!("unknown dtype code: {}", ix))), + _ => return Err(Error::with_msg(format!("unknown dtype code: {:?}", ix))), }; Ok(g) } @@ -122,7 +122,7 @@ impl ScalarType { "bool" => BOOL, _ => { return Err(Error::with_msg_no_trace(format!( - "from_bsread_str can not understand bsread {}", + "from_bsread_str can not understand bsread {:?}", s ))) } @@ -130,6 +130,26 @@ impl ScalarType { Ok(ret) } + pub fn from_ca_id(k: u16) -> Result { + use ScalarType::*; + let ret = match k { + 0 => STRING, + 1 => I16, + 2 => F32, + 3 => I16, + 4 => I8, + 5 => I32, + 6 => F64, + _ => { + return Err(Error::with_msg_no_trace(format!( + "from_ca_id can not understand {:?}", + k + ))) + } + }; + Ok(ret) + } + pub fn from_archeng_db_str(s: &str) -> Result { use ScalarType::*; let ret = match s { @@ -141,7 +161,7 @@ impl ScalarType { "F64" => F64, _ => { return Err(Error::with_msg_no_trace(format!( - "from_archeng_db_str can not understand {}", + "from_archeng_db_str can not understand {:?}", s ))) } @@ -678,6 +698,22 @@ impl Shape { Ok(res) } + pub fn from_ca_count(k: u16) -> Result { + if k == 0 { + Err(Error::with_public_msg_no_trace(format!( + "zero sized ca data count {k:?}" + ))) + } else if k == 1 { + Ok(Shape::Scalar) + } else if k <= 2048 { + Ok(Shape::Wave(k as u32)) + } else { + Err(Error::with_public_msg_no_trace(format!( + "too large ca data count {k:?}" + ))) + } + } + pub fn to_scylla_vec(&self) -> Vec { use Shape::*; match self {