style: clippy format
This commit is contained in:
parent
b0f3343a27
commit
65a00c69ec
12 changed files with 61 additions and 61 deletions
|
@ -1,6 +1,6 @@
|
||||||
use bstr::BStr;
|
|
||||||
use nom::error::VerboseError;
|
use nom::error::VerboseError;
|
||||||
use std::fmt::{Debug, Display};
|
use std::fmt::{Debug};
|
||||||
use std::num::ParseFloatError;
|
use std::num::ParseFloatError;
|
||||||
use thiserror::Error as ThisError;
|
use thiserror::Error as ThisError;
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
use crate::hashes::SupportedUnit;
|
use crate::hashes::SupportedUnit;
|
||||||
use crate::ingest_protocol::error::Error;
|
use crate::ingest_protocol::error::Error;
|
||||||
use crate::ingest_protocol::parser::parse_mac_address;
|
use crate::ingest_protocol::parser::parse_mac_address;
|
||||||
use bstr::BStr;
|
|
||||||
use hifitime::Epoch;
|
use hifitime::Epoch;
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::formats::Separator;
|
use serde_with::formats::Separator;
|
||||||
use serde_with::serde_as;
|
use serde_with::serde_as;
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use nom::bytes::complete::tag;
|
||||||
use nom::bytes::complete::take_until1;
|
use nom::bytes::complete::take_until1;
|
||||||
use nom::bytes::complete::{take, take_while, take_while1};
|
use nom::bytes::complete::{take, take_while, take_while1};
|
||||||
use nom::character::complete::hex_digit1;
|
use nom::character::complete::hex_digit1;
|
||||||
use nom::{InputTake, Parser};
|
use nom::{Parser};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use crate::ingest_protocol::error::Error;
|
use crate::ingest_protocol::error::Error;
|
||||||
|
@ -55,7 +55,7 @@ fn handle_special_sensor_macs<'a>(
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ok(true);
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_packet_body<'a>(
|
pub fn parse_packet_body<'a>(
|
||||||
|
@ -69,7 +69,7 @@ pub fn parse_packet_body<'a>(
|
||||||
|
|
||||||
match sensor_mac {
|
match sensor_mac {
|
||||||
"OWNER" => {
|
"OWNER" => {
|
||||||
let (line, owner_value) = take_while1(|c| c != '\n')(line)?;
|
let (_line, owner_value) = take_while1(|c| c != '\n')(line)?;
|
||||||
|
|
||||||
packet.owner = Some(owner_value.into())
|
packet.owner = Some(owner_value.into())
|
||||||
|
|
||||||
|
@ -82,11 +82,11 @@ pub fn parse_packet_body<'a>(
|
||||||
tag("#"),
|
tag("#"),
|
||||||
take_while1(|c| c != '\n' && c != '#' && "1234567890.".contains(c)),
|
take_while1(|c| c != '\n' && c != '#' && "1234567890.".contains(c)),
|
||||||
))(line)?;
|
))(line)?;
|
||||||
let (line, sensor_name) = opt(preceded(tag("#"), take_while1(|c| c != '\n')))(line)?;
|
let (_line, sensor_name) = opt(preceded(tag("#"), take_while1(|c| c != '\n')))(line)?;
|
||||||
|
|
||||||
let sensor_time = match sensor_time {
|
let sensor_time = match sensor_time {
|
||||||
Some(v) => Some(Epoch::from_unix_seconds(
|
Some(v) => Some(Epoch::from_unix_seconds(
|
||||||
v.parse().map_err(|e| TimestampParseError(e))?,
|
v.parse().map_err(TimestampParseError)?,
|
||||||
)),
|
)),
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
@ -103,7 +103,7 @@ pub fn parse_packet_body<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok((line, ()));
|
Ok((line, ()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_packet(input: &str) -> MyIError<&str, NMDeviceDataPacket> {
|
pub fn parse_packet(input: &str) -> MyIError<&str, NMDeviceDataPacket> {
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
async fn main() {}
|
|
22
src/main.rs
22
src/main.rs
|
@ -40,20 +40,20 @@ mod hashes;
|
||||||
mod ingest_protocol;
|
mod ingest_protocol;
|
||||||
mod web_server;
|
mod web_server;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::collections::{BTreeSet, HashMap, HashSet};
|
|
||||||
use std::mem::{size_of, size_of_val};
|
|
||||||
use std::num::NonZeroUsize;
|
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
use hifitime::Epoch;
|
|
||||||
|
|
||||||
use crate::ingest_protocol::error::Error;
|
|
||||||
use crate::ingest_protocol::error::Error::TimestampParseError;
|
|
||||||
use crate::ingest_protocol::{NMDeviceDataPacket, SensorValue};
|
|
||||||
use crate::web_server::old_app_api::old_api_handler;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
use crate::web_server::server_main;
|
use crate::web_server::server_main;
|
||||||
use rust_decimal::Decimal;
|
|
||||||
|
|
||||||
/*fn parse_sensor_value(input: Vec<&str>) -> MyIError<Vec<&str>, NarodMonValues> {
|
/*fn parse_sensor_value(input: Vec<&str>) -> MyIError<Vec<&str>, NarodMonValues> {
|
||||||
Ok(
|
Ok(
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
use derive_more::Display;
|
use derive_more::Display;
|
||||||
use fred::prelude::*;
|
use fred::prelude::*;
|
||||||
use ntex::http::header::{HeaderName, HeaderValue};
|
|
||||||
use ntex::http::{HeaderMap, Response, StatusCode};
|
use ntex::http::{StatusCode};
|
||||||
use ntex::web;
|
use ntex::web;
|
||||||
use ntex::web::types::Json;
|
|
||||||
use ntex::web::{App, HttpRequest, HttpResponse};
|
use ntex::web::{HttpRequest, HttpResponse};
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::fmt::format;
|
|
||||||
use std::str::FromStr;
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::ingest_protocol::error::Error;
|
|
||||||
use crate::insert_header;
|
use crate::insert_header;
|
||||||
use crate::web_server::old_devices_api::QSParserError;
|
use crate::web_server::old_devices_api::QSParserError;
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use ufmt::derive::uDebug;
|
|
||||||
|
|
||||||
#[derive(Debug, Error, Display)]
|
#[derive(Debug, Error, Display)]
|
||||||
pub enum AppError {
|
pub enum AppError {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::web_server::old_app_api::old_api_handler;
|
use crate::web_server::old_app_api::old_api_handler;
|
||||||
use fred::bytes_utils::Str;
|
use fred::bytes_utils::Str;
|
||||||
use fred::prelude::*;
|
use fred::prelude::*;
|
||||||
use std::time::Duration;
|
|
||||||
use tokio;
|
|
||||||
|
|
||||||
pub(crate) mod app_error;
|
pub(crate) mod app_error;
|
||||||
pub mod old_app_api;
|
pub mod old_app_api;
|
||||||
|
@ -15,7 +15,7 @@ pub struct NMAppState {
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::web_server::old_devices_api::device_handler;
|
use crate::web_server::old_devices_api::device_handler;
|
||||||
use heapless::String as HeaplessString;
|
|
||||||
use ntex::web;
|
use ntex::web;
|
||||||
|
|
||||||
pub async fn server_main() {
|
pub async fn server_main() {
|
||||||
|
@ -26,7 +26,7 @@ pub async fn server_main() {
|
||||||
|
|
||||||
// connect to the server, returning a handle to the task that drives the connection
|
// connect to the server, returning a handle to the task that drives the connection
|
||||||
let _ = client.connect();
|
let _ = client.connect();
|
||||||
let _ = client.wait_for_connect().await.unwrap();
|
client.wait_for_connect().await.unwrap();
|
||||||
|
|
||||||
let asd: Str = client.ping().await.unwrap();
|
let asd: Str = client.ping().await.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
use crate::web_server::app_error::AppError;
|
use crate::web_server::app_error::AppError;
|
||||||
use crate::web_server::old_app_api::handlers::{app_init, version};
|
use crate::web_server::old_app_api::handlers::{app_init, version};
|
||||||
|
@ -9,7 +9,7 @@ use nom::AsBytes;
|
||||||
use ntex::util::Bytes;
|
use ntex::util::Bytes;
|
||||||
use ntex::web;
|
use ntex::web;
|
||||||
use ntex::web::types::State;
|
use ntex::web::types::State;
|
||||||
use serde_json::Value;
|
|
||||||
|
|
||||||
pub async fn old_api_handler(
|
pub async fn old_api_handler(
|
||||||
app_state: State<NMAppState>,
|
app_state: State<NMAppState>,
|
||||||
|
@ -24,8 +24,9 @@ pub async fn old_api_handler(
|
||||||
|
|
||||||
let mandatory_params: MandatoryParams<'_> = serde_json::from_slice(body_bytes)?; // TODO: Simd-JSON
|
let mandatory_params: MandatoryParams<'_> = serde_json::from_slice(body_bytes)?; // TODO: Simd-JSON
|
||||||
|
|
||||||
|
// Ignore clippy singlematch
|
||||||
match mandatory_params.cmd.as_ref() {
|
match mandatory_params.cmd.as_ref() {
|
||||||
"version" => return Ok(version((), &app_state).await?),
|
"version" => return version((), &app_state).await,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ pub async fn old_api_handler(
|
||||||
"appInit" => {
|
"appInit" => {
|
||||||
let body: AppInitRequest = serde_json::from_slice(body_bytes)?;
|
let body: AppInitRequest = serde_json::from_slice(body_bytes)?;
|
||||||
|
|
||||||
return Ok(app_init(body, &app_state).await?);
|
app_init(body, &app_state).await
|
||||||
}
|
}
|
||||||
_ => Err(AppError::UnknownMethod(mandatory_params.cmd.to_string())),
|
_ => Err(AppError::UnknownMethod(mandatory_params.cmd.to_string())),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
use crate::web_server::app_error::AppError;
|
use crate::web_server::app_error::AppError;
|
||||||
use crate::web_server::old_app_api::types::AppInitRequest;
|
use crate::web_server::old_app_api::types::AppInitRequest;
|
||||||
use crate::web_server::NMAppState;
|
use crate::web_server::NMAppState;
|
||||||
use heapless::String as HeaplessString;
|
|
||||||
use serde_json::{json, Value as JsonValue};
|
use serde_json::{json};
|
||||||
use ufmt::uwrite;
|
|
||||||
|
|
||||||
use crate::insert_header;
|
use crate::insert_header;
|
||||||
use fred::interfaces::KeysInterface;
|
use fred::interfaces::KeysInterface;
|
||||||
use ntex::http::StatusCode;
|
use ntex::http::StatusCode;
|
||||||
use ntex::web;
|
use ntex::web;
|
||||||
use ntex::web::types::State;
|
|
||||||
use ntex::web::Responder;
|
|
||||||
|
|
||||||
pub async fn app_init(
|
pub async fn app_init(
|
||||||
body: AppInitRequest<'_>,
|
_body: AppInitRequest<'_>,
|
||||||
app_state: &NMAppState,
|
app_state: &NMAppState,
|
||||||
) -> Result<web::HttpResponse, AppError> {
|
) -> Result<web::HttpResponse, AppError> {
|
||||||
let _: () = app_state
|
let _: () = app_state
|
||||||
|
@ -24,7 +24,7 @@ pub async fn app_init(
|
||||||
Ok(web::HttpResponse::build(StatusCode::OK).body("Hello world!"))
|
Ok(web::HttpResponse::build(StatusCode::OK).body("Hello world!"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn version(body: (), app_state: &NMAppState) -> Result<web::HttpResponse, AppError> {
|
pub async fn version(_body: (), _app_state: &NMAppState) -> Result<web::HttpResponse, AppError> {
|
||||||
let mut resp = web::HttpResponse::build(StatusCode::OK).json(&json!({
|
let mut resp = web::HttpResponse::build(StatusCode::OK).json(&json!({
|
||||||
"version": "indev",
|
"version": "indev",
|
||||||
"iotishnik": true
|
"iotishnik": true
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
mod methods;
|
mod methods;
|
||||||
|
|
||||||
use crate::hashes::SupportedUnit;
|
|
||||||
pub use methods::*;
|
pub use methods::*;
|
||||||
use phf::phf_map;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::hashes::SupportedUnit;
|
|
||||||
use serde::{Deserialize, Deserializer, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
// fn<'de, D>(D) -> Result<T, D::Error> where D: Deserializer<'de>
|
// fn<'de, D>(D) -> Result<T, D::Error> where D: Deserializer<'de>
|
||||||
|
|
|
@ -2,9 +2,9 @@ use crate::ingest_protocol::error::Error;
|
||||||
use crate::ingest_protocol::parser::parse_mac_address;
|
use crate::ingest_protocol::parser::parse_mac_address;
|
||||||
use crate::ingest_protocol::{NMDeviceDataPacket, NMJsonPacket};
|
use crate::ingest_protocol::{NMDeviceDataPacket, NMJsonPacket};
|
||||||
use crate::web_server::app_error::AppError;
|
use crate::web_server::app_error::AppError;
|
||||||
use bstr::BStr;
|
|
||||||
use ntex::http::error::DecodeError::Method;
|
|
||||||
use ntex::http::{HttpMessage, Payload, StatusCode};
|
use ntex::http::{HttpMessage, StatusCode};
|
||||||
use ntex::util::{Bytes, HashMap};
|
use ntex::util::{Bytes, HashMap};
|
||||||
use ntex::{http, web};
|
use ntex::{http, web};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -33,11 +33,11 @@ impl From<serde_qs::Error> for QSParserError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn parse_nm_qs_format<'a>(input: &'a str) -> Result<NMDeviceDataPacket, QSParserError> {
|
pub async fn parse_nm_qs_format(input: &str) -> Result<NMDeviceDataPacket, QSParserError> {
|
||||||
let parsed: HashMap<&str, &str> = serde_qs::from_str(input)?;
|
let parsed: HashMap<&str, &str> = serde_qs::from_str(input)?;
|
||||||
|
|
||||||
let (_, device_mac) = if let Some(id) = parsed.get("ID") {
|
let (_, _device_mac) = if let Some(id) = parsed.get("ID") {
|
||||||
parse_mac_address(*id)?
|
parse_mac_address(id)?
|
||||||
} else {
|
} else {
|
||||||
return Err(QSParserError::NoMAC);
|
return Err(QSParserError::NoMAC);
|
||||||
};
|
};
|
||||||
|
@ -53,7 +53,7 @@ pub async fn parse_nm_qs_format<'a>(input: &'a str) -> Result<NMDeviceDataPacket
|
||||||
time: None,
|
time: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
return Ok(device_data);
|
Ok(device_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn device_handler<'a>(
|
pub async fn device_handler<'a>(
|
||||||
|
@ -96,12 +96,12 @@ pub async fn device_handler<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(body) = real_body {
|
if let Some(_body) = real_body {
|
||||||
// TODO
|
// TODO
|
||||||
} else {
|
} else {
|
||||||
return Err(AppError::UnknownBody {
|
return Err(AppError::UnknownBody {
|
||||||
json_err: json_error,
|
json_err: json_error,
|
||||||
query_error: query_error,
|
query_error,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue