CN111104097B - Data writing and reading method and device - Google Patents

Data writing and reading method and device Download PDF

Info

Publication number
CN111104097B
CN111104097B CN201911286323.0A CN201911286323A CN111104097B CN 111104097 B CN111104097 B CN 111104097B CN 201911286323 A CN201911286323 A CN 201911286323A CN 111104097 B CN111104097 B CN 111104097B
Authority
CN
China
Prior art keywords
data
type
target
target data
data type
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.)
Active
Application number
CN201911286323.0A
Other languages
Chinese (zh)
Other versions
CN111104097A (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.)
Shanghai Zhongyuan Network Co ltd
Original Assignee
Shanghai Zhongyuan Network 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 Shanghai Zhongyuan Network Co ltd filed Critical Shanghai Zhongyuan Network Co ltd
Priority to CN201911286323.0A priority Critical patent/CN111104097B/en
Publication of CN111104097A publication Critical patent/CN111104097A/en
Application granted granted Critical
Publication of CN111104097B publication Critical patent/CN111104097B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/20Software design
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0602Interfaces specially adapted for storage systems specifically adapted to achieve a particular effect
    • G06F3/0604Improving or facilitating administration, e.g. storage management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0602Interfaces specially adapted for storage systems specifically adapted to achieve a particular effect
    • G06F3/0614Improving the reliability of storage systems
    • G06F3/0619Improving the reliability of storage systems in relation to data integrity, e.g. data losses, bit errors
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The embodiment of the invention provides a data writing and reading method and device, wherein the method comprises the following steps: when a write-in instruction aiming at target data is received, determining the target data type of the target data and target identification information of the target data; judging whether the target data type of the target data is a preset data type or not; if the target data type of the target data is the preset data type, calling a general data writing method, and transmitting the target data and a writing method name corresponding to the target identification information into a storage space; if the target data type of the target data is a non-preset data type, converting the target data type into a preset data type, calling a universal data writing method, and transmitting the writing method name and the target data of the preset data type into a storage space. The embodiment of the invention prevents the setting error of the data type when the data is read by defining the data type when the data is written.

Description

Data writing and reading method and device
Technical Field
The present invention relates to the field of data reading and writing technologies, and in particular, to a method and an apparatus for writing and reading data.
Background
In the programming process, the written data generally cannot indicate the data type, so that when a computer reads the data, the technician is often required to manually set the data type of the read data, and the set read data type is easy to be different from the written data type, so that data disorder and even software breakdown are caused.
Disclosure of Invention
The embodiment of the invention aims to provide a data writing and reading method and device so as to achieve the consistency of the data type of read data and the data type of input data. The specific technical scheme is as follows:
in a first aspect of the present invention, there is provided a data writing method, the method comprising:
when a write instruction for target data is received, determining a target data type of the target data and target identification information of the target data;
judging whether the target data type of the target data is a preset data type or not;
if the target data type of the target data is a preset data type, a universal data writing method is called, and the target data and a writing method name corresponding to the target identification information are transmitted into a storage space;
and if the target data type of the target data is a non-preset data type, converting the target data type into a preset data type, calling the universal data writing method, and transmitting the writing method name and the target data of the preset data type into the storage space.
Optionally, before determining whether the target data type of the target data is the preset data type, the method further includes:
Generating attribute information containing the target identification information and the target data type;
acquiring a writing method name and a reading method name of the target identification information according to the target identification information, and acquiring a general type writing method and a general type reading method of the target data type according to the target data type, wherein the general type writing method is used for converting the target data from the target data type to the preset data type, and the general type reading method is used for converting the target data from the preset data type to the target data type;
respectively directing the address of the write method name to the universal type write method, and directing the address of the read method name to the universal type read method;
and respectively pointing the universal type writing method to the universal data writing method and pointing the universal type reading method to the universal data reading method.
In a second aspect of the present invention, there is provided a data reading method, the method comprising:
receiving a reading instruction, wherein the reading instruction comprises target identification information of data to be read;
inquiring a target data type corresponding to the target identification information according to pre-declared attribute information, wherein the attribute information comprises identification information and data types of each data;
Reading data corresponding to the target identification information from a storage space by a general data reading method, and judging whether the read data type is the same as the target data type, wherein the data is the data of the preset data type written into the storage space;
and if the read data type is different from the target data type, converting the read data into the data of the target data type to obtain the target data.
Optionally, the storage space is a persistence container; the reading the data corresponding to the target identification information from the storage space by the universal data reading method comprises the following steps:
determining a reading method name corresponding to the target identification information;
transmitting the read method name into the persistence container through a universal data read method;
and reading the data corresponding to the target identification information from the persistence container.
Optionally, said passing said read method name into said persistence container by a generic data read method includes:
converting the reading method name into a container reading method name through a name conversion method;
and transmitting the name of the container reading method into a persistent container through the universal data reading method.
Optionally, the converting the read data into the data of the target data type includes:
and converting the read data into the data of the target data type through a general type reading method corresponding to the target data type.
In a third aspect of the present invention, there is provided a data writing apparatus, the apparatus comprising:
the determining module is used for determining the target data type of the target data and the target identification information of the target data when a writing instruction aiming at the target data is received;
the judging module is used for judging whether the target data type of the target data is a preset data type or not;
the first input module is used for calling a general data writing method if the target data type of the target data is a preset data type, and inputting the target data and a writing method name corresponding to the target identification information into a storage space;
and the second incoming module is used for converting the target data type into a preset data type if the target data type of the target data is a non-preset data type, calling the universal data writing method and introducing the writing method name and the target data of the preset data type into the storage space.
In a fourth aspect of the present invention, there is provided a data reading apparatus, the apparatus comprising:
the receiving module is used for receiving a reading instruction, wherein the reading instruction comprises target identification information of data to be read;
the query module is used for querying a target data type corresponding to the target identification information according to pre-declared attribute information, wherein the attribute information comprises identification information and data types of each data;
the reading module is used for reading data corresponding to the target identification information from a storage space through a general data reading method and judging whether the type of the read data is the same as the type of the target data, wherein the data is the data of the preset data type written into the storage space;
and the conversion module is used for converting the read data into the data of the target data type if the read data type is different from the target data type, so as to obtain the target data.
In yet another aspect of the present invention, there is also provided a computer readable storage medium having instructions stored therein, which when executed on a computer, cause the computer to perform a data writing and reading method as described in any one of the above.
In yet another aspect of the present invention, there is also provided a computer program product containing instructions which, when run on a computer, cause the computer to perform a data writing, reading method as described in any of the above.
According to the data writing and reading method provided by the embodiment of the invention, the target data type of the target data is defined when the data is written, so that the terminal equipment automatically acquires the target data type when the data is read, and the manually set read data type is prevented from being different from the type of the written data; in addition, the embodiment of the invention stores the target data into the persistence container, so that the target data can be stored in the persistence container for a long time, and the target data is prevented from being lost.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below.
FIG. 1 is a schematic diagram of a method for writing data according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a method for generating attribute information according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of a method for reading data according to an embodiment of the invention;
FIG. 4 is a schematic diagram of a method for reading data from a memory space according to an embodiment of the invention;
FIG. 5 is a schematic diagram of a method for entering a read method name into a persistence container in an embodiment of the invention;
FIG. 6 is a flowchart of a data writing method according to an embodiment of the present invention;
FIG. 7 is a flowchart of a data reading method according to an embodiment of the present invention;
FIG. 8 is a schematic diagram of an apparatus for writing data according to an embodiment of the present invention;
FIG. 9 is a schematic diagram of an apparatus for reading data according to an embodiment of the present invention;
fig. 10 is a schematic structural diagram of a terminal device in an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be described below with reference to the accompanying drawings in the embodiments of the present invention.
The embodiment of the invention provides a data writing method which is applied to terminal equipment, wherein the terminal equipment is used for acquiring the data type of target data to be written and storing the target data of a preset data type in a persistence container.
The following will take a terminal device as an example, and describe in detail a data writing method provided by the embodiment of the present invention in connection with a specific implementation manner: the method comprises the steps that a terminal device determines a target data type of target data and target identification information of the target data according to a writing instruction aiming at the target data, obtains a writing method name and a reading method name of the target identification information according to the target identification information, obtains a general type writing method and a general type reading method of the target data type according to the target data type, and calls the general data writing method if the terminal device judges that the target data type of the target data is a preset data type, and transmits the target data and the writing method name corresponding to the target identification information into a storage space; if the terminal equipment judges that the target data type of the target data is a non-preset data type, converting the target data type into a preset data type, calling a universal data writing method, and transmitting the writing method name and the target data of the preset data type into a storage space.
A data writing method is that a terminal device transmits a writing method name and target data of a preset data type to a storage space, as shown in figure 1,
step 101: when a write instruction for target data is received, a target data type of the target data and target identification information of the target data are determined.
In the embodiment of the invention, when the terminal equipment receives the writing instruction aiming at the target data, the target identification information and the target data type of the target data can be determined according to the target data, wherein the writing instruction can be generated in response to user operation or can be generated by triggering a system program in the system operation process of the terminal equipment.
For example, when the terminal device receives the write command, the target data of the write command is "YES", and then the terminal device may determine that the target identification information is audioswitch open and the data type is boolean.
Step 102: and judging whether the target data type of the target data is a preset data type or not.
In the embodiment of the present invention, the preset data type is an OC type, and the target data type is an OC type or a non-OC type, so that in order to make the data types of the target data in the incoming persistent container consistent, the terminal device needs to determine whether the target data type of the target data is the preset data type.
Step 103: and if the target data type of the target data is the preset data type, calling a general data writing method, and transmitting the target data and a writing method name corresponding to the target identification information into a storage space.
In the embodiment of the invention, if the target data type of the target data is the preset data type, the terminal equipment does not need to perform type conversion on the target data type any more, the terminal equipment analyzes the write method name into the target identification information through a name conversion method, maps the target identification information into the container write method name, and transmits the container write method name and the target data into the persistent container through a general data write method.
For example, if the target data is YES, the writing method is named as "setaudioswitch open", the target data type is "OC", the terminal device encapsulates "YES" as "oc_yes", the name conversion method parses "setaudioswitch open" into "audioswitch open", then maps "audioswitch open" into "com.reader.audioswitch open", and transmits "com.reader.audioswitch open" and "oc_yes" into the persistence container through the general data writing method.
Step 104: if the target data type of the target data is a non-preset data type, converting the target data type into a preset data type, calling a universal data writing method, and transmitting the writing method name and the target data of the preset data type into a storage space.
In the embodiment of the invention, if the target data type of the target data is a non-preset data type, the terminal equipment converts the target data type into the preset data type through a general type writing method, analyzes the writing method name into target identification information through a name conversion method, maps the target identification information into a container writing method name, and finally transmits the container writing method name and the target data of the preset data type into a persistence container.
For example, if the target data is YES, the writing method is named as "setaudioswitch open", the target data type is "BOOL", the terminal device converts the target data type from the BOOL type to the OC type through the general type writing method, encapsulates the "YES" into the "oc_yes", the name conversion method parses the "setaudioswitch open" into "audioswitch open", and then maps the "audioswitch open" into "com.reader.audioswitch open", and transfers the "com.reader.audioswitch open" and the "oc_yes" into the persistence container through the general data writing method.
Optionally, before determining whether the target data type of the target data is the preset data type, the terminal device generates attribute information, as shown in fig. 2:
Step 201: attribute information including target identification information and a target data type is generated.
In the embodiment of the invention, the terminal equipment generates attribute information by adopting a +load method, wherein the attribute information comprises identification information and data types of all data, and then the attribute information also comprises target identification information and target data types.
Step 202: according to the target identification information, a write method name and a read method name of the target identification information are obtained, and according to the target data type, a general type write method and a general type read method of the target data type are obtained, wherein the general type write method is used for converting the target data from the target data type to a preset data type, and the general type read method is used for converting the target data from the preset data type to the target data type.
In the embodiment of the invention, the terminal equipment acquires the write method name and the read method name of the target identification information according to the target identification information, and in one implementation mode, adds set before the name of the target identification information, and capitalizes the initial of the name of the target identification information to obtain the write method name; the name of the target identification information is the same as the name of the reading method. If the name of the target identification information is audioswitch open, the writing method is named setaudioswitch open, and the reading method is named audioswitch open. The present invention does not limit the specific acquisition process of the read method name and the write method name.
In the embodiment of the invention, a terminal device obtains a general type writing method and a general type reading method of a target data type according to the target data type, specifically, the target data type is converted into a fixed format to obtain a corresponding general type writing method and a general type reading method, if the target data type is BOOL, the general type writing method is a generalBoolSetter, and the general type reading method is a generalBoolGetter; if the target data type is Int, the general type writing method is generatlntlsetter, and the general type reading method is generatlntgetter.
The general type writing method is used for converting the target data from the target data type to the preset data type if the target data type of the target data is not the preset data type in the data writing process, and the general type reading method is used for converting the target data from the preset data type to the target data type if the read data type is different from the target data type in the data reading process.
Step 203: the addresses of the write method names are respectively directed to the universal type write methods, and the addresses of the read method names are directed to the universal type read methods.
In the embodiment of the invention, the terminal equipment points the address of the write method name to the universal type write method, and points the address of the read method name to the universal type read method, so that the universal type write method can be called by adopting the write method name, and the universal type read method can be called by adopting the read method name. In the embodiment of the invention, a method_setmaterialization method of run time is adopted, the address of the write method name is pointed to a universal type write method, and the address of the read method name is pointed to a universal type read method.
Step 204: the general type writing method is directed to the general data writing method, and the general type reading method is directed to the general data reading method, respectively.
In the embodiment of the invention, the terminal equipment points the universal type writing method to the universal data writing method and points the universal type reading method to the universal data reading method respectively, so that the data types of the target data transmitted into the persistence container are consistent, different rules are prevented from being established for the target data of different data types, and the efficiency and the accuracy are improved.
The application also provides a data reading method, which comprises the specific steps as shown in fig. 3:
step 301: and receiving a reading instruction, wherein the reading instruction comprises target identification information of data to be read.
In the embodiment of the invention, after the terminal device writes the target data into the storage space, the terminal device may receive a read instruction, where the read instruction includes target identification information of the data to be read. The reading instruction may be generated in response to a user operation, or may be generated by triggering a system program in a system operation process of the terminal device.
Step 302: and inquiring the target data type corresponding to the target identification information according to the pre-declared attribute information, wherein the attribute information comprises the identification information and the data type of each data.
In the embodiment of the present invention, the attribute information includes identification information of each data, specifically, each data corresponds to one attribute information, and the declaration process of the attribute information is noted in the foregoing.
The terminal device may query attribute information including the target identification information according to the target identification information in the read instruction, and further obtain a target data type corresponding to the target identification information from the attribute information, where in the embodiment of the present invention, the storage space may be a persistent container.
In an embodiment of the present invention, the data types may include an OC (object-C) type and a non-OC type, wherein the non-OC type includes, but is not limited to, a boolean type, an integer type, etc., and the OC type includes a string type, a NSObject type, etc. The target data type corresponding to the target identification information may be an OC type or a non-OC type.
Step 303: and reading data corresponding to the target identification information from the storage space by a general data reading method, and judging whether the read data type is the same as the target data type, wherein the data is the data of the preset data type written into the storage space.
In the embodiment of the invention, the terminal equipment can store a general data reading method, wherein the general data reading method is applicable to OC type data. The terminal equipment reads data corresponding to the target identification information from the storage space through a preset general data reading method, wherein the data is data of a preset data type written into the storage space. Specifically, the data types of the data read from the storage space are OC types, and since the target data type of the target data is not necessarily OC type, the terminal device is required to determine whether the read data type is the same as the target data type.
Step 304: if the read data type is different from the target data type, converting the read data into the data of the target data type to obtain the target data.
In the embodiment of the invention, as the data type read by the terminal equipment is the OC type, if the target data type is the non-OC type, the read data type is different from the target data type, the terminal equipment converts the read data of the OC type into the data of the target data type through a general type reading method, and obtains the target data of the target data type; if the target data type is OC type, the read data type is the same as the target data type, and the terminal equipment reads the target data of the target data type.
For example, if the target data type is a boolean type and belongs to a non-OC type, the target data type and the read OC type are different, and the terminal converts the read OC type data into boolean type data to obtain boolean type target data.
Optionally, reading data corresponding to the target identification information from the storage space, as shown in fig. 4, includes:
step 401: and determining a reading method name corresponding to the target identification information.
In the embodiment of the invention, the terminal equipment can obtain the general type reading method corresponding to the target data type through the target data type of the target data. In the general type reading method, the terminal device obtains a reading method name corresponding to the target identification information through_cmd (command prompt), wherein the reading method name is the same as the target identification information, for example, the target identification information is audioswitch open, and the reading method name is audioswitch open.
Step 402: the read method name is passed into the persistence container by a generic data read method.
In the embodiment of the invention, the terminal equipment transmits the reading method name into the storage space through the universal data reading method, and particularly, in the embodiment of the invention, the storage space is a persistent container. The storage space can also be a container such as NSUserDefaults, a database, a file and the like, and the invention does not limit the storage space specifically.
Step 403: and reading the data corresponding to the target identification information from the persistent container.
In the embodiment of the invention, after the terminal equipment transmits the reading method name corresponding to the target identification information into the persistence container, a preset general data reading method is called, and the data corresponding to the target identification information is read from the persistence container.
Optionally, converting the read method name by a name conversion method, and transferring the converted read method name into a persistence container, as shown in fig. 5, including:
step 501: the read method name is converted into a container read method name by a name conversion method.
In the embodiment of the invention, in the process of transmitting the reading method name into the persistent container, the terminal equipment analyzes the reading method name into target identification information through a name conversion method, and maps the target identification information into the container reading method name according to preset mapping information.
In the embodiment of the invention, the names of the reading method names are shorter, repeated names are easy to generate among the reading method names in the persistent container, the repeated probability can be reduced by converting the reading method names with shorter names into the container reading method names with longer names, data confusion is avoided, in addition, after the persistent container is upgraded, the original reading method names are not suitable for the updated persistent container, so that the adaptability of the reading method names can be improved by converting the reading method names into the container reading method names.
For example, the read method name may be audioswitch open, the terminal device parses the read method name into audioswitch open through a name conversion method, and then the name conversion method maps audioswitch open into com.
Step 502: the container read method name is passed into the persistence container by a generic data read method.
In the embodiment of the invention, the terminal equipment calls a general data reading method and transmits the converted container reading method name into the persistent container. Generally, the read data needs to call the target data which is written in advance, the target data is stored in the memory of the terminal equipment, and once the terminal equipment is powered off or is turned off accidentally, the target data in the memory disappears, so that the target data needs to be stored in a persistence container, and the permanence of the target data is ensured.
Optionally, if the read data type is different from the target data type, converting the read data into the data of the target data type by a general type reading method corresponding to the target data type.
In the embodiment of the invention, the target data type corresponding to the target data is OC type or non-OC type, but the data type read by the terminal equipment from the persistence container is OC type, in order to ensure that the target data keeps the original data type, the terminal equipment needs to judge whether the read data type and the target data type are the same, if the terminal equipment judges that the read data type is different from the target data type, the data of the OC type needs to be converted into the data of the non-OC type, and the general type reading method corresponds to the target data type, so that the conversion process is completed in the general type reading method; and if the terminal equipment judges that the read data type is the same as the target data type, acquiring the data obtained from the persistence container.
As shown in fig. 6, the embodiment of the invention further provides a flowchart of an example of a data writing method.
Step 601: attribute information is generated.
In the embodiment of the invention, the terminal equipment generates attribute information through a +load method, wherein the attribute information comprises identification information and data types of each data, such as target identification information 'audioswitch open' of target data 'YES' and target data type 'BOOL'.
Step 602: and determining target identification information and target data type of the target data according to the target data.
In the embodiment of the invention, when the terminal equipment receives a writing instruction, target identification information 'audioswitch open' and target data type 'BOOL' corresponding to 'YES' are determined according to expected target data 'YES'.
Step 603: and acquiring a writing method name and a reading method name of the target identification information according to the target identification information, and acquiring a general type writing method and a general type reading method of the target data type according to the target data type.
In the embodiment of the invention, a terminal device acquires a write method name of 'audioswitch open' and a read method name of 'audioswitch open' according to target identification information of 'audioswitch open', wherein the target identification information is the same as the read method name, and the target identification information is different from the write method name; and according to the target data type 'BOOL', the general type writing method 'generatBoolSetter' and the general type reading method 'generatBoolGetter' of the target data type 'BOOL' are obtained.
Step 604: the addresses of the write method names are respectively directed to the universal type write methods, and the addresses of the read method names are directed to the universal type read methods.
In the embodiment of the present invention, the terminal device directs the address of the write method name "setaudioswitch open" to the universal type write method "generateboolsetter" and directs the address of the read method name "audioswitch open" to the universal type read method "generateboolgetter" respectively by the method_setimplementation method of run.
Step 605: the general type writing method is directed to the general data writing method, and the general type reading method is directed to the general data reading method, respectively.
In the embodiment of the invention, the terminal equipment respectively points the general type writing method 'generatBoolSetter' to the general data writing method 'generateSetter', and points the general type reading method 'generatBoolGetter' to the general data reading method 'generatalGetter', so that the data types of the target data transmitted into the persistence container are consistent, different rules are prevented from being established aiming at the target data of different data types, and the efficiency and the accuracy are improved.
Step 606: whether the target data type of the target data is the preset data type is determined, if yes, step 607 is entered, if no, step 608 is entered.
In the embodiment of the present invention, the terminal device is to transfer the target data of the target data type into the persistence container, so that it is required to determine whether the target data type of the target data is the preset data type "OC", if yes, step 607 is entered, and if no, step 608 is entered.
Step 607: and calling a preset universal data writing method, and transmitting the writing method name and target data into a persistence container.
In the embodiment of the invention, the name conversion method converts the write method name 'setaudioswitch open' into the container write method name 'com.reader.audioswitch open', and the 'com.reader.audioswitch open' and the target data 'OC_YES' are transmitted into the persistence container through the general data write method 'generatSetter'.
Step 608: and converting the target data type into a preset data type, calling a preset general data writing method, and transmitting the writing method name and the target data of the preset data type into a persistence container.
In the embodiment of the invention, the terminal equipment converts the target data type 'BOOL' into the preset data type 'OC', converts the writing method name 'setAudio SwitchOpen' into the container writing method name 'com.reader.audioSwitchOpen' through a name conversion method, and transmits the container writing method name 'com.reader.audioSwitchOpen' and the target data 'OC_YES' of the preset data type into a persistence container through a general data writing method.
As shown in fig. 7, the embodiment of the invention further provides a flowchart of a data reading method.
Step 701: the read method name is transferred into the persistence container through the universal data read method.
In the embodiment of the invention, the terminal equipment converts the reading method name 'audioswitch open' into the container reading method name 'com.reader.audioswitch open' through a name conversion method, and transmits the container reading method name 'com.reader.audioswitch open' into the persistent container through a general data reading method 'generategetter'.
Step 702: and reading the data corresponding to the target identification information from the persistent container.
In the embodiment of the invention, the terminal equipment invokes a preset universal data reading method 'generalGetter', and reads data 'OC_YES' corresponding to the target identification information from the persistence container.
Step 703: whether the read data type is the same as the target data type is judged, if not, the step 704 is entered, and if yes, the step 705 is entered.
In the embodiment of the present invention, the terminal device determines whether the read OC type data "oc_yes" is the same as the target data type, if not, step 704 is entered, and if YES, step 705 is entered.
Step 704: and converting the read data type into a target data type.
In the embodiment of the present invention, if the terminal device determines that the read OC type data "oc_yes" is different from the target data type, the read OC type data "oc_yes" is converted into the target data type, that is, the non-OC type data "bool_yes".
Step 705: target data of the target data type is acquired.
In the embodiment of the present invention, if the terminal device determines that the read OC type data "oc_yes" is the same as the target data type, the terminal device obtains the target data "oc_yes", where the target data type of the target data is the same as the written target data type.
According to the data writing and reading method provided by the embodiment of the invention, the target data type of the target data is defined when the data is written, so that the terminal equipment automatically acquires the target data type when the data is read, and the manually set read data type is prevented from being different from the type of the written data; in addition, the embodiment of the invention stores the target data into the persistence container, so that the target data can be stored in the persistence container for a long time, and the target data is prevented from being lost.
The embodiment of the invention also provides a data writing device, as shown in fig. 8, which comprises:
A determining module 801, configured to determine, when a write instruction for target data is received, a target data type of the target data and target identification information of the target data;
a judging module 802, configured to judge whether a target data type of the target data is a preset data type;
the first input module 803 is configured to invoke a general data writing method if the target data type of the target data is a preset data type, and input the target data and a writing method name corresponding to the target identification information into the storage space;
the second incoming module 804 is configured to convert the target data type into a preset data type if the target data type of the target data is a non-preset data type, call a general data writing method, and incoming the writing method name and the target data of the preset data type into the storage space.
Optionally, the apparatus further comprises:
the generation module generates attribute information containing target identification information and target data types;
the system comprises an acquisition module, a target identification information reading module and a target data type obtaining module, wherein the acquisition module is used for acquiring a writing method name and a reading method name of the target identification information according to the target identification information and acquiring a general type writing method and a general type reading method of the target data type according to the target data type, the general type writing method is used for converting the target data from the target data type into a preset data type, and the general type reading method is used for converting the target data from the preset data type into the target data type;
The first pointing module is used for pointing the addresses of the write method names to the universal type write methods respectively and pointing the addresses of the read method names to the universal type read methods;
and the second instruction module is used for respectively directing the universal type writing method to the universal data writing method and directing the universal type reading method to the universal data reading method.
The embodiment of the invention also provides a data reading device, as shown in fig. 9, the device comprises:
a receiving module 901, configured to receive a read instruction, where the read instruction includes target identification information of data to be read;
a query module 902, configured to query a target data type corresponding to the target identification information according to pre-declared attribute information, where the attribute information includes identification information and a data type of each data;
the reading module 903 is configured to read data corresponding to the target identification information from the storage space by using a general data reading method, and determine whether the type of the read data is the same as the type of the target data, where the data is data of a preset data type written into the storage space;
the conversion module 904 is configured to convert the read data into data of the target data type if the read data type is different from the target data type, so as to obtain the target data.
Optionally, the storage space is a persistence container; the reading module 903 includes:
a determining unit for determining a reading method name corresponding to the target identification information;
the input unit is used for inputting the reading method name into the persistence container through a universal data reading method;
and the reading unit is used for reading the data corresponding to the target identification information from the persistent container.
Optionally, the incoming unit includes:
a conversion subunit for converting the read method name into a container read method name by a name conversion method;
and the input subunit is used for inputting the method name of the container reading method into the persistent container through the universal data reading method.
Optionally, the conversion module 904 includes:
and the conversion unit is used for converting the read data into the data of the target data type through a general type reading method corresponding to the target data type.
The embodiment of the invention also provides an electronic device, as shown in fig. 10, which comprises a processor 1001, a communication interface 1002, a memory 1003 and a communication bus 1004, wherein the processor 1001, the communication interface 1002 and the memory 1003 complete communication with each other through the communication bus 1004,
a memory 1003 for storing a computer program;
a processor 1001 for executing the program stored in the memory 1003, and performing the steps described above
The communication bus mentioned by the above terminal may be a peripheral component interconnect standard (Peripheral Component Interconnect, abbreviated as PCI) bus or an extended industry standard architecture (Extended Industry Standard Architecture, abbreviated as EISA) bus, etc. The communication bus may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The communication interface is used for communication between the terminal and other devices.
The memory may include random access memory (Random Access Memory, RAM) or non-volatile memory (non-volatile memory), such as at least one disk memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor.
The processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU for short), a network processor (Network Processor, NP for short), etc.; but also digital signal processors (Digital Signal Processing, DSP for short), application specific integrated circuits (Application Specific Integrated Circuit, ASIC for short), field-programmable gate arrays (Field-Programmable Gate Array, FPGA for short) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
In yet another embodiment of the present invention, a computer readable storage medium is provided, in which instructions are stored, which when executed on a computer, cause the computer to perform a data writing and reading method according to any of the foregoing embodiments.
In yet another embodiment of the present invention, a computer program product containing instructions that, when run on a computer, cause the computer to perform a data writing and reading method as described in any of the above embodiments is also provided.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present invention, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, by wired (e.g., coaxial cable, optical fiber, digital Subscriber Line (DSL)), or wireless (e.g., infrared, wireless, microwave, etc.). The computer readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), etc.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
In this specification, each embodiment is described in a related manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for system embodiments, since they are substantially similar to method embodiments, the description is relatively simple, as relevant to see a section of the description of method embodiments.
The foregoing description is only of the preferred embodiments of the present invention and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims (9)

