fix: update parser api usages after refactoring
This commit is contained in:
parent
264177e9c9
commit
71e3b90a0b
3 changed files with 27 additions and 24 deletions
|
@ -52,8 +52,8 @@ impl Hash for SensorValue {
|
|||
/// Функция-помощник для [MacAsArray], предназначенный для использования с [serde_with].
|
||||
///
|
||||
/// Преобразует MAC-адрес.
|
||||
fn mac_as_array(value: &str) -> Result<[u8; 6], Error<&str>> {
|
||||
Ok(parse_mac_address(value)?.1)
|
||||
fn mac_as_array(value: &str) -> Result<[u8; 6], Error> {
|
||||
parse_mac_address(value.as_bytes())
|
||||
}
|
||||
|
||||
serde_with::serde_conv!(
|
||||
|
|
|
@ -17,8 +17,9 @@ fn test_asd() {
|
|||
#ALT#38
|
||||
##
|
||||
"#
|
||||
.trim();
|
||||
let packet = parse_packet(asd).unwrap().1;
|
||||
.trim()
|
||||
.as_bytes();
|
||||
let packet = parse_packet(asd).unwrap();
|
||||
assert!(serde_json::to_string_pretty(&packet)
|
||||
.unwrap()
|
||||
.contains(r#""time": 1000000.0"#));
|
||||
|
@ -27,8 +28,8 @@ fn test_asd() {
|
|||
#[test]
|
||||
fn test_mac() {
|
||||
assert_eq!(
|
||||
parse_mac_address("12-34-AA-12-55-AA").unwrap(),
|
||||
("", [18, 52, 170, 18, 85, 170])
|
||||
parse_mac_address(b"12-34-Aa-1255-fA").unwrap(),
|
||||
[18, 52, 170, 18, 85, 250],
|
||||
);
|
||||
|
||||
dbg!(Epoch::now().unwrap().to_unix_seconds());
|
||||
|
@ -45,7 +46,7 @@ fn test_packet() {
|
|||
#T2#1.2#3400005345
|
||||
##"#;
|
||||
|
||||
println!("{:#?}", parse_packet(inp));
|
||||
println!("{:#?}", parse_packet(inp.as_bytes()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -19,31 +19,29 @@ pub enum QSParserError {
|
|||
#[snafu(display("asd"))]
|
||||
SerdeQS {
|
||||
#[snafu(source(from(serde_qs::Error, convert_to_arc::<serde_qs::Error>)))]
|
||||
source: Arc<serde_qs::Error>
|
||||
source: Arc<serde_qs::Error>,
|
||||
},
|
||||
#[snafu(display("asd"))]
|
||||
Parsing {
|
||||
context: String
|
||||
},
|
||||
Parsing { context: String },
|
||||
|
||||
#[snafu(display("asd"))]
|
||||
FloatP {
|
||||
#[snafu(source)]
|
||||
source: ParseFloatError
|
||||
source: ParseFloatError,
|
||||
},
|
||||
|
||||
#[snafu(display("failed to parse into decimal"))]
|
||||
DecimalParse {
|
||||
source: rust_decimal::Error
|
||||
},
|
||||
DecimalParse { source: rust_decimal::Error },
|
||||
|
||||
#[snafu(display("asd"))]
|
||||
NoMAC,
|
||||
}
|
||||
|
||||
impl From<Error<&str>> for QSParserError {
|
||||
fn from(value: Error<&str>) -> Self {
|
||||
QSParserError::Parsing { context: format!("{:?}", value)}
|
||||
impl From<Error> for QSParserError {
|
||||
fn from(value: Error) -> Self {
|
||||
QSParserError::Parsing {
|
||||
context: format!("{:?}", value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,7 +80,9 @@ pub fn parse_decimal_if_exists(
|
|||
key: &str,
|
||||
) -> Result<Option<Decimal>, QSParserError> {
|
||||
if let Some(unwrapped_value) = parsed.remove(key) {
|
||||
Ok(Some(Decimal::from_str(unwrapped_value.as_str()).context(DecimalParseSnafu{})?))
|
||||
Ok(Some(
|
||||
Decimal::from_str(unwrapped_value.as_str()).context(DecimalParseSnafu {})?,
|
||||
))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
|
@ -93,7 +93,9 @@ pub fn parse_epoch_if_exists(
|
|||
key: &str,
|
||||
) -> Result<Option<Epoch>, QSParserError> {
|
||||
if let Some(unwrapped_value) = parsed.remove(key) {
|
||||
Ok(Some(Epoch::from_unix_seconds(unwrapped_value.parse().context(FloatPSnafu{})?)))
|
||||
Ok(Some(Epoch::from_unix_seconds(
|
||||
unwrapped_value.parse().context(FloatPSnafu {})?,
|
||||
)))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
|
@ -102,8 +104,8 @@ pub fn parse_epoch_if_exists(
|
|||
pub async fn parse_nm_qs_format(input: &str) -> Result<NMDeviceDataPacket, QSParserError> {
|
||||
let mut parsed: HashMap<String, String> = serde_qs::from_str(input).context(SerdeQSSnafu {})?;
|
||||
|
||||
let (_, device_mac) = if let Some(id) = parsed.get("ID") {
|
||||
parse_mac_address(id)?
|
||||
let device_mac = if let Some(id) = parsed.get("ID") {
|
||||
parse_mac_address(id.as_bytes())?
|
||||
} else {
|
||||
return Err(QSParserError::NoMAC);
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue