Support conversion from ca tags

This commit is contained in:
Dominik Werder
2022-05-04 16:38:54 +02:00
parent 165ddf316d
commit 775650c2d8
2 changed files with 45 additions and 3 deletions

View File

@@ -295,6 +295,12 @@ impl From<FromUtf8Error> for Error {
}
}
impl From<std::str::Utf8Error> for Error {
fn from(k: std::str::Utf8Error) -> Self {
Self::with_msg(k.to_string())
}
}
/*
impl<T: fmt::Debug> From<nom::Err<T>> for Error {
fn from(k: nom::Err<T>) -> Self {

View File

@@ -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<Self, Error> {
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<Self, Error> {
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<Self, Error> {
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<i32> {
use Shape::*;
match self {