CN115334177A - Binary data message analysis method based on xml configuration file recursion - Google Patents

Binary data message analysis method based on xml configuration file recursion Download PDF

Info

Publication number
CN115334177A
CN115334177A CN202210802565.6A CN202210802565A CN115334177A CN 115334177 A CN115334177 A CN 115334177A CN 202210802565 A CN202210802565 A CN 202210802565A CN 115334177 A CN115334177 A CN 115334177A
Authority
CN
China
Prior art keywords
message
structure object
field
attribute
data message
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202210802565.6A
Other languages
Chinese (zh)
Other versions
CN115334177B (en
Inventor
姜锋
张双双
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Unittec Co Ltd
Original Assignee
Unittec Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Unittec Co Ltd filed Critical Unittec Co Ltd
Priority to CN202210802565.6A priority Critical patent/CN115334177B/en
Publication of CN115334177A publication Critical patent/CN115334177A/en
Application granted granted Critical
Publication of CN115334177B publication Critical patent/CN115334177B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/22Parsing or analysis of headers
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Computer Security & Cryptography (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Machine Translation (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the application provides a binary data message analysis method based on xml configuration file recursion, which comprises the steps of reading the xml configuration file and constructing a message structure object dictionary based on reading a characteristic field; acquiring a data message, and acquiring a message structure object corresponding to the data message from a constructed message structure object dictionary; traversing the field structure in the message structure object, and analyzing based on the attribute of the field structure. The attribute of the field in the xml file is expanded, so that the dynamic message with any structure can be completely analyzed through xml configuration. Compared with a hard coding analysis mode, the time required by revising the message configuration due to the change of the interface document is greatly reduced.

Description

Binary data message analysis method based on xml configuration file recursion realization
Technical Field
The application relates to the field of message analysis, in particular to a binary data message analysis method based on xml configuration file recursion.
Background
At present, there are two main methods for binary message analysis in rail transit industry. The method is based on hard coding, and the analysis logic of each message is hard coded in the code, so that the method has the advantages that the analysis logic can be customized according to specific messages, the analysis is very efficient and flexible, and the defect that once a message interface is changed, the code needs to be modified again, and the change cost is high. The other method is an analysis method based on the Xml configuration file, and the Xml has the advantages of good readability, strong expandability and the like. Configuring a message structure in an xml file generally configures a field name, a field length and a field type. Where the field type is typically an underlying data type such as unsigned integer, signed integer, ASCII string, address type, enumerated type, and the like. However, if the content of the message field is complex types such as variable-length arrays, deep-level structures and the like, the prior art cannot meet the requirement. In addition, in a scenario of modifying a message, the value of the crc field of the message needs to be dynamically calculated according to the values of other fields of the message, otherwise, the modified message cannot be used by the service system.
Disclosure of Invention
The embodiment of the application provides a binary data message analysis method based on the xml configuration file recursion, and solves the problems that the existing analysis method based on the xml configuration file cannot process dynamic arrays and complex structures, cannot dynamically update the values of fields and the like. The method expands the attribute of the field in the xml file, so that the dynamic message with any structure can be completely analyzed through xml configuration. In addition, compared with a hard coding analysis mode, the method greatly reduces the time required for revising the message configuration due to the change of the interface document.
Specifically, the binary data message parsing method based on recursive xml configuration files provided in the embodiments of the present application includes:
s1, reading an xml configuration file, and constructing a message structure object dictionary based on the read characteristic fields;
s2, acquiring a data message, and acquiring a message structure object corresponding to the data message from the constructed message structure object dictionary;
and S3, traversing the field structure in the message structure object, and analyzing based on the attribute of the field structure.
Optionally, the S1 includes:
s11, reading an xml configuration file of the binary data message, and acquiring a characteristic field in the xml configuration file;
and S12, constructing a message structure object dictionary by taking the message structure object as a value according to the acquired feature field as an index key.
Optionally, the S2 includes:
s21, acquiring a binary data message and extracting characteristics;
and S22, acquiring the corresponding message structure object from the message structure object dictionary according to the feature index.
Optionally, the S3 includes:
s31, traversing a field structure object list in the message structure object, if the list has an unretraversed field structure object, taking out the field structure object and executing S32, otherwise, exiting the layer of message analysis;
s32, judging the extracted field structure object based on the count attribute;
s33, judging the extracted field structure object based on the refTo attribute, and if the extracted field structure object contains the refTo attribute, re-executing the steps S2 to S3; if the fetched field structure object does not contain the preferto attribute, step S31 is re-executed.
Optionally, the S32 includes:
s321, if the field structure object contains the count attribute, judging whether the count attribute is a variable;
s322, if the count attribute is variable, dynamically determining whether the extracted field structure object contains the count attribute according to the known field analysis result, and analyzing the field containing the count attribute in an array mode;
s323, if the count attribute is a constant, analyzing in a fixed-length array mode;
s324, if the field structure object does not contain the count attribute, the field structure object is resolved in a single element mode.
Optionally, the S33 includes:
s331, if the field structure object contains the preferto attribute, judging whether the preferto attribute is an expression;
s332, if the refeto attribute is in an expression form, dynamically determining a sub-message structural object of the refeto according to the previous analysis result, and analyzing in a sub-message mode;
s333, if the refeto attribute is not in the expression form, directly determining a sub-message structure object of the refeto according to the value of the refeto attribute, and analyzing in a sub-message mode;
s334, if the field structure object does not contain the referrto attribute, the step of parsing the base type field is performed.
Optionally, the S334 further includes:
s3341, determining the length of the field according to the length, determining the type of the field according to the format, and analyzing the value of the field;
s3342, if the attribute of the field structure object format is a crc function expression, the value of the expression is not calculated in real time when the data dictionary is serialized into the binary data message, and the value of the expression is not used in the process of parsing the binary data message into the data dictionary.
Has the beneficial effects that:
the problems that an existing analysis method based on the xml configuration file cannot process dynamic arrays and complex structures, cannot dynamically update values of fields and the like are solved. The method expands the attribute of the field in the xml file, so that the dynamic message with any structure can be completely analyzed through xml configuration. In addition, compared with a hard coding analysis mode, the method greatly reduces the time required for revising the message configuration due to the change of the interface document.
Drawings
In order to more clearly illustrate the technical solutions of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings without creative efforts.
Fig. 1 is a flowchart of a binary data message parsing method implemented recursively based on xml configuration files according to an embodiment of the present application;
FIG. 2 is a flowchart illustrating an exemplary implementation of the present invention;
fig. 3 is a diagram illustrating a binary data message xml configuration according to an embodiment of the present application.
Detailed Description
To make the structure and advantages of the present application clearer, the structure of the present application will be further described with reference to the accompanying drawings.
Specifically, as shown in fig. 1, the binary data message parsing method based on xml configuration file recursion proposed in the embodiment of the present application includes:
s1, reading an xml configuration file, and constructing a message structure object dictionary based on the read characteristic fields;
s2, acquiring a data message, and acquiring a message structure object corresponding to the data message from the constructed message structure object dictionary;
and S3, traversing the field structure in the message structure object, and analyzing based on the attribute of the field structure.
In implementation, in order to solve the problems of the two current methods for parsing messages, a binary data message parsing method implemented based on xml configuration file recursion is proposed. And referencing the configuration of another sub-packet through the refto extended attribute of the field. The program can know whether the value of the field is a structural object or not through the refto attribute of the message field, and if the refto is the name of the sub-message, namely points to a sub-message configuration, the program analyzes the value of the field by using the sub-message configuration. If the preferto is an expression containing other sub-messages, the expression is analyzed in the analysis process, and the analysis of which sub-message is used is dynamically judged, so that the analysis of the dynamic sub-message can be realized.
It should be noted that the message parsing method provided by the present application further extends the attribute through the count of the field, and indicates whether the value of the field is an array. If the count is a constant, the value of the field is a fixed-length array, if the count is the name of another field, the value of the field is a variable-length array, and the length of the array is dynamically determined by the value of the corresponding name field in the message analysis process.
Specifically, the S1 for constructing the message structure object dictionary operation in the foregoing method includes:
s11, reading an xml configuration file of the binary data message, and acquiring a characteristic field in the xml configuration file;
and S12, constructing a message structure object dictionary by taking the message structure object as a value according to the acquired feature field as an index key.
Optionally, the S2, in the method, for acquiring a message structure object corresponding to the data message, includes:
s21, acquiring a binary data message and extracting characteristics;
and S22, acquiring a corresponding message structure object from the message structure object dictionary according to the characteristic index.
Optionally, S3 in the foregoing method for performing parsing based on an attribute of a field structure includes:
s31, traversing a field structure object list in the message structure object, if the list has an unretraversed field structure object, taking out the field structure object and executing S32, otherwise, exiting the layer of message analysis;
s32, judging the extracted field structure object based on the count attribute;
s33, judging the extracted field structure object based on the preferto attribute, and if the extracted field structure object contains the preferto attribute, re-executing the steps S2 to S3; if the fetched field structure object does not contain the referrto attribute, step S31 is re-executed.
In an implementation, S32 comprises:
s321, if the field structure object contains the count attribute, judging whether the count attribute is a variable;
s322, if the count attribute is variable, dynamically determining whether the extracted field structure object contains the count attribute according to the known field analysis result, and analyzing the field containing the count attribute in an array mode;
s323, if the count attribute is a constant, analyzing in a fixed-length array mode;
s324, if the field structure object does not contain the count attribute, the field structure object is resolved in a single element mode.
S33 includes:
s331, if the field structure object contains the preferto attribute, judging whether the preferto attribute is an expression;
s332, if the refTo attribute is in an expression form, dynamically determining a sub-message structural object of the refTo according to the previous analysis result, and analyzing in a sub-message mode;
s333, if the refTo attribute is not in the expression form, directly determining the sub-message structure object of the refTo according to the value of the refTo attribute, and analyzing in the sub-message mode;
s334, if the field structure object does not contain the referrto attribute, the step of parsing the base type field is performed.
S334 includes:
s3341, determining the length of the field according to the length, determining the type of the field according to the format, and analyzing the value of the field;
s3342, if the attribute of the field structure object format is a crc function expression, the value of the expression is not calculated in real time when the data dictionary is serialized into the binary data message, and the value of the expression is not used in the process of parsing the binary data message into the data dictionary.
In the above determining step, the attribute is extended by format of the field, and the type of the field may be hex (hexadecimal), decimall (decimal), binary, ascii (character string), or may be an expression, for example: crc32 (field 1, field2, field 3) or crc32 (field 1..) indicating that the value of this field needs to be dynamically calculated from the other fields of the message after the message has been modified. Through the preferto extended attribute and the embedded extended attribute, the same fields of a plurality of messages only need to be configured once, and then the messages are quoted in a plurality of places, and the quoted sub-message configuration is embedded into the quoted main message during analysis.
Based on the technical solution proposed in the foregoing, a specific execution flow is shown in fig. 2:
step 1, reading an xml configuration file of a binary data message, using characteristic fields of SID, DID, type and the like of the message as index keys together, using a message structure object as a value, and constructing a message structure object dictionary. The message structure object comprises basic attributes of the message and a field structure object list, and the field structure object comprises each attribute of a field, including that the field occupies several bytes (length), a field type (format), whether the field is an array, an array length (count), a message structure object (refto) referring to a sub-message, and the like.
And step 2, acquiring a binary data message, and acquiring a corresponding message structure object from the message structure object dictionary according to the index.
And 3, traversing a field structure object list in the message structure object, if the list has non-traversed field structure objects, taking out one field structure object, entering the next step, and otherwise, exiting the layer of message analysis.
And 4, if the field structure object contains the count attribute, judging whether the count attribute is a variable. If yes, the value of the count attribute is dynamically determined according to the analysis result of the previous field. The fields containing the count attribute are resolved in an array manner. Otherwise, it is resolved in a single element.
And step 6, if the field structure object contains the preferto attribute, judging whether the preferto attribute is an expression or not. If so, dynamically determining the sub-message structure object of the refTo according to the previous analysis result. And (4) analyzing the field containing the refto attribute in a sub-message mode, returning to the step 3 (recursive implementation), and otherwise, entering the step 7.
And 7, determining the length of the field according to the length, determining the type of the field according to the format, and analyzing the value of the field. If the field structure object format attribute is a crc function expression, it is not used in parsing the binary data message into a data dictionary. The values of the expressions are computed in real time as the data dictionary is serialized into binary data messages.
Fig. 3 is a diagram of binary data message xml configuration, which replaces the configuration of service message of actual rail transit with the configuration of an example in life. The main message contains fields of Name, age, height Andweight, luckyNumber, phonenumbers, friends, CRCValue, etc.
On line 5, the Height Andweight embeds the Height and weight fields into the main message in an embedding manner;
line 7, phoneNumbers is a fixed-length array with 4-byte decimal number as internal element and 5 number;
in line 9, friends is a structure with an internal element type being Friend, and the number of the dynamic variable-length arrays is FriendsCount value;
in line 10, when the LuckyNumber and any subsequent fields are changed, the value of the CRCValue field is recalculated according to the LuckyNumber and subsequent fields;
on line 25, the value of the Food is a structure dynamically determined according to the value of the Type, and when the Type is respectively equal to 1 or 2, the Food is respectively analyzed by the configuration of the Meet or Vegetable sub-message.
The above description is intended only to serve as examples of the present application and should not be construed as limiting the present application, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present application should be included in the scope of the present application.

Claims (7)

1. A binary data message analysis method based on xml configuration file recursion implementation is characterized by comprising the following steps:
s1, reading an xml configuration file, and constructing a message structure object dictionary based on the read characteristic fields;
s2, acquiring a data message, and acquiring a message structure object corresponding to the data message from the constructed message structure object dictionary;
and S3, traversing the field structure in the message structure object, and analyzing based on the attribute of the field structure.
2. The binary data message parsing method based on recursive xml configuration file according to claim 1, wherein the S1 comprises:
s11, reading an xml configuration file of the binary data message, and acquiring a characteristic field in the xml configuration file;
and S12, constructing a message structure object dictionary by taking the message structure object as a value according to the acquired feature field as an index key.
3. The binary data message parsing method based on recursive xml configuration file according to claim 1, wherein the S2 comprises:
s21, acquiring a binary data message and extracting characteristics;
and S22, acquiring the corresponding message structure object from the message structure object dictionary according to the feature index.
4. The binary data message parsing method based on xml-profile recursive implementation according to claim 1, wherein the S3 comprises:
s31, traversing a field structure object list in the message structure object, if the list has an unretraversed field structure object, taking out the field structure object and executing S32, otherwise, exiting the layer of message analysis;
s32, judging the extracted field structure object based on the count attribute;
s33, judging the extracted field structure object based on the preferto attribute, and if the extracted field structure object contains the preferto attribute, re-executing the steps S2 to S3; if the fetched field structure object does not contain the referrto attribute, step S31 is re-executed.
5. The binary data message parsing method based on recursive xml-configuration file according to claim 4, wherein the S32 comprises:
s321, if the field structure object contains a count attribute, judging whether the count attribute is a variable;
s322, if the count attribute is variable, dynamically determining whether the extracted field structure object contains the count attribute according to the known field analysis result, and analyzing the field containing the count attribute in an array mode;
s323, if the count attribute is a constant, analyzing in a fixed-length array mode;
s324, if the field structure object does not contain the count attribute, the field structure object is resolved in a single element mode.
6. The binary data message parsing method based on recursive xml configuration file according to claim 4, wherein the step S33 comprises:
s331, if the field structure object contains the refTo attribute, judging whether the refTo attribute is an expression or not;
s332, if the refTo attribute is in an expression form, dynamically determining a sub-message structural object of the refTo according to the previous analysis result, and analyzing in a sub-message mode;
s333, if the refTo attribute is not in the expression form, directly determining the sub-message structure object of the refTo according to the value of the refTo attribute, and analyzing in the sub-message mode;
s334, if the field structure object does not contain the referrto attribute, the step of parsing the base type field is performed.
7. The binary data message parsing method based on recursive xml configuration file according to claim 1, wherein said S334 further comprises:
s3341, determining the length of the field according to the length, determining the type of the field according to the format, and analyzing the value of the field;
s3342, if the attribute of the field structure object format is a crc function expression, the value of the expression is not calculated in real time when the data dictionary is serialized into the binary data message, and the value of the expression is not used in the process of parsing the binary data message into the data dictionary.
CN202210802565.6A 2022-07-07 2022-07-07 Binary data message analysis method based on xml configuration file recursion realization Active CN115334177B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210802565.6A CN115334177B (en) 2022-07-07 2022-07-07 Binary data message analysis method based on xml configuration file recursion realization

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210802565.6A CN115334177B (en) 2022-07-07 2022-07-07 Binary data message analysis method based on xml configuration file recursion realization

Publications (2)

Publication Number Publication Date
CN115334177A true CN115334177A (en) 2022-11-11
CN115334177B CN115334177B (en) 2023-12-05

Family

ID=83918626

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210802565.6A Active CN115334177B (en) 2022-07-07 2022-07-07 Binary data message analysis method based on xml configuration file recursion realization

Country Status (1)

Country Link
CN (1) CN115334177B (en)

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101221556A (en) * 2008-02-01 2008-07-16 中国建设银行股份有限公司 Method and device for XML document analysis
US20090150412A1 (en) * 2007-12-05 2009-06-11 Sam Idicula Efficient streaming evaluation of xpaths on binary-encoded xml schema-based documents
CN106095792A (en) * 2016-05-27 2016-11-09 ***股份有限公司 The method and apparatus generating database manipulation code
CN109885569A (en) * 2018-12-29 2019-06-14 天津南大通用数据技术股份有限公司 Field extraction and structural method are carried out to XML data based on configuration file
CN110457526A (en) * 2019-07-31 2019-11-15 南京理工大学 Unitized data analytic method based on xml document
CN110719296A (en) * 2019-10-25 2020-01-21 福建网能科技开发有限责任公司 Method for automatically analyzing message data in terminal communication protocol
CN112037074A (en) * 2020-09-11 2020-12-04 中国银行股份有限公司 Visualization-based data file analysis method and device
CN113225320A (en) * 2021-04-21 2021-08-06 南京理工大学 Network message analysis method for keeping user configurable message format secret

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090150412A1 (en) * 2007-12-05 2009-06-11 Sam Idicula Efficient streaming evaluation of xpaths on binary-encoded xml schema-based documents
CN101221556A (en) * 2008-02-01 2008-07-16 中国建设银行股份有限公司 Method and device for XML document analysis
CN106095792A (en) * 2016-05-27 2016-11-09 ***股份有限公司 The method and apparatus generating database manipulation code
CN109885569A (en) * 2018-12-29 2019-06-14 天津南大通用数据技术股份有限公司 Field extraction and structural method are carried out to XML data based on configuration file
CN110457526A (en) * 2019-07-31 2019-11-15 南京理工大学 Unitized data analytic method based on xml document
CN110719296A (en) * 2019-10-25 2020-01-21 福建网能科技开发有限责任公司 Method for automatically analyzing message data in terminal communication protocol
CN112037074A (en) * 2020-09-11 2020-12-04 中国银行股份有限公司 Visualization-based data file analysis method and device
CN113225320A (en) * 2021-04-21 2021-08-06 南京理工大学 Network message analysis method for keeping user configurable message format secret

Also Published As

Publication number Publication date
CN115334177B (en) 2023-12-05

Similar Documents

Publication Publication Date Title
KR100614677B1 (en) Method for compressing/decompressing a structured document
US10572370B2 (en) Test-assisted application programming interface (API) learning
CN109104405B (en) Binary protocol encoding and decoding method and device
US8533172B2 (en) Method and device for coding and decoding information
CN109460220B (en) Message predefined code generation method and device, electronic equipment and storage medium
JP4653381B2 (en) Structured document compression / decompression method
EP1803225A1 (en) Adaptive compression scheme
US8234288B2 (en) Method and device for generating reference patterns from a document written in markup language and associated coding and decoding methods and devices
CN111249736B (en) Code processing method and device
CN111324619B (en) Object updating method, device, equipment and storage medium in micro-service system
US20090254882A1 (en) Methods and devices for iterative binary coding and decoding of xml type documents
CN110765773A (en) Address data acquisition method and device
US20090322570A1 (en) Adaptive Entropy Coding Compression Output Formats
CN111131403A (en) Message coding and decoding method and device for Internet of things equipment
US7518538B1 (en) Adaptive entropy coding compression with multi-level context escapes
CN108664546B (en) XML data structure conversion method and device
CN115242896A (en) Dynamic message analysis method and device, electronic equipment and computer readable storage medium
CN113254026B (en) Low code development method and device
CN117278661B (en) Industrial Internet of things multi-protocol analysis method and system
CN111552839B (en) Object conversion method based on XML template
CN108880559B (en) Data compression method, data decompression method, compression equipment and decompression equipment
CN115334177A (en) Binary data message analysis method based on xml configuration file recursion
CN115576603B (en) Method and device for acquiring variable values in code segment
CN111049813A (en) Message assembling method, message analyzing method, message assembling device, message analyzing device and storage medium
WO2021189434A1 (en) User selection method and device, and server and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant