Fix warnings
This commit is contained in:
@@ -9,12 +9,10 @@ serde = { version = "1", features = ["derive"] }
|
|||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
humantime-serde = "1.1"
|
humantime-serde = "1.1"
|
||||||
chrono = { version = "0.4.26", features = ["serde"] }
|
chrono = { version = "0.4.26", features = ["serde"] }
|
||||||
bytes = "1.8"
|
bytes = "1.10"
|
||||||
byteorder = "1.4"
|
byteorder = "1.4"
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
nom = "7.1.3"
|
nom = "7.1.3"
|
||||||
|
autoerr = "0.0.3"
|
||||||
daqbuf-err = { path = "../daqbuf-err" }
|
daqbuf-err = { path = "../daqbuf-err" }
|
||||||
netpod = { path = "../daqbuf-netpod", package = "daqbuf-netpod" }
|
netpod = { path = "../daqbuf-netpod", package = "daqbuf-netpod" }
|
||||||
|
|
||||||
[patch.crates-io]
|
|
||||||
thiserror = { git = "https://github.com/dominikwerder/thiserror.git", branch = "cstm" }
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use crate::channelconfig::CompressionMethod;
|
use crate::channelconfig::CompressionMethod;
|
||||||
use crate::nom;
|
use crate::nom;
|
||||||
use daqbuf_err as err;
|
|
||||||
use netpod::log::*;
|
use netpod::log::*;
|
||||||
use netpod::ScalarType;
|
use netpod::ScalarType;
|
||||||
use netpod::Shape;
|
use netpod::Shape;
|
||||||
@@ -132,7 +131,11 @@ pub struct Api1ChannelHeader {
|
|||||||
byte_order: Api1ByteOrder,
|
byte_order: Api1ByteOrder,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
shape: Vec<u32>,
|
shape: Vec<u32>,
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none", with = "serde_compression_method")]
|
#[serde(
|
||||||
|
default,
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
with = "serde_compression_method"
|
||||||
|
)]
|
||||||
compression: Option<CompressionMethod>,
|
compression: Option<CompressionMethod>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +204,10 @@ mod serde_compression_method {
|
|||||||
match v {
|
match v {
|
||||||
0 => Ok(None),
|
0 => Ok(None),
|
||||||
1 => Ok(Some(CompressionMethod::BitshuffleLZ4)),
|
1 => Ok(Some(CompressionMethod::BitshuffleLZ4)),
|
||||||
_ => Err(de::Error::unknown_variant("compression variant index", &["0"])),
|
_ => Err(de::Error::unknown_variant(
|
||||||
|
"compression variant index",
|
||||||
|
&["0"],
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -264,7 +270,12 @@ fn basic_header_ser_01() {
|
|||||||
};
|
};
|
||||||
let js = serde_json::to_string(&h).unwrap();
|
let js = serde_json::to_string(&h).unwrap();
|
||||||
let vals = serde_json::from_str::<serde_json::Value>(&js).unwrap();
|
let vals = serde_json::from_str::<serde_json::Value>(&js).unwrap();
|
||||||
let x = vals.as_object().unwrap().get("compression").unwrap().as_i64();
|
let x = vals
|
||||||
|
.as_object()
|
||||||
|
.unwrap()
|
||||||
|
.get("compression")
|
||||||
|
.unwrap()
|
||||||
|
.as_i64();
|
||||||
assert_eq!(x, Some(1))
|
assert_eq!(x, Some(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,14 +295,16 @@ fn basic_header_deser_01() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic_header_deser_02() {
|
fn basic_header_deser_02() {
|
||||||
let js = r#"{ "name": "ch1", "type": "float64", "byteOrder": "LITTLE_ENDIAN", "compression": 0 }"#;
|
let js =
|
||||||
|
r#"{ "name": "ch1", "type": "float64", "byteOrder": "LITTLE_ENDIAN", "compression": 0 }"#;
|
||||||
let h: Api1ChannelHeader = serde_json::from_str(js).unwrap();
|
let h: Api1ChannelHeader = serde_json::from_str(js).unwrap();
|
||||||
assert!(h.compression.is_none());
|
assert!(h.compression.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic_header_deser_03() {
|
fn basic_header_deser_03() {
|
||||||
let js = r#"{ "name": "ch1", "type": "float64", "byteOrder": "LITTLE_ENDIAN", "compression": 1 }"#;
|
let js =
|
||||||
|
r#"{ "name": "ch1", "type": "float64", "byteOrder": "LITTLE_ENDIAN", "compression": 1 }"#;
|
||||||
let h: Api1ChannelHeader = serde_json::from_str(js).unwrap();
|
let h: Api1ChannelHeader = serde_json::from_str(js).unwrap();
|
||||||
assert!(h.compression.is_some());
|
assert!(h.compression.is_some());
|
||||||
assert_eq!(h.compression, Some(CompressionMethod::BitshuffleLZ4));
|
assert_eq!(h.compression, Some(CompressionMethod::BitshuffleLZ4));
|
||||||
@@ -299,7 +312,8 @@ fn basic_header_deser_03() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic_header_deser_04() {
|
fn basic_header_deser_04() {
|
||||||
let js = r#"{ "name": "ch1", "type": "float64", "byteOrder": "LITTLE_ENDIAN", "compression": 2 }"#;
|
let js =
|
||||||
|
r#"{ "name": "ch1", "type": "float64", "byteOrder": "LITTLE_ENDIAN", "compression": 2 }"#;
|
||||||
let res = serde_json::from_str::<Api1ChannelHeader>(js);
|
let res = serde_json::from_str::<Api1ChannelHeader>(js);
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
}
|
}
|
||||||
@@ -354,7 +368,7 @@ pub enum Api1Frame {
|
|||||||
Data(Data),
|
Data(Data),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fail_on_input<'a, T, E>(inp: &'a [u8]) -> Nres<T, E>
|
fn fail_on_input<'a, T, E>(inp: &'a [u8]) -> Nres<'a, T, E>
|
||||||
where
|
where
|
||||||
E: ParseError<&'a [u8]>,
|
E: ParseError<&'a [u8]>,
|
||||||
{
|
{
|
||||||
@@ -362,7 +376,7 @@ where
|
|||||||
IResult::Err(Err::Failure(e))
|
IResult::Err(Err::Failure(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn header<'a, E>(inp: &'a [u8]) -> Nres<Header, E>
|
fn header<'a, E>(inp: &'a [u8]) -> Nres<'a, Header, E>
|
||||||
where
|
where
|
||||||
E: ParseError<&'a [u8]> + ContextError<&'a [u8]>,
|
E: ParseError<&'a [u8]> + ContextError<&'a [u8]>,
|
||||||
{
|
{
|
||||||
@@ -380,12 +394,14 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn data<'a, E>(inp: &'a [u8]) -> Nres<Data, E>
|
fn data<'a, E>(inp: &'a [u8]) -> Nres<'a, Data, E>
|
||||||
where
|
where
|
||||||
E: ParseError<&'a [u8]>,
|
E: ParseError<&'a [u8]>,
|
||||||
{
|
{
|
||||||
if inp.len() < 16 {
|
if inp.len() < 16 {
|
||||||
IResult::Err(Err::Incomplete(Needed::Size(NonZeroUsize::new(16).unwrap())))
|
IResult::Err(Err::Incomplete(Needed::Size(
|
||||||
|
NonZeroUsize::new(16).unwrap(),
|
||||||
|
)))
|
||||||
} else {
|
} else {
|
||||||
let (inp, ts) = be_u64(inp)?;
|
let (inp, ts) = be_u64(inp)?;
|
||||||
let (inp, pulse) = be_u64(inp)?;
|
let (inp, pulse) = be_u64(inp)?;
|
||||||
@@ -396,7 +412,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn api1_frame_complete<'a, E>(inp: &'a [u8]) -> Nres<Api1Frame, E>
|
fn api1_frame_complete<'a, E>(inp: &'a [u8]) -> Nres<'a, Api1Frame, E>
|
||||||
where
|
where
|
||||||
E: ParseError<&'a [u8]> + ContextError<&'a [u8]>,
|
E: ParseError<&'a [u8]> + ContextError<&'a [u8]>,
|
||||||
{
|
{
|
||||||
@@ -423,14 +439,17 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn api1_frame<'a, E>(inp: &'a [u8]) -> Nres<Api1Frame, E>
|
fn api1_frame<'a, E>(inp: &'a [u8]) -> Nres<'a, Api1Frame, E>
|
||||||
where
|
where
|
||||||
E: ParseError<&'a [u8]> + ContextError<&'a [u8]>,
|
E: ParseError<&'a [u8]> + ContextError<&'a [u8]>,
|
||||||
{
|
{
|
||||||
let inp_orig = inp;
|
let inp_orig = inp;
|
||||||
let (inp, len) = be_u32(inp)?;
|
let (inp, len) = be_u32(inp)?;
|
||||||
if len < 1 {
|
if len < 1 {
|
||||||
IResult::Err(Err::Failure(ParseError::from_error_kind(inp, ErrorKind::Fail)))
|
IResult::Err(Err::Failure(ParseError::from_error_kind(
|
||||||
|
inp,
|
||||||
|
ErrorKind::Fail,
|
||||||
|
)))
|
||||||
} else {
|
} else {
|
||||||
if inp.len() < len as usize + 4 {
|
if inp.len() < len as usize + 4 {
|
||||||
let e = Err::Incomplete(Needed::Size(NonZeroUsize::new(len as _).unwrap()));
|
let e = Err::Incomplete(Needed::Size(NonZeroUsize::new(len as _).unwrap()));
|
||||||
@@ -439,7 +458,10 @@ where
|
|||||||
let (inp, payload) = nom::bytes::complete::take(len)(inp)?;
|
let (inp, payload) = nom::bytes::complete::take(len)(inp)?;
|
||||||
let (inp, len2) = be_u32(inp)?;
|
let (inp, len2) = be_u32(inp)?;
|
||||||
if len != len2 {
|
if len != len2 {
|
||||||
IResult::Err(Err::Failure(ParseError::from_error_kind(inp_orig, ErrorKind::Fail)))
|
IResult::Err(Err::Failure(ParseError::from_error_kind(
|
||||||
|
inp_orig,
|
||||||
|
ErrorKind::Fail,
|
||||||
|
)))
|
||||||
} else {
|
} else {
|
||||||
let (left, res) = api1_frame_complete(payload)?;
|
let (left, res) = api1_frame_complete(payload)?;
|
||||||
if left.len() != 0 {
|
if left.len() != 0 {
|
||||||
@@ -452,7 +474,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn api1_frames<'a, E>(inp: &'a [u8]) -> Nres<Vec<Api1Frame>, E>
|
pub fn api1_frames<'a, E>(inp: &'a [u8]) -> Nres<'a, Vec<Api1Frame>, E>
|
||||||
where
|
where
|
||||||
E: ParseError<&'a [u8]> + ContextError<&'a [u8]>,
|
E: ParseError<&'a [u8]> + ContextError<&'a [u8]>,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,13 +2,10 @@ use daqbuf_err as err;
|
|||||||
use err::*;
|
use err::*;
|
||||||
use netpod::log::*;
|
use netpod::log::*;
|
||||||
use netpod::range::evrange::NanoRange;
|
use netpod::range::evrange::NanoRange;
|
||||||
use netpod::timeunits::DAY;
|
|
||||||
use netpod::timeunits::MS;
|
use netpod::timeunits::MS;
|
||||||
use netpod::ByteOrder;
|
use netpod::ByteOrder;
|
||||||
use netpod::DtNano;
|
use netpod::DtNano;
|
||||||
use netpod::NodeConfigCached;
|
|
||||||
use netpod::ScalarType;
|
use netpod::ScalarType;
|
||||||
use netpod::SfDbChannel;
|
|
||||||
use netpod::Shape;
|
use netpod::Shape;
|
||||||
use netpod::TsNano;
|
use netpod::TsNano;
|
||||||
use nom::bytes::complete::take;
|
use nom::bytes::complete::take;
|
||||||
@@ -21,21 +18,20 @@ use nom::Needed;
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
#[derive(Debug, ThisError)]
|
autoerr::create_error_v1!(
|
||||||
#[cstm(name = "ConfigParse")]
|
name(ConfigParseError, "ConfigParse"),
|
||||||
pub enum ConfigParseError {
|
enum variants {
|
||||||
NotSupportedOnNode,
|
NotSupportedOnNode,
|
||||||
FileNotFound,
|
FileNotFound,
|
||||||
#[error("PermissionDenied({0:?})")]
|
PermissionDenied(String),
|
||||||
PermissionDenied(PathBuf),
|
IO,
|
||||||
IO,
|
ParseError(String),
|
||||||
ParseError(String),
|
NotSupported,
|
||||||
NotSupported,
|
},
|
||||||
}
|
);
|
||||||
|
|
||||||
impl<T: fmt::Debug> From<nom::Err<T>> for ConfigParseError {
|
impl<T: fmt::Debug> From<nom::Err<T>> for ConfigParseError {
|
||||||
fn from(k: nom::Err<T>) -> Self {
|
fn from(k: nom::Err<T>) -> Self {
|
||||||
@@ -239,24 +235,24 @@ pub fn parse_entry(inp: &[u8]) -> NRes<Option<ConfigEntry>> {
|
|||||||
pulse,
|
pulse,
|
||||||
ks,
|
ks,
|
||||||
bs,
|
bs,
|
||||||
split_count: split_count,
|
split_count,
|
||||||
status,
|
status,
|
||||||
bb,
|
bb,
|
||||||
modulo,
|
modulo,
|
||||||
offset,
|
offset,
|
||||||
precision,
|
precision,
|
||||||
scalar_type,
|
scalar_type,
|
||||||
is_compressed: is_compressed,
|
is_compressed,
|
||||||
is_array: is_array,
|
is_array,
|
||||||
is_shaped: is_shaped,
|
is_shaped,
|
||||||
byte_order,
|
byte_order,
|
||||||
compression_method: compression_method,
|
compression_method,
|
||||||
shape,
|
shape,
|
||||||
source_name: source_name,
|
source_name,
|
||||||
unit,
|
unit,
|
||||||
description,
|
description,
|
||||||
optional_fields: optional_fields,
|
optional_fields,
|
||||||
value_converter: value_converter,
|
value_converter,
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user