Skip to content

Commit acec1d2

Browse files
committed
add parser prototype for IoText message in RUST
1 parent 4b8aee3 commit acec1d2

File tree

1 file changed

+31
-35
lines changed

1 file changed

+31
-35
lines changed

src/test_parse.rs

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
use std::*;
22

3-
43
// COPY -> PASTE to https://play.rust-lang.org/ for check parser prototype
54

6-
7-
85
//use std::intrinsics::type_name::*;
96
//use std::num::ParseIntError;
107
//use rust_decimal::Decimal;
118

12-
139
struct MetricDataTypes {}
1410

1511
impl MetricDataTypes {
@@ -19,7 +15,6 @@ impl MetricDataTypes {
1915
const TEXT: &str = "t";
2016
}
2117

22-
2318
struct ItemType {}
2419
impl ItemType {
2520
const TIME_UNIX_MILIS: &str = "t";
@@ -44,9 +39,7 @@ enum ItemTypeEnum {
4439
const MSG_EXAMPLE: &str = "t|3900237526042,d|device_name_001,m|val_water_level1=i:42,m|light_on=b:1,m|bulb_on=b:0,m|msg_machine_01=t:hello,m|wind_speed=d:1234.5678";
4540

4641
fn main() {
47-
let item_parts: Vec<&str> = MSG_EXAMPLE
48-
.split(',')
49-
.collect();
42+
let item_parts: Vec<&str> = MSG_EXAMPLE.split(',').collect();
5043

5144
for part in item_parts {
5245
println!("part: {}", part);
@@ -76,7 +69,7 @@ fn main() {
7669
MetricDataTypes::BOOL => {
7770
let value = match metric_parts_values[1] {
7871
"1" => true,
79-
"0" => false,
72+
"0" => false,
8073
_ => todo!(),
8174
};
8275
println!(
@@ -90,7 +83,7 @@ fn main() {
9083
MetricValueType::TextItemType(metric_parts_values[1].to_string())
9184
)
9285
}
93-
/*
86+
/*
9487
MetricDataTypes::DECIMAL => {
9588
println!(
9689
"\t\t\tDecimalItemType: {:?}",
@@ -113,7 +106,10 @@ fn main() {
113106
)
114107
}
115108
ItemType::DEVICE_ID => {
116-
println!("\t\t\tDEVICE_ID: {:?}", ItemTypeEnum::DeviceId(String::from(item_part[1])))
109+
println!(
110+
"\t\t\tDEVICE_ID: {:?}",
111+
ItemTypeEnum::DeviceId(String::from(item_part[1]))
112+
)
117113
}
118114
ItemType::METRIC => {
119115
println!("\t\t\tMETRIC: {}", String::from(item_part[1]))
@@ -144,40 +140,40 @@ STDOUT:
144140
145141
part: t|3900237526042
146142
item_part: ["t", "3900237526042"]
147-
TIME_UNIX_MILIS: TimeUnixMilis(3900237526042)
148-
context: 3900237526042
143+
TIME_UNIX_MILIS: TimeUnixMilis(3900237526042)
144+
context: 3900237526042
149145
part: d|device_name_001
150146
item_part: ["d", "device_name_001"]
151-
DEVICE_ID: DeviceId("device_name_001")
152-
context: device_name_001
147+
DEVICE_ID: DeviceId("device_name_001")
148+
context: device_name_001
153149
part: m|val_water_level1=i:42
154150
item_part: ["m", "val_water_level1=i:42"]
155-
metric: val_water_level1=i:42
156-
metric_parts: ["val_water_level1", "i:42"]
157-
metric_parts_values: ["i", "42"]
158-
IntegerItemType: IntegerItemType(42)
151+
metric: val_water_level1=i:42
152+
metric_parts: ["val_water_level1", "i:42"]
153+
metric_parts_values: ["i", "42"]
154+
IntegerItemType: IntegerItemType(42)
159155
part: m|light_on=b:1
160156
item_part: ["m", "light_on=b:1"]
161-
metric: light_on=b:1
162-
metric_parts: ["light_on", "b:1"]
163-
metric_parts_values: ["b", "1"]
164-
BoolItemType: BoolItemType(true)
157+
metric: light_on=b:1
158+
metric_parts: ["light_on", "b:1"]
159+
metric_parts_values: ["b", "1"]
160+
BoolItemType: BoolItemType(true)
165161
part: m|bulb_on=b:0
166162
item_part: ["m", "bulb_on=b:0"]
167-
metric: bulb_on=b:0
168-
metric_parts: ["bulb_on", "b:0"]
169-
metric_parts_values: ["b", "0"]
170-
BoolItemType: BoolItemType(false)
163+
metric: bulb_on=b:0
164+
metric_parts: ["bulb_on", "b:0"]
165+
metric_parts_values: ["b", "0"]
166+
BoolItemType: BoolItemType(false)
171167
part: m|msg_machine_01=t:hello
172168
item_part: ["m", "msg_machine_01=t:hello"]
173-
metric: msg_machine_01=t:hello
174-
metric_parts: ["msg_machine_01", "t:hello"]
175-
metric_parts_values: ["t", "hello"]
176-
BoolItemType: TextItemType("hello")
169+
metric: msg_machine_01=t:hello
170+
metric_parts: ["msg_machine_01", "t:hello"]
171+
metric_parts_values: ["t", "hello"]
172+
BoolItemType: TextItemType("hello")
177173
part: m|wind_speed=d:1234.5678
178174
item_part: ["m", "wind_speed=d:1234.5678"]
179-
metric: wind_speed=d:1234.5678
180-
metric_parts: ["wind_speed", "d:1234.5678"]
181-
metric_parts_values: ["d", "1234.5678"]
182-
other
175+
metric: wind_speed=d:1234.5678
176+
metric_parts: ["wind_speed", "d:1234.5678"]
177+
metric_parts_values: ["d", "1234.5678"]
178+
other
183179
*/

0 commit comments

Comments
 (0)