Disclosure of Invention
In view of this, embodiments of the present invention provide a method, an apparatus, and a device for converting a data format, so as to solve the problems that the number of converters is continuously increased and the adaptability is poor when data format conversion is performed in the prior art.
A first aspect of an embodiment of the present invention provides a data format conversion method, including:
receiving data of a format to be converted, and determining that the data format of the received data is a first data format;
reading a corresponding conversion configuration file according to the converted second data format and the first data format;
and converting the received data into data in a target data format according to the read conversion configuration file.
With reference to the first aspect, in a first possible implementation manner of the first aspect, the reading, according to the converted second data format and the first data format, a corresponding conversion configuration file includes:
comparing whether the format to be converted of the configuration file is the same as the first data format or not, and comparing whether the converted target format of the configuration file is the same as the second data format or not;
and if the configuration file and the configuration file are the same, the searched configuration file is the configuration file corresponding to the first data format and the second data format.
With reference to the first aspect, in a second possible implementation manner of the first aspect, the reading, according to the converted second data format and the first data format, a corresponding conversion configuration file includes:
when the configuration file does not comprise the configuration file converted from the first data format into the second data format, searching whether the configuration file converted from the first data format into the third data format exists or not, and searching whether the configuration file converted from the third data format into the second data format exists or not;
the step of converting the received data into data of a target data format according to the read conversion configuration file includes:
converting the data in the first data format into the data in the third data format according to the configuration file converted from the first data format into the third data format;
and converting the data in the third data format into the data in the second data format according to the configuration file converted into the second data format from the third data format.
With reference to the first aspect, in a third possible implementation manner of the first aspect, the determining that the data format of the received data is the first data format includes:
and searching the equipment number of the data with the format to be converted at the corresponding storage position according to the corresponding relation between the preset data format and the equipment number storage position, and determining the data format of the received data according to the searched equipment number.
With reference to the first aspect, the first possible implementation manner of the first aspect, the second possible implementation manner of the first aspect, or the third possible implementation manner of the first aspect, in a fourth possible implementation manner of the first aspect, the data format is any one of a JSON object markup JSON data format, an original data format, or a wireless machine communication protocol WMMP data format.
A second aspect of an embodiment of the present invention provides a data format conversion apparatus, including:
the data receiving unit is used for receiving the data with the format to be converted and determining that the data format of the received data is a first data format;
a configuration file reading unit, configured to read a corresponding conversion configuration file according to the converted second data format and the first data format;
and the conversion unit is used for converting the received data into data in a target data format according to the read conversion configuration file.
With reference to the second aspect, in a first possible implementation manner of the second aspect, the configuration file reading unit includes:
the comparison subunit is configured to compare whether the format to be converted of the configuration file is the same as the first data format, and compare whether the converted target format of the configuration file is the same as the second data format;
and the first searching subunit is configured to, if the two are the same, find the configuration file corresponding to the first data format and the second data format.
With reference to the second aspect, in a second possible implementation manner of the second aspect, the configuration file reading unit includes:
the second searching subunit is used for searching whether a configuration file with the first data format converted into a third data format exists or not and a configuration file with the third data format converted into the second data format exists when the configuration file does not include the configuration file with the first data format converted into the second data format;
the conversion unit includes:
the first conversion subunit is used for converting the data in the first data format into the data in the third data format according to the configuration file converted from the first data format into the third data format;
and the second conversion subunit is used for converting the data in the third data format into the data in the second data format according to the configuration file converted from the third data format into the second data format.
A third aspect of embodiments of the present invention provides a data format conversion device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the data format conversion method according to any one of the first aspect when executing the computer program.
A fourth aspect of embodiments of the present invention provides a computer-readable storage medium, which stores a computer program that, when executed by a processor, implements the steps of the data format conversion method according to any one of the first aspects.
Compared with the prior art, the embodiment of the invention has the following beneficial effects: the received data can be effectively converted into the data in the target format by presetting a plurality of configuration files for converting different data formats and reading the corresponding configuration files according to the acquired first data format and the converted second data format of the data in the format to be converted, so that the requirements of converting various different types of data formats can be effectively met, and the number of converters can be reduced.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system structures, techniques, etc. in order to provide a thorough understanding of the embodiments of the invention. It will be apparent, however, to one skilled in the art that the present invention may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present invention with unnecessary detail.
In order to explain the technical means of the present invention, the following description will be given by way of specific examples.
Fig. 1 is a schematic flow chart illustrating an implementation process of a data format conversion method according to an embodiment of the present application, which is detailed as follows:
in step S101, receiving data of a format to be converted, and determining that a data format of the received data is a first data format;
specifically, the data with the format to be converted may be data sent by an internet of things device, and a device receiving the data may be a data processing server correspondingly. Of course, the data in the format to be converted may also be data sent or received by other devices that need to perform data conversion.
The format to be converted can be an original data format, a JSON data format marked by JS objects, a WMMP data format of a wireless machine communication protocol, or the like. Correspondingly, the converted data format can also be an original data format, a JSON data format marked by JS object, a WMMP data format of wireless machine communication protocol, or the like. The converted data format is inconsistent with the converted data format.
In order to realize the conversion of data in different data formats, a data protocol conversion algorithm can be adopted to analyze the data to be converted, and the data corresponding to the converted data format is generated by combining the protocol corresponding to the converted data format according to the analysis result.
The format of the received data in the format to be converted is determined, identifier data may be set at a predetermined position, such as a start position of the data or other positions of the data, by setting an identifier, and the data format of the data in the format to be converted may be correspondingly obtained according to a corresponding relationship between the identifier and the data format.
As a preferred embodiment, the data format may be represented by a device number. The method comprises the steps of setting an identifier of an equipment number in data, determining the equipment number corresponding to the data with the data format to be converted according to the identifier of the equipment number, and further determining the format of the data with the data format to be converted to be the first data format according to the equipment number.
In step S102, reading a corresponding conversion configuration file according to the converted second data format and the first data format;
the configuration file stores two protocols of data formats to be converted, data can be analyzed through any one of the two protocols, and the analyzed data is generated into data of a corresponding data format through the other protocol.
The second data format is determined according to the target data format required for conversion. And searching a required configuration file in a preset configuration file library according to the first data format and the second data format. The configuration file may be one or multiple, and a specific search process of the configuration file may be as shown in fig. 2, including:
in step S201, comparing whether the format to be converted of the configuration file is the same as the first data format, and comparing whether the converted target format of the configuration file is the same as the second data format;
the format to be converted and the converted target format are defined in each configuration file, and in order to effectively find the required configuration file, the format to be converted and the first data format, and the converted target format and the second data format need to be respectively compared.
In step S202, if the two are the same, the searched configuration file is a configuration file corresponding to the first data format and the second data format.
If the format conversion relation of the configuration file can be directly found to be matched with the data format to be converted and the converted data format, the configuration file can be directly read to convert the format of the data. When the corresponding configuration file cannot be found in the configuration file library, the present application may further perform format conversion on the data file in a manner of connecting a plurality of configuration files, specifically as shown in step S203:
in step S203, when the configuration file converted from the first data format to the second data format is not included in the configuration file, searching whether a configuration file converted from the first data format to the third data format exists or not, and a configuration file converted from the third data format to the second data format exists;
if the configuration file which can directly meet the conversion condition cannot be searched in the configuration file library, a plurality of configuration files can be further searched, and format conversion is carried out on the data file in a mode that the configuration files are combined into a connector.
For example, all first configuration file sets meeting the condition may be searched for through a first data format of a data file to be converted, a second configuration file set may be searched for according to a second data format, and configuration files including the same third data format may be respectively searched for according to the first configuration file set and the second configuration file set, that is, the configuration files in the first configuration file set may convert the first data format into the third data format, and the configuration files in the second configuration file set may convert the third data format into the second data format.
Of course, this is only one possible conversion method, and when two configuration files still cannot meet the conversion requirement, the data may also be formatted through three configuration files, or more than three configuration files. Therefore, the conversion requirements of different data can be better met.
In step S103, the received data is converted into data in the target data format according to the read conversion profile.
If a configuration file meeting the conversion requirement can be directly found, the configuration file can be directly read to convert the format of the data to be converted.
If the data needs to be format-converted by means of two configuration file connections, the steps S204 to S205 shown in fig. 2 may specifically include:
in step S204, converting the data in the first data format into the data in the third data format according to the configuration file converted from the first data format into the third data format;
the first data format may be converted to a first configuration file of a third data format from which data may be converted, and the third data format may be further converted to a second data format from a second configuration file.
In step S205, the data in the third data format is converted into the data in the second data format according to the configuration file in which the third data format is converted into the second data format.
According to the first configuration file set and the second configuration file set selected in step S203, the first configuration file and the second configuration file meeting the conversion requirement can be found correspondingly, and the data format to be converted can be effectively converted into the target data format through the sequential conversion of the two configuration files. The method can meet the conversion requirements of various different data formats, thereby greatly reducing the number of the analysis server for the types of the converters and being beneficial to improving the conversion efficiency.
Fig. 3 is a schematic implementation flow diagram of another data format conversion method provided in the embodiment of the present application, which is detailed as follows:
in step S301, receiving data of a format to be converted, searching for an equipment number of the data of the format to be converted at a corresponding storage location according to a corresponding relationship between a preset data format and an equipment number storage location, and determining a data format of the received data according to the searched equipment number;
specifically, the data to be converted may be set with a predetermined length data representing device number at a specified position, for example, 1 to 19 bits in the original data may represent device number. By determining the device number, the data format corresponding to the device number can be found correspondingly according to the corresponding relationship between the device number and the data format. Of course, the data format identifier of the device may also be directly set, so that the device can directly analyze the data format corresponding to the data in the format to be converted.
In step S302, a corresponding conversion configuration file is read according to the converted second data format and the first data format.
In step S303, the received data is converted into data in the target data format according to the read conversion profile.
Steps S302-S303 are substantially the same as steps S102-S103 in fig. 1.
In the data format conversion method shown in fig. 3, the identification information of the device number is set at the designated position of the data file, and the data format of the corresponding data in the format to be converted can be conveniently found through the identification information.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
Fig. 4 is a schematic structural diagram of a data format conversion device according to an embodiment of the present application, which is detailed as follows:
the data format conversion apparatus includes:
adata receiving unit 401, configured to receive data of a format to be converted, and determine that a data format of the received data is a first data format;
a configurationfile reading unit 402, configured to read a corresponding converted configuration file according to the converted second data format and the first data format;
a convertingunit 403, configured to convert the received data into data in the target data format according to the read conversion configuration file.
Preferably, the configuration file reading unit includes:
the comparison subunit is configured to compare whether the format to be converted of the configuration file is the same as the first data format, and compare whether the converted target format of the configuration file is the same as the second data format;
and the first searching subunit is configured to, if the two are the same, find the configuration file corresponding to the first data format and the second data format.
Preferably, the configuration file reading unit includes:
the second searching subunit is used for searching whether a configuration file with the first data format converted into a third data format exists or not and a configuration file with the third data format converted into the second data format exists when the configuration file does not include the configuration file with the first data format converted into the second data format;
the conversion unit includes:
the first conversion subunit is used for converting the data in the first data format into the data in the third data format according to the configuration file converted from the first data format into the third data format;
and the second conversion subunit is used for converting the data in the third data format into the data in the second data format according to the configuration file converted from the third data format into the second data format.
The data format conversion apparatus shown in fig. 4 corresponds to the data format conversion method shown in fig. 1 to 3.
Fig. 5 is a schematic diagram of a data format conversion device according to an embodiment of the present invention. As shown in fig. 5, the dataformat conversion device 5 of this embodiment includes: aprocessor 50, amemory 51 and acomputer program 52, such as a data format conversion program, stored in saidmemory 51 and executable on saidprocessor 50. Theprocessor 50, when executing thecomputer program 52, implements the steps in the above-described embodiments of the data format conversion method, such as the steps 101 to 103 shown in fig. 1. Alternatively, theprocessor 50, when executing thecomputer program 52, implements the functions of each module/unit in the above-mentioned device embodiments, for example, the functions of the modules 501 to 503 shown in fig. 5.
Illustratively, thecomputer program 52 may be partitioned into one or more modules/units that are stored in thememory 51 and executed by theprocessor 50 to implement the present invention. The one or more modules/units may be a series of computer program instruction segments capable of performing specific functions, which are used to describe the execution process of thecomputer program 52 in the dataformat conversion device 5. For example, thecomputer program 52 may be divided into a data receiving unit, a configuration file reading unit and a converting unit, and the specific functions of each unit are as follows:
the data receiving unit is used for receiving the data with the format to be converted and determining that the data format of the received data is a first data format;
a configuration file reading unit, configured to read a corresponding conversion configuration file according to the converted second data format and the first data format;
and the conversion unit is used for converting the received data into data in a target data format according to the read conversion configuration file.
The dataformat conversion device 5 may be a desktop computer, a notebook, a palm computer, a cloud server, or other computing devices. The data format conversion device may include, but is not limited to, aprocessor 50, amemory 51. It will be appreciated by those skilled in the art that fig. 5 is merely an example of the dataformat conversion device 5, and does not constitute a limitation of the dataformat conversion device 5, and may include more or less components than those shown, or combine some components, or different components, for example, the data format conversion device may also include an input output device, a network access device, a bus, etc.
TheProcessor 50 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
Thememory 51 may be an internal storage unit of the dataformat conversion device 5, such as a hard disk or a memory of the dataformat conversion device 5. Thememory 51 may also be an external storage device of the dataformat conversion device 5, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), or the like, provided on the dataformat conversion device 5. Further, thememory 51 may also include both an internal storage unit of the dataformat conversion device 5 and an external storage device. Thememory 51 is used to store the computer program and other programs and data required by the data format conversion device. Thememory 51 may also be used to temporarily store data that has been output or is to be output.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-mentioned functions. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the system may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus/terminal device and method may be implemented in other ways. For example, the above-described embodiments of the apparatus/terminal device are merely illustrative, and for example, the division of the modules or units is only one logical division, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated modules/units, if implemented in the form of software functional units and sold or used as separate products, may be stored in a computer readable storage medium. Based on such understanding, all or part of the flow of the method according to the embodiments of the present invention may also be implemented by a computer program, which may be stored in a computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method embodiments may be implemented. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like. It should be noted that the computer readable medium may contain other components which may be suitably increased or decreased as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media which may not include electrical carrier signals and telecommunications signals in accordance with legislation and patent practice.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present invention, and not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present invention, and are intended to be included within the scope of the present invention.