1. A method of writing data, the method comprising:
when a write instruction for target data is received, determining a target data type of the target data and target identification information of the target data;
judging whether the target data type of the target data is a preset data type or not;
if the target data type of the target data is a preset data type, a general data writing method is called, and the target data and a writing method name corresponding to the target identification information are transmitted into a storage space, wherein the storage space is a persistence container;
if the target data type of the target data is a non-preset data type, converting the target data type into a preset data type, calling the universal data writing method, and transmitting the writing method name and the target data of the preset data type into the storage space;
before determining whether the target data type of the target data is the preset data type, the method further includes:
Generating attribute information containing the target identification information and the target data type;
acquiring a writing method name and a reading method name of the target identification information according to the target identification information, and acquiring a general type writing method and a general type reading method of the target data type according to the target data type, wherein the general type writing method is used for converting the target data from the target data type to the preset data type, and the general type reading method is used for converting the target data from the preset data type to the target data type;
respectively directing the address of the write method name to the universal type write method, and directing the address of the read method name to the universal type read method;
and respectively pointing the universal type writing method to the universal data writing method and pointing the universal type reading method to the universal data reading method.
2. A data reading method after data writing based on the data writing method of claim 1, characterized in that the method comprises:
receiving a reading instruction, wherein the reading instruction comprises target identification information of data to be read;
Inquiring a target data type corresponding to the target identification information according to pre-declared attribute information, wherein the attribute information comprises identification information and data types of each data;
reading data corresponding to the target identification information from a storage space by a general data reading method, and judging whether the read data type is the same as the target data type, wherein the data is data of a preset data type written into the storage space, and the storage space is a persistence container;
and if the read data type is different from the target data type, converting the read data into the data of the target data type to obtain the target data.
3. The data reading method of claim 2, wherein the storage space is a persistent container; the reading the data corresponding to the target identification information from the storage space by the universal data reading method comprises the following steps:
determining a reading method name corresponding to the target identification information;
transmitting the read method name into the persistence container through a universal data read method;
and reading the data corresponding to the target identification information from the persistence container.
4. A data reading method according to claim 3, wherein said passing said read method name into said persistence container by a generic data reading method comprises:
converting the reading method name into a container reading method name through a name conversion method;
and transmitting the name of the container reading method into a persistent container through the universal data reading method.
5. The data reading method according to claim 2, wherein the converting the read data into the data of the target data type includes:
and converting the read data into the data of the target data type through a general type reading method corresponding to the target data type.
6. A data writing apparatus, the apparatus comprising:
the determining module is used for determining the target data type of the target data and the target identification information of the target data when a writing instruction aiming at the target data is received;
the judging module is used for judging whether the target data type of the target data is a preset data type or not;
the first input module is used for calling a general data writing method if the target data type of the target data is a preset data type, and inputting the target data and a writing method name corresponding to the target identification information into a storage space, wherein the storage space is a persistence container;
The second incoming module is used for converting the target data type into a preset data type if the target data type of the target data is a non-preset data type, calling the universal data writing method and introducing the writing method name and the target data of the preset data type into the storage space;
wherein the device is further for:
generating attribute information containing the target identification information and the target data type;
acquiring a writing method name and a reading method name of the target identification information according to the target identification information, and acquiring a general type writing method and a general type reading method of the target data type according to the target data type, wherein the general type writing method is used for converting the target data from the target data type to the preset data type, and the general type reading method is used for converting the target data from the preset data type to the target data type;
respectively directing the address of the write method name to the universal type write method, and directing the address of the read method name to the universal type read method;
and respectively pointing the universal type writing method to the universal data writing method and pointing the universal type reading method to the universal data reading method.
7. A data reading apparatus after data writing based on the data writing apparatus of claim 6, characterized in that the apparatus comprises:
the receiving module is used for receiving a reading instruction, wherein the reading instruction comprises target identification information of data to be read;
the query module is used for querying a target data type corresponding to the target identification information according to pre-declared attribute information, wherein the attribute information comprises identification information and data types of each data;
the reading module is used for reading data corresponding to the target identification information from a storage space through a general data reading method, judging whether the type of the read data is the same as the type of the target data, wherein the data is the data of the preset data type written into the storage space, and the storage space is a persistence container;
and the conversion module is used for converting the read data into the data of the target data type if the read data type is different from the target data type, so as to obtain the target data.
8. The terminal is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus;
A memory for storing a computer program;
a processor for carrying out the method steps of any one of claims 1-5 when executing a program stored on a memory.
9. A computer readable storage medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the method according to any of claims 1-5.
CN201911286323.0A 2019-12-13 2019-12-13 Data writing and reading method and device Active CN111104097B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911286323.0A CN111104097B (en) 2019-12-13 2019-12-13 Data writing and reading method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911286323.0A CN111104097B (en) 2019-12-13 2019-12-13 Data writing and reading method and device

