-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/wasm pack #10
Changes from 6 commits
fa42a89
ea594d3
2bdaf58
6270206
9ee8af9
c0262b8
a9423f5
1eabe9e
a44fed4
9d6bb1d
055ee5c
233bccc
e4553bb
6632f48
90b287d
a1afd3b
ba1a73f
02af844
daa096c
f262ecc
ba31ea3
f9a50e2
e69bd71
22949fb
4b9e1d5
4d7107d
2a14d94
e0ebf64
1e899ed
373a6c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,15 +28,19 @@ bindgen = "0.69.4" | |
[features] | ||
std = [] | ||
plaintext-before-extension = [] | ||
serde_support = ["serde", "std", "arrayvec/serde"] | ||
|
||
[profile.release] | ||
opt-level = 'z' # Optimize for size | ||
lto = true # Enable Link Time Optimization | ||
codegen-units = 1 # Reduce codegen units to improve optimizations | ||
|
||
[dependencies] | ||
serde = { version = "1.0", features = ["derive"], optional = true } | ||
bitflags = "2.4.2" | ||
arrayvec = "0.7.4" | ||
arrayvec = { version = "0.7.4", features = [ | ||
"serde", | ||
], optional = true, default-features = false } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is arrayvec really optional? You seem to use it without a feature gate in the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
[workspace] | ||
members = ["cli"] | ||
members = ["cli", "wasm"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,9 +58,16 @@ pub mod frames; | |
pub mod user_data; | ||
|
||
#[derive(Debug)] | ||
#[cfg_attr(feature = "serde_support", derive(serde::Serialize))] | ||
#[cfg_attr( | ||
feature = "serde_support", | ||
derive(serde::Deserialize), | ||
serde(bound(deserialize = "'de: 'a")) | ||
)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These can probably be the same cfg_attr. You don't need a separate one for each derive. #[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize),
serde(bound(deserialize = "'de: 'a"))
)] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was not possible |
||
pub struct MbusData<'a> { | ||
pub frame: frames::Frame<'a>, | ||
pub user_data: Option<user_data::UserDataBlock<'a>>, | ||
pub data_records: Option<user_data::DataRecords>, | ||
} | ||
|
||
#[derive(Debug)] | ||
|
@@ -77,9 +84,7 @@ impl From<FrameError> for MbusError { | |
|
||
impl From<ApplicationLayerError> for MbusError { | ||
fn from(error: ApplicationLayerError) -> MbusError { | ||
match error { | ||
_ => MbusError::ApplicationLayerError(error), | ||
} | ||
MbusError::ApplicationLayerError(error) | ||
} | ||
} | ||
|
||
|
@@ -88,15 +93,30 @@ impl<'a> TryFrom<&'a [u8]> for MbusData<'a> { | |
|
||
fn try_from(data: &'a [u8]) -> Result<Self, Self::Error> { | ||
let frame = frames::Frame::try_from(data)?; | ||
|
||
let user_data = match &frame { | ||
let mut user_data = None; | ||
let mut data_records = None; | ||
match &frame { | ||
frames::Frame::LongFrame { data, .. } => { | ||
Some(user_data::UserDataBlock::try_from(*data)?) | ||
if let Ok(x) = user_data::UserDataBlock::try_from(*data) { | ||
user_data = Some(x); | ||
if let Ok(user_data::UserDataBlock::VariableDataStructure { | ||
fixed_data_header: _, | ||
variable_data_block, | ||
}) = user_data::UserDataBlock::try_from(*data) | ||
{ | ||
data_records = user_data::DataRecords::try_from(variable_data_block).ok(); | ||
} | ||
} | ||
} | ||
frames::Frame::SingleCharacter { .. } => None, | ||
frames::Frame::ShortFrame { .. } | frames::Frame::ControlFrame { .. } => None, | ||
frames::Frame::SingleCharacter { .. } => (), | ||
frames::Frame::ShortFrame { .. } => (), | ||
frames::Frame::ControlFrame { .. } => (), | ||
}; | ||
|
||
Ok(MbusData { frame, user_data }) | ||
Ok(MbusData { | ||
frame, | ||
user_data, | ||
data_records, | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,14 @@ use super::variable_user_data::DataRecordError; | |
use arrayvec::ArrayVec; | ||
|
||
const MAX_DIFE_RECORDS: usize = 10; | ||
#[cfg_attr( | ||
feature = "serde_support", | ||
derive(serde::Serialize, serde::Deserialize) | ||
)] | ||
#[derive(Debug, PartialEq)] | ||
pub struct DataInformationBlock { | ||
pub data_information_field: DataInformationField, | ||
#[serde(skip_serializing, skip_deserializing)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should also be in a cfg_attr |
||
pub data_information_field_extension: | ||
Option<ArrayVec<DataInformationFieldExtension, MAX_DIFE_RECORDS>>, | ||
} | ||
|
@@ -19,7 +24,10 @@ impl DataInformationBlock { | |
size | ||
} | ||
} | ||
|
||
#[cfg_attr( | ||
feature = "serde_support", | ||
derive(serde::Serialize, serde::Deserialize) | ||
)] | ||
#[derive(Debug, PartialEq)] | ||
pub struct DataInformationField { | ||
pub data: u8, | ||
|
@@ -42,7 +50,10 @@ impl From<u8> for DataInformationFieldExtension { | |
DataInformationFieldExtension { data } | ||
} | ||
} | ||
|
||
#[cfg_attr( | ||
feature = "serde_support", | ||
derive(serde::Serialize, serde::Deserialize) | ||
)] | ||
#[derive(Debug, PartialEq)] | ||
pub struct DataInformationFieldExtension { | ||
pub data: u8, | ||
|
@@ -94,7 +105,10 @@ impl DataInformationFieldExtension { | |
self.data & 0x80 != 0 | ||
} | ||
} | ||
|
||
#[cfg_attr( | ||
feature = "serde_support", | ||
derive(serde::Serialize, serde::Deserialize) | ||
)] | ||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct DataInformation { | ||
pub storage_number: u64, | ||
|
@@ -116,7 +130,10 @@ impl std::fmt::Display for DataInformation { | |
} | ||
|
||
const MAXIMUM_DATA_INFORMATION_SIZE: usize = 11; | ||
|
||
#[cfg_attr( | ||
feature = "serde_support", | ||
derive(serde::Serialize, serde::Deserialize) | ||
)] | ||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct DataInformationExtensionField {} | ||
|
||
|
@@ -205,11 +222,19 @@ impl TryFrom<&DataInformationBlock> for DataInformation { | |
} | ||
} | ||
|
||
#[cfg_attr( | ||
feature = "serde_support", | ||
derive(serde::Serialize, serde::Deserialize) | ||
)] | ||
#[derive(Debug, PartialEq)] | ||
pub enum DataType { | ||
Text(ArrayVec<u8, 18>), | ||
Number(f64), | ||
} | ||
#[cfg_attr( | ||
feature = "serde_support", | ||
derive(serde::Serialize, serde::Deserialize) | ||
)] | ||
#[derive(PartialEq, Debug)] | ||
pub struct Data { | ||
value: Option<DataType>, | ||
|
@@ -509,7 +534,10 @@ impl DataInformation { | |
self.size | ||
} | ||
} | ||
|
||
#[cfg_attr( | ||
feature = "serde_support", | ||
derive(serde::Serialize, serde::Deserialize) | ||
)] | ||
#[derive(Debug, Clone, Copy, PartialEq)] | ||
pub enum FunctionField { | ||
InstantaneousValue, | ||
|
@@ -529,7 +557,10 @@ impl std::fmt::Display for FunctionField { | |
} | ||
} | ||
} | ||
|
||
#[cfg_attr( | ||
feature = "serde_support", | ||
derive(serde::Serialize, serde::Deserialize) | ||
)] | ||
#[derive(Debug, Clone, Copy, PartialEq)] | ||
pub enum SpecialFunctions { | ||
ManufacturerSpecific, | ||
|
@@ -655,7 +686,10 @@ impl DataFieldCoding { | |
} | ||
} | ||
} | ||
|
||
#[cfg_attr( | ||
feature = "serde_support", | ||
derive(serde::Serialize, serde::Deserialize) | ||
)] | ||
#[derive(Debug, Clone, Copy, PartialEq)] | ||
pub enum DataFieldCoding { | ||
NoData, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this feature to just serde than make the array
["dep:serde", "std", "arrayvec/serde"]
also it is necessary to enable std to use serde? I don't think you need std to use serde