A Transmission Processing Method and Device for MSON Data Format
By using the MSON data format, the Map data is converted into MSON strings and transmitted, and then converted into Map objects at the receiving end, the problem of low Map data transmission efficiency in the prior art is solved, and a smaller transmission byte length and higher processing efficiency is achieved.
Patent Information
- Application Number
- CN202210235342.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-10
- Publication Date
- 2025-06-27
- Estimated Expiration
- 2042-03-10
AI Technical Summary
In the existing Map data transmission scheme, the serialized byte length is too large, and serialization/deserialization is time-consuming, resulting in inefficiency.
In the MSON data format, the Map data is converted into MSON string for transmission, and the MSON string is converted into a Map object at the receiving end. The MSON string uses six constructor characters (BEGIN_ARRAY, BEGIN_OBJECT, END_ARRAY, END_OBJECT, NAME_SEPARATOR, VALUE_SEPARATOR) and strings, supporting loop nested conversions and minor error detection.
Through the MSON data format, the byte length of the transmitted packet is smaller than that of similar serialization methods such as xml, JSON and JDK, and has high processing efficiency. It can be quickly converted into a Map object, making it easy to use directly.
Smart Images

Figure CN114626342B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of data transmission processing, and particularly relates to a method and device for transmitting and processing MSON data format. Background Art
[0002] In more and more scenarios, Map format data is used for data interaction. How to improve the transmission efficiency of Map data and how to transmit and parse Map data have become problems that need to be solved by those skilled in the art. Existing solutions, such as fastjson, serialize Map objects into JSON strings for use in communication transmission or database storage. Then, after receiving or retrieving from the database, it is deserialized into a Map object. Similar technical solutions also include the native serialization tool of JDK, Hessian serialization tool, etc. However, there are problems in existing technical solutions such as the excessive byte length after serialization and the relatively long time-consuming for serialization / deserialization. Summary of the Invention
[0003] Aiming at the deficiencies in the prior art, the present invention provides a method and device for transmitting and processing MSON data format, aiming to convert Map data into an MSON string for transmission and process it at the receiving end to convert the MSON string into a Map object. The present invention is applicable to the following several major scenarios:
[0004] 1) When transmitting Map data, serialize it into an MSON string for transmission and deserialize it at the processing end;
[0005] 2) Where the message is a Map string, convert it into an MSON string and then into a Map object, and then directly use it in the program; for example, retrieve the message from the log and finally convert it into a Map object for use in the test class;
[0006] 3) When saving or storing Map data in the database, convert it into an MSON string for saving.
[0007] To achieve the above object, the present invention adopts the following technical solutions:
[0008] A method for transmitting and processing MSON data format, characterized by including:
[0009] Converting Map data into an MSON string;
[0010] Parsing out the keys and values of the MSON string;
[0011] Assembling the parsed keys and values into key-value pairs and converting them into a Map object;
[0012] Among them, the MSON string contains six construction characters BEGIN_ARRAY, BEGIN_OBJECT, END_ARRAY, END_OBJECT, NAME_SEPARATOR, and VALUE_SEPARATOR. Among them, BEGIN_ARRAY represents the left square bracket, BEGIN_OBJECT represents the left curly brace, END_ARRAY represents the right square bracket, END_OBJECT represents the right curly brace, NAME_SEPARATOR represents the equal sign, and VALUE_SEPARATOR represents the comma. In the composition structure of the MSON string, an object is enclosed by BEGIN_OBJECT and END_OBJECT, and an array is enclosed by BEGIN_ARRAY and END_ARRAY.
[0013] To optimize the above technical solution, the specific measures taken also include:
[0014] Further, the key-value pair is in the form of "k = v", where k represents the key, the key is in string format, and v represents the value, and the value is an object, an array, or a string.
[0015] Further, the keys and values of the MSON string are parsed as follows: Start parsing from the position after the first BEGIN_OBJECT at the beginning of the MSON data format, and separate it into the form of "k = v, k = v, k =... = v" by NAME_SEPARATOR. The first and last k and v are processed separately, and each group of "v, k" separated by NAME_SEPARATOR is iteratively parsed to parse out v and k from each group of "v, k".
[0016] Further, when iteratively parsing each group of "v, k" separated by NAME_SEPARATOR, it is necessary to determine the offset off and the position next of NAME_SEPARATOR; the first iteration starts from the position after the first BEGIN_OBJECT at the beginning of the MSON data format. At this time, off = 0, the off of the next iteration is the current iteration's next plus 1, and the next of the next iteration is the position of the first NAME_SEPARATOR that is not inside an object, not inside an array, and not inside a string after the current iteration's off.
[0017] Further, when parsing v and k from each group of "v, k", it is necessary to first determine the position vIndex of VALUE_SEPARATOR. vIndex is the first VALUE_SEPARATOR that is not inside an object, not inside an array, and not inside a string after NAME_SEPARATOR; then the following steps are performed:
[0018] S01: If the first digit of the parsed value is BEGIN_OBJECT, it is an object. Call the function str2Map to convert the string to a Map, find the position of END_OBJECT, and then parse the value of the object;
[0019] If the first digit is still BEGIN_OBJECT, loop and call str2Map, then go to S01; if the first digit is BEGIN_ARRAY, it is an array, go to S02; if it is a string, directly parse it according to the form of "k = v";
[0020] Finally, use the position of the first VALUE_SEPARATOR after END_OBJECT as vIndex;
[0021] S02: If the first digit of the parsed value is BEGIN_ARRAY, call the function str2List to convert the string to an array, find the position of END_ARRAY, and then parse the value of the array;
[0022] If the first digit is BEGIN_OBJECT, go to S01; if the first digit is still BEGIN_ARRAY, go to S02; if it is a string, directly obtain the position of END_ARRAY, and use VALUE_SEPARATOR as the delimiter to obtain the array elements to get the value of the array;
[0023] Finally, use the position of the first VALUE_SEPARATOR after END_ARRAY as vIndex;
[0024] S03: If the parsed value is a string, directly obtain the position vIndex of VALUE_SEPARATOR;
[0025] S04: After determining the position vIndex of VALUE_SEPARATOR, the string between it and the next NAME_SEPARATOR is the next k; thus, a set of "v, k" is parsed;
[0026] S05: Iteratively parse all "v, k";
[0027] S06: Parse the last v. The string from the position of the last VALUE_SEPARATOR to the end of the MSON string is the last value;
[0028] Thus, the entire MSON string is parsed into two arrays composed of v and k.
[0029] The present invention also proposes a transmission processing device for MSON data format, which is characterized by including:
[0030] A conversion unit for converting Map data into an MSON string;
[0031] A parsing unit for parsing the keys and values of the MSON string;
[0032] An assembly unit for assembling the parsed keys and values into key-value pairs and converting them into a Map object;
[0033] Among them, the MSON string includes six construction characters BEGIN_ARRAY, BEGIN_OBJECT, END_ARRAY, END_OBJECT, NAME_SEPARATOR, VALUE_SEPARATOR and strings. Among them, BEGIN_ARRAY represents a left square bracket, BEGIN_OBJECT represents a left curly bracket, END_ARRAY represents a right square bracket, END_OBJECT represents a right curly bracket, NAME_SEPARATOR represents an equal sign, and VALUE_SEPARATOR represents a comma; in the composition structure of the MSON string, an object is enclosed by BEGIN_OBJECT and END_OBJECT, and an array is enclosed by BEGIN_ARRAY and END_ARRAY.
[0034] Further, the key-value pair is in the form of "k = v", where k represents the key, the key is in string format, and v represents the value, and the value is an object, an array or a string.
[0035] Further, the parsing unit parses the keys and values of the MSON string as follows: starting from the position after the first BEGIN_OBJECT of the MSON data format, it is separated by NAME_SEPARATOR into the form of "k = v, k = v, k =... = v", and the first and last k and v are processed separately, and each group of "v, k" separated by NAME_SEPARATOR is iteratively parsed, and v and k are parsed from each group of "v, k".
[0036] Further, when the parsing unit iteratively parses each group of "v, k" separated by NAME_SEPARATOR, it is necessary to determine the offset off and the position next of NAME_SEPARATOR; the first iteration starts from the position after the first BEGIN_OBJECT of the MSON data format, at this time off = 0, the off of the next iteration is the next of the current iteration plus 1, and the next of the next iteration is the position of the first NAME_SEPARATOR that is not within an object, not within an array, and not within a string after the off of the current iteration.
[0037] Further, when the parsing unit parses v and k from each group of "v, k", it is necessary to first determine the position vIndex of VALUE_SEPARATOR, where vIndex is the first VALUE_SEPARATOR after NAME_SEPARATOR that is not within an object, not within an array, and not within a string; then perform the following steps:
[0038] S01: If the first character of the parsed value is BEGIN_OBJECT, it is an object. Call the function str2Map to convert the string to a Map, find the position of END_OBJECT, and then parse the value of the object;
[0039] If the first character is still BEGINOBJECT, loop and call str2Map, and go to S01; if the first character is BEGIN_ARRAY, it is an array, go to S02; if it is a string, directly parse it according to the form of "k = v";
[0040] Finally, use the position of the first VALUE_SEPARATOR after END_OBJECT as vIndex;
[0041] S02: If the first character of the parsed value is BEGIN_ARRAY, call the function str2List to convert the string to an array, find the position of END_ARRAY, and then parse the value of the array;
[0042] If the first character is BEGIN_OBJECT, go to S01; if the first character is still BEGIN_ARRAY, go to S02; if it is a string, directly obtain the position of END_ARRAY, and use VALUE_SEPARATOR as the delimiter to obtain the array elements to get the value of the array;
[0043] Finally, use the position of the first VALUE_SEPARATOR after END_ARRAY as vIndex;
[0044] S03: If the parsed value is a string, directly obtain the position vIndex of VALUE_SEPARATOR;
[0045] S04: After determining the position vIndex of VALUE_SEPARATOR, the string between it and the next NAME_SEPARATOR is the next k; thus, a group of "v, k" is parsed;
[0046] S05: Iteratively parse all "v, k";
[0047] S06: Parse the last v. The last value is from the position of the last VALUE_SEPARATOR to the end of the MSON string.
[0048] At this point, the parsing unit parses the entire MSON string into two arrays consisting of v and k.
[0049] The beneficial effects of the present invention are as follows: The present invention creates a new MSON data format and provides a transmission processing method and device for this format. It supports circular nested conversion and slight error detection. The transmission message converted into an MSON string is smaller than serialized methods such as similar xml, JSON, and JDK, and the processing end processes such data into a Map object and directly uses it, which is very convenient. Description of the Drawings
[0050] Figure 1 It is a schematic diagram of the MSON string processing flow.
[0051] Figure 2 It is a schematic diagram of the MSON string parsing. Detailed Embodiments
[0052] Now, the present invention will be further described in detail with reference to the accompanying drawings.
[0053] The present invention first creates a new MSON data format and provides a transmission processing method and device for this format. MSON, named after Map String Object Notation, processes data for Map objects.
[0054] MSON is a sequence of tokens, including six construction characters and strings. In its composition structure, objects are enclosed by "{" and "}"; arrays are enclosed by "[" and "]"; the key-value pairs of Map objects are in the format of k = v, the key k is in string format, and the value v can be any nested combination of Map objects, arrays, strings, or object arrays; key-value pairs are separated by ",".
[0055] 1) The tokens include six construction characters as follows:
[0056] ·BEGIN_ARRAY = ws%x5B ws; [left square bracket
[0057] ·BEGIN_OBJECT = ws%x7B ws; {left curly brace
[0058] ·END_ARRAY = ws%x5D ws; ]right square bracket
[0059] ·END_OBJECT = ws%x7D ws;}right curly brace
[0060] ·NAME_SEPARATOR = ws%x3D ws; = equals
[0061] ·VALUE_SEPARATOR = ws%x2C ws; , comma
[0062] 2) Insignificant whitespace characters (ws) are allowed before or after these six construction characters as follows:
[0063] ·%x20; space
[0064] ·%x09; horizontal tab
[0065] ·%xOA; line feed or new line
[0066] ·%x0D; carriage return
[0067] 3) The key-value pairs included in the data format are in the form of k = v, and the key-value pairs are separated by a comma ",". The value v can be an array object or a string as follows:
[0068] ① An object consists of members separated by commas enclosed in curly braces. The members are composed of string keys and key-value pairs where the values are as described above separated by commas. For example:
[0069] {name = John Doe, age = 18,
[0070] address = {country = china, zip-code = 10000}, parameters = [10, 100]}
[0071] ② An array consists of a group of values enclosed in square brackets. For example:
[0072] [3, 1, 4, 1, 5, 9, 2, 6]
[0073] ③ A string is a collection of any number of Unicode characters.
[0074] The MSON data format defines that the object to be transmitted is a Map object. If the value of the Map object only nests strings and Map objects, the toString() method of the Map object is directly called to obtain a string in Map format, which is consistent with the MSON data format of this application and can be directly used; if the value of the Map object nests other classes, such as custom classes, these classes need to be converted into Map objects, and then the toString() of the Map object is called to obtain the MSON string.
[0075] The transmission of the MSON data format, that is, after obtaining the MSON string as above, it is transmitted as a message.
[0076] The processing of the MSON data format, that is, after the receiving end receives the MSON string, it performs a series of parsing processes to obtain a Map object.
[0077] In an embodiment of the present application, a method for transmitting and processing the MSON data format is proposed, as Figure 1 shown, and its specific processing flow is as follows:
[0078] First, the first digit of the MSON data format is "{", so it can be parsed starting from the next digit after BEGIN_OBJECT('{'), and is separated by NAME_SEPARATOR into "k=v, k=v, k=...=v". The first and last k and v are processed separately, and the middle ones are in the form of "v, k" after being separated by "=". Iteratively processing each "v, k" is the key point.
[0079] Next, iteratively parse out groups of "v, k". It is necessary to find the offset off, the position next of NAME_SEPARATOR, and the position vIndex of VALUE_SEPARATOR. The off for the next iteration is the current iteration's next + 1; the next for the next iteration is the first NAME_SEPARATOR after the current iteration's off that is not inside an object, not inside an array, and not inside a string, and the places where NAME_SEPARATOR is contained in v need to be excluded. To parse v and k from "v, k", it is necessary to first parse out the position vIndex of VALUE_SEPARATOR. vIndex is the first VALUE_SEPARATOR after NAME_SEPARATOR that is not inside an object, not inside an array, and not inside a string. It is not inside a string because the value v may also contain VALUE_SEPARATOR when it is a string, and it is also the first VALUE_SEPARATOR from the end of "v, k" going forward. Based on these two points, slight error detection and repair can be performed.
[0080] The MSON string parsing diagram is as Figure 2 shown. The value v is a segment of string between the corresponding NAME_SEPARATOR and VALUE_SEPARATOR. v is the value parsed from this segment of string. This segment of string may need to be parsed into an object, an array, a string, or may be nested with each other. If the first digit of the value is "{", it is an object; if it is "[", it is an array; and the rest are strings or literals.
[0081] S01: If it is BEGIN_OBJECT, that is, "{", call the function str2Map to convert the string to a Map. Its function is: find the position of END_OBJECT, and then parse the value of the object. If it is still BEGIN_OBJECT, recursively call str2Map and go to S01; if it is BEGIN_ARRAY, it is an array, call str2List and go to S02; otherwise, the object element is normal, and it can be directly parsed in the form of k = v. Finally, according to END_OBJECT, the position of the first VALUE_SEPARATOR after it is the value of vIndex. If there are no characters or only whitespace characters between END_OBJECT and vIndex, and if there are other characters, they can be detected and logged as a prompt, and corrected.
[0082] S02: If it is BEGIN_ARRAY, that is, "[", call the function str2List to convert the string to an array. Its function is: find the position of END_ARRAY, and then parse the value of the array, which may be an object, an array, a string, etc. If it is an object, go to S01; if it is an array, go to S02; if it is a string, directly obtain the position of END_ARRAY, and use VALUE_SEPARATOR as the delimiter to obtain the array elements, that is, obtain the value of the array. Finally, according to END_ARRAY, the position of the first VALUE_SEPARATOR after it is the position of vIndex. If there are no characters or only whitespace characters between END_ARRAY and vIndex, and if there are other characters, they can be detected and logged as a prompt, and corrected.
[0083] S03: If it is a literal such as a string, the position of VALUE_SEPARATOR can be directly obtained.
[0084] S04: After determining the position of VALUE_SEPARATOR, the string between it and the next NAME_SEPARATOR is the next k. Thus, one "v, k" is parsed.
[0085] S05: Iteratively parse all "v, k".
[0086] S06: Parse the last v. From the position of the last VALUE_SEPARATOR to the end of the string, the last value can be easily parsed.
[0087] At this point, the entire MSON string is parsed into two arrays composed of v and k. Iteratively assembling the two arrays into key-value pairs, it is successfully converted into a Map object.
[0088] In another embodiment of the present application, a transmission processing device for the MSON data format is proposed. This device can convert a Map object into an MSON string, transmit it through a byte array, and then parse it at the receiving end. Specifically, it includes:
[0089] A conversion unit for converting Map data into an MSON string;
[0090] An analysis unit for parsing the keys and values of the MSON string;
[0091] An assembly unit for assembling the parsed keys and values into key-value pairs and converting them into a Map object.
[0092] In this embodiment, the transmission processing method of the transmission processing device is the same as that of the previous embodiment.
[0093] When the present invention is specifically implemented, the following dependencies are introduced:
[0094]
[0095] The use of the tool is as follows:
[0096]
[0097] Some characteristics of the present invention are as follows:
[0098] 1. In addition to ws in the value, it also supports characters such as spaces and commas inside the value;
[0099] 2. It supports more complex arbitrary nesting between objects and arrays:
[0100] {date = 2021-06-10 18:16:15, userList = [{name = Tom, age = [{a = 0}, {a = 0}]}, {name = Jack, age = [{a = 0}, {a = 0}]}, {name = Nett, age = [{a = 0}, {a = 0}]}], penetrateDesc = Order not paid, revoked, custId = CUST2102071014421439, idList = [1, 2, 3], jack = {name = Netty, age = 11, parameters = [10, 100]}, parameters2 = [11, 111], params = [[1, 2], [3, 4], [5, 6]], params2 = [[{a = 1, b = [[1, 2], [3, 4], [5, 6]]}, {a = 11, b = [[1, 2], [3, 4], [5, 6]]}], [{a = 2, b = [[1, 2], [3, 4], [5, 6]]}, {a = 22, b = [[1, 2], [3, 4], [5, 6]]}]], paramsMap = {a = 1, b = 2}, paramsMap2 = {a = [1, 2, 3], name = 234}}
[0101] 3. Support slight error detection and repair:
[0102] {userList = [], params = [[1, 2], [3, 4], [5, 6]], penetrateDesc = Order not paid, revoked, paramsMap = {a = 1, b = 2}, paramsMap2 = {a = [1, 2, 3], name = 234}}, penetrateDesc1 = Order not paid, revoked1}
[0103] At the position of index 38, there is an extra "]", then a warn log will be printed and automatically repaired as follows:
[0104] 10:25:13.017 [main] WARN com.ccg.core.MapUtil-str2Map, char between 38~38 may has wrong String "]":
[0105] userList = [], params = [[1, 2], [3, 4], [5, 6]], penetrateDesc = Order not paid, revoked, paramsMap = {a = 1, b = 2}, paramsMap2 = {a = [1, 2, 3], name = 234}, penetrateDesc1 = Order not paid, revoked1
[0106] 4. Can be used in various scenarios of serialization / deserialization transmission:
[0107] 1) TCP and HTTP data transmission, greatly reducing transmission consumption
[0108] 2) Map data storage in Redis when serialization storage is required
[0109] 3) When sending messages via MQ, serialization is required, etc.
[0110] 5. Can be used in scenarios where it can be retrieved and used directly from logs:
[0111] It can be used in the joint debugging scenario, retrieved and used directly from the logs, and obtain a Map object to simulate joint debugging calls;
[0112] It can be used in the accident emergency handling scenario, retrieved and used directly from the production logs, and obtain a Map object for immediate handling.
[0113] As shown in Table 1, in comparison, among the byte lengths after serialization, the MSON solution of the present invention is the smallest; in the experiments of serialization / deserialization for 10 / 100 / 10,000 times, the average time consumption of this solution is the least.
[0114] Table 1 Comparison between the MSON solution and other existing solutions
[0115]
[0116] The above are only the preferred implementation manners of the present invention. The protection scope of the present invention is not limited to the above embodiments. All technical solutions falling within the concept of the present invention belong to the protection scope of the present invention. It should be noted that for those of ordinary skill in the art in this technical field, several improvements and refinements made without departing from the principle of the present invention should be regarded as within the protection scope of the present invention.
Claims
1. A transmission processing method for MSON data format, characterized in that Including: Convert Map data into an MSON string; Parse out the keys and values of the MSON string; Assemble the parsed keys and values into key-value pairs and convert them into a Map object; Among them, the MSON string contains six construction characters BEGIN_ARRAY, BEGIN_OBJECT, END_ARRAY, END_OBJECT, NAME_SEPARATOR, VALUE_SEPARATOR and strings. Among them, BEGIN_ARRAY represents a left square bracket, BEGIN_OBJECT represents a left curly brace, END_ARRAY represents a right square bracket, END_OBJECT represents a right curly brace, NAME_SEPARATOR represents an equal sign, and VALUE_SEPARATOR represents a comma; in the composition structure of the MSON string, an object is enclosed by BEGIN_OBJECT and END_OBJECT, and an array is enclosed by BEGIN_ARRAY and END_ARRAY; The key-value pair is in the form of "k = v", where k represents the key, the key is in string format, and v represents the value, and the value is an object, an array or a string; The keys and values of the parsed MSON string are as follows: start parsing from the position after the first BEGIN_OBJECT at the beginning of the MSON data format, and separate it into the form of "k = v, k = v, k =... = v" by NAME_SEPARATOR. The first and last k and v are processed separately, and each group of "v, k" separated by NAME_SEPARATOR is iteratively parsed to parse out v and k from each group of "v, k"; When parsing out v and k from each group of "v, k", it is necessary to first determine the position vIndex of the VALUE_SEPARATOR. vIndex is the first VALUE_SEPARATOR that is not inside an object, not inside an array, and not inside a string after the NAME_SEPARATOR; then perform the following steps: S01: If the first digit of the parsed value is BEGIN_OBJECT, it is an object. Call the function str2Map that converts a string to a Map, find the position of END_OBJECT, and then parse the value of the object; If the first digit is still BEGIN_OBJECT, loop and call str2Map, and go to S01; if the first digit is BEGIN_ARRAY, it is an array, go to S02; if it is a string, directly parse it according to the form of "k = v"; Finally, use the position of the first VALUE_SEPARATOR after END_OBJECT as vIndex; S02: If the first digit of the parsed value is BEGIN_ARRAY, call the function str2List that converts a string to an array, find the position of END_ARRAY, and then parse the value of the array; If the first character is BEGIN_OBJECT, go to S01; if the first character is still BEGIN_ARRAY, go to S02; if it is a string, directly obtain the position of END_ARRAY, and use VALUE_SEPARATOR as the delimiter to obtain the array elements to get the value of the array; Finally, use the position of the first VALUE_SEPARATOR after END_ARRAY as vIndex; S03: If the parsed value is a string, directly obtain the position vIndex of VALUE_SEPARATOR; S04: After determining the position vIndex of VALUE_SEPARATOR, the string between it and the next NAME_SEPARATOR is the next k; thus, a set of "v, k" is parsed; S05: Iteratively parse all "v, k"; S06: Parse the last v, and the string from the position of the last VALUE_SEPARATOR to the end of the MSON string is the last value; Thus, the entire MSON string is parsed into two arrays composed of v and k.
2. The transmission processing method of the MSON data format according to claim 1, characterized in that: When iteratively parsing each group of "v, k" separated by NAME_SEPARATOR, it is necessary to determine the offset off and the position next of NAME_SEPARATOR; the first iteration starts from the position after the first BEGIN_OBJECT at the beginning of the MSON data format, at this time off = 0, the off of the next iteration is the next of the current iteration plus 1, and the next of the next iteration is the position of the first NAME_SEPARATOR that is not within an object, not within an array, and not within a string after the off of the current iteration.
3. A transmission processing device for MSON data format, characterized in that, Including: A conversion unit for converting Map data into an MSON string; A parsing unit for parsing the keys and values of the MSON string; An assembly unit for assembling the parsed keys and values into key-value pairs and converting them into a Map object; Among them, the MSON string contains six construction characters BEGIN_ARRAY, BEGIN_OBJECT, END_ARRAY, END_OBJECT, NAME_SEPARATOR, VALUE_SEPARATOR and strings, where BEGIN_ARRAY represents a left square bracket, BEGIN_OBJECT represents a left curly brace, END_ARRAY represents a right square bracket, END_OBJECT represents a right curly brace, NAME_SEPARATOR represents an equal sign, and VALUE_SEPARATOR represents a comma; in the composition structure of the MSON string, an object is enclosed by BEGIN_OBJECT and END_OBJECT, and an array is enclosed by BEGIN_ARRAY and END_ARRAY; The key-value pair is in the form of "k = v", where k represents the key, the key is in string format, and v represents the value, and the value is an object, an array or a string; The parsing unit parses the keys and values of the MSON string as follows: starting from the position after the first BEGIN_OBJECT in the MSON data format, it is separated by NAME_SEPARATOR into the form of "k=v,k=v,k=…=v", and the first and last k and v are processed separately. Iteratively parse each group of "v,k" separated by NAME_SEPARATOR, and parse v and k from each group of "v,k". When the parsing unit parses v and k from each group of "v,k", it needs to first determine the position vIndex of VALUE_SEPARATOR. vIndex is the first VALUE_SEPARATOR that is not within an object, not within an array, and not within a string after NAME_SEPARATOR. Then perform the following steps: S01: If the first character of the parsed value is BEGIN_OBJECT, it is an object. Call the function str2Map that converts a string to a Map, find the position of END_OBJECT, and then parse the value of the object. If the first character is still BEGIN_OBJECT, loop and call str2Map, and go to S01; if the first character is BEGIN_ARRAY, it is an array, go to S02; if it is a string, directly parse it according to the form of "k=v". Finally, use the position of the first VALUE_SEPARATOR after END_OBJECT as vIndex. S02: If the first character of the parsed value is BEGIN_ARRAY, call the function str2List that converts a string to an array, find the position of END_ARRAY, and then parse the value of the array. If the first character is BEGIN_OBJECT, go to S01; if the first character is still BEGIN_ARRAY, go to S02; if it is a string, directly obtain the position of END_ARRAY, and use VALUE_SEPARATOR as the delimiter to obtain the array elements to get the value of the array. Finally, use the position of the first VALUE_SEPARATOR after END_ARRAY as vIndex. S03: If the parsed value is a string, directly obtain the position vIndex of VALUE_SEPARATOR. S04: After determining the position vIndex of VALUE_SEPARATOR, the string between it and the next NAME_SEPARATOR is the next k. Thus, parsing of a group of "v,k" is completed. S05: Iteratively parse all "v,k". S06: Parse the last v. The part from the position of the last VALUE_SEPARATOR to the end of the MSON string is the last value. Thus, the parsing unit parses the entire MSON string into two arrays composed of v and k.
4. The transmission processing device for the MSON data format according to claim 3, characterized in that: When the parsing unit iteratively parses each group of "v,k" separated by NAME_SEPARATOR, it is necessary to determine the offset off and the position next of NAME_SEPARATOR; the first iteration starts from the position after the first BEGIN_OBJECT at the beginning of the MSON data format. At this time, off = 0. The off for the next iteration is the current iteration's next plus 1, and the next for the next iteration is the position of the first NAME_SEPARATOR that is not within an object, not within an array, and not within a string after the current iteration's off.
Citation Information
Patent Citations
Android system component version information assembling method and device
CN109992293A