Publications (2)

Publication Number Publication Date
CN111104097A CN111104097A (en) 2020-05-05
CN111104097B true CN111104097B (en) 2023-06-30

Family

ID=70423218

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911286323.0A Active CN111104097B (en) 2019-12-13 2019-12-13 Data writing and reading method and device

Country Status (1)

Country Link
CN (1) CN111104097B (en)

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5361351A (en) * 1990-09-21 1994-11-01 Hewlett-Packard Company System and method for supporting run-time data type identification of objects within a computer program
CN104766027A (en) * 2015-03-25 2015-07-08 深圳市金立通信设备有限公司 Data access method
WO2015176531A1 (en) * 2014-05-21 2015-11-26 中兴通讯股份有限公司 Terminal data writing and reading methods and devices
CN105786819A (en) * 2014-12-18 2016-07-20 广州华多网络科技有限公司 Data operation method and device
CN107967121A (en) * 2017-10-25 2018-04-27 华为技术有限公司 Method for writing data and storage device
CN109684307A (en) * 2018-12-26 2019-04-26 百度在线网络技术(北京)有限公司 A kind of date storage method, device, equipment and storage medium
CN110096541A (en) * 2019-04-28 2019-08-06 新华三大数据技术有限公司 Method for interchanging data and device between a kind of database
CN110555073A (en) * 2019-09-10 2019-12-10 政采云有限公司 data processing method and device, electronic equipment and storage medium

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP4395178B2 (en) * 2007-05-29 2010-01-06 インターナショナル・ビジネス・マシーンズ・コーポレーション Content processing system, method and program
WO2016041191A1 (en) * 2014-09-19 2016-03-24 华为技术有限公司 Method and apparatus for reading and writing data, storage device and computer system

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5361351A (en) * 1990-09-21 1994-11-01 Hewlett-Packard Company System and method for supporting run-time data type identification of objects within a computer program
WO2015176531A1 (en) * 2014-05-21 2015-11-26 中兴通讯股份有限公司 Terminal data writing and reading methods and devices
CN105786819A (en) * 2014-12-18 2016-07-20 广州华多网络科技有限公司 Data operation method and device
CN104766027A (en) * 2015-03-25 2015-07-08 深圳市金立通信设备有限公司 Data access method
CN107967121A (en) * 2017-10-25 2018-04-27 华为技术有限公司 Method for writing data and storage device
CN109684307A (en) * 2018-12-26 2019-04-26 百度在线网络技术(北京)有限公司 A kind of date storage method, device, equipment and storage medium
CN110096541A (en) * 2019-04-28 2019-08-06 新华三大数据技术有限公司 Method for interchanging data and device between a kind of database
CN110555073A (en) * 2019-09-10 2019-12-10 政采云有限公司 data processing method and device, electronic equipment and storage medium

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
王广红 ; 黄连生 ; 高格 ; 傅鹏 ; 何诗英 ; 王泽京 ; .EAST极向场电源的数据存储及读取方法.强激光与粒子束.2019,(05),全文. *
陆政 ; 范长军 ; 江云飞 ; .基于OpenSSD的闪存转换算法优化.计算机系统应用.2018,(05),全文. *

