@@ -164,7 +164,7 @@ m-bus-parser = "0.1"
164164``` rust
165165use m_bus_parser :: {Address , WiredFrame , Function };
166166use m_bus_parser :: mbus_data :: MbusData ;
167- use m_bus_parser :: user_data :: { DataRecords , UserDataBlock } ;
167+ use m_bus_parser :: user_data :: parse_application_layer ;
168168
169169let frame_bytes : Vec <u8 > = vec! [
170170 0x68 , 0x4D , 0x4D , 0x68 , 0x08 , 0x01 , 0x72 , 0x01 ,
@@ -174,21 +174,31 @@ let frame_bytes: Vec<u8> = vec![
174174let frame = WiredFrame :: try_from (frame_bytes . as_slice ())? ;
175175
176176if let WiredFrame :: LongFrame { function , address , data } = frame {
177- if let Ok (user_data ) = UserDataBlock :: try_from (data ) {
178- if let UserDataBlock :: VariableDataStructureWithLongTplHeader {
179- long_tpl_header ,
180- variable_data_block ,
181- ..
182- } = user_data {
183- let records = DataRecords :: from ((variable_data_block , & long_tpl_header ));
184- for record in records . flatten () {
185- println! (" {}" , record . data);
186- }
177+ let application_layer = parse_application_layer (data )? ;
178+ if let Some (records ) = application_layer . data_records () {
179+ for record in records {
180+ println! (" {:?}" , record ? . value ());
187181 }
188182 }
189183}
190184```
191185
186+ ### Parse application-layer data records
187+
188+ When the link and transport headers have already been removed, parse the DIF/VIF
189+ records directly:
190+
191+ ``` rust
192+ use m_bus_parser :: user_data :: parse_data_records;
193+
194+ let data = [0x03 , 0x13 , 0x15 , 0x31 , 0x00 ];
195+ for record in parse_data_records (& data ) {
196+ let record = record ? ;
197+ println! (" value: {:?}" , record . value ());
198+ println! (" value information: {:?}" , record . value_information ());
199+ }
200+ ```
201+
192202### Serialize to any format
193203
194204``` rust
0 commit comments