Also Published As

Publication number Publication date
CN111104097A (en) 2020-05-05

Similar Documents

Publication Publication Date Title
CN111428462B (en) Communication protocol template construction method and terminal equipment
US11212658B2 (en) Method for providing near filed communication device information for user and system therefor
US11507718B1 (en) Chip verification system and verification method therefor
CN114266539A (en) File flow processing method, system, device and computer readable storage medium
CN111104097B (en) Data writing and reading method and device
CN110442636B (en) Data reading and writing method and device and data reading and writing equipment
CN112000589A (en) Data writing method, data reading device and electronic equipment
CN116996601A (en) Message format conversion method and device, electronic equipment and storage medium
US8291270B2 (en) Request processing device, request processing system, and access testing method
CN111124545A (en) Application program starting method and device, electronic equipment and storage medium
CN102880669A (en) Business processing method and business processing device based on file
CN114547164A (en) Method and related device for exporting test data
CN109254855B (en) Registration method and device of parameter transmission protocol and electronic equipment
CN111510483B (en) Configuration synchronization system, method and device between different network domains in chip test
CN114461223A (en) Code generation method and device and terminal equipment
CN113011848A (en) Method, device, equipment and storage medium for accessing approval service
US20150309788A1 (en) Function module modularizing method in data distribution service and modularizing apparatus thereof
CN111914128A (en) Method and device for determining associated user, electronic equipment and readable storage medium
CN111078308B (en) Automatic class loading method and device, electronic equipment and storage medium
CN112788091B (en) Document content providing system, document content collecting method, device and equipment
CN117112047B (en) USB equipment management and control method, equipment and storage medium
CN116775526B (en) Expansion device and electronic equipment
CN111290806B (en) Calling method and device of application program interface, computer equipment and storage medium
CN115278649B (en) Telephone number acquisition method, equipment, system and medium based on machine learning
CN113204946B (en) Data control method, device, equipment 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