Method and apparatus for converting data
By identifying data categories and converting them into binary streams using commonalities, it solves the complexity problem of multi-type data conversion in the operating system, achieves simplification and efficiency improvement of data encapsulation, and solves the problem of excessive method overloading.
Patent Information
- Application Number
- CN201910902622.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-09-24
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2039-09-24
AI Technical Summary
In the operating system, multiple representations of the same data type lead to excessive method overloading, which increases the workload and time cost when encapsulating components, and this workload cannot be reused.
By identifying data categories, using commonalities to convert data into binary streams, and converting and outputting according to the target type, a method and device for converting data are provided, including an identification unit, a conversion unit and a storage unit, to realize multiple types of data Conversion and output.
It simplifies the data encapsulation process, reduces the number of method overloads, improves processing efficiency, and enables reuse and efficient output of multiple types of data.
Smart Images

Figure CN111782713B
Abstract
Description
Technical Field
[0001] Embodiments of the present disclosure relate to the field of computer technology, and in particular to a method and device for converting data. Background Art
[0002] Operating systems (such as Android) often have the problem of having multiple types of data sources for the same data. For example, the image data types corresponding to ImageView include: application built-in image R.drawable.xx type, Drawable type, Bitmap type, File file type, network Url type. When we encapsulate components and want to modify the properties of internal controls, since the internal controls are not exposed to the outside, we generally overload methods for multiple image data types, and there will be an abnormally large number of methods that need to be overloaded.
[0003] For encapsulators, overloading these methods is a physical labor, time-consuming and labor-intensive, and a burden. These usability-oriented processes consume a lot of time for encapsulators. When a new attribute is added to the encapsulated component, 2n+1 more methods will be overloaded (calculation formula: ((N+X)*(N+X)-(N*N))X is the number of newly added attributes). The output of this workload is not reusable and can only be used in the current component. Summary of the invention
[0004] Embodiments of the present disclosure provide methods and devices for converting data.
[0005] In a first aspect, an embodiment of the present disclosure provides a method for converting data, comprising: in response to receiving data to be converted, identifying a category of the data; converting the data into a binary stream according to the commonality of the category; and converting the binary stream into data of a target type.
[0006] In some embodiments, converting the data into a binary stream according to the commonality of the categories includes: in response to receiving an output request including a target type, converting the binary stream into data of the target type and outputting the data.
[0007] In some embodiments, the method further includes: storing the data of the target type; and outputting the data of the target type in response to receiving an output request.
[0008] In some embodiments, the method further comprises: storing data of the target type before receiving an output request including the target type.
[0009] In some embodiments, the commonality includes a website address; and converting the data into a binary stream according to the commonality of the category includes: downloading source data according to the website address; converting the source data into a binary stream.
[0010] In some embodiments, the target type includes a URL category; and converting a binary stream into data of the target type includes: converting the binary stream into a downloadable file and uploading it to a designated server to obtain a download address; using the download address as data of the target type.
[0011] In a second aspect, an embodiment of the present disclosure provides a device for converting data, comprising: an identification unit, configured to identify the category of data in response to receiving data to be converted; a first conversion unit, configured to convert the data into a binary stream based on the commonality of the category; and a second conversion unit, configured to convert the binary stream into data of a target type.
[0012] In some embodiments, the first conversion unit is further configured to: in response to receiving an output request including a target type, convert the binary stream into data of the target type and output the data.
[0013] In some embodiments, the device further includes a storage unit configured to: store data of the target type; and output the data of the target type in response to receiving an output request.
[0014] In some embodiments, the apparatus further comprises a storage unit configured to: store data of the target type before receiving an output request comprising the target type.
[0015] In some embodiments, the commonality includes a website address; and the first conversion unit is further configured to: download source data according to the website address; and convert the source data into a binary stream.
[0016] In some embodiments, the target type includes a URL category; and the second conversion unit is further configured to: convert the binary stream into a downloadable file and then upload it to a designated server and obtain a download address; and use the download address as data of the target type.
[0017] In a third aspect, an embodiment of the present disclosure provides an electronic device for converting data, comprising: one or more processors; a storage device on which one or more programs are stored, and when the one or more programs are executed by the one or more processors, the one or more processors implement any method as described in the first aspect.
[0018] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable medium having a computer program stored thereon, wherein when the program is executed by a processor, any method in the first aspect is implemented.
[0019] The method and device for converting data provided by the embodiments of the present disclosure perform common processing according to resource types, encapsulate them using platform system methods, and realize resource conversion internally for external use. Thus, resource data of the same type can be encapsulated to realize multi-type conversion, so as to output various types required by the external. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Other features, objects and advantages of the present disclosure will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0021] Figure 1 is an exemplary system architecture diagram in which an embodiment of the present disclosure may be applied;
[0022] Figure 2 is a flow chart of one embodiment of a method for converting data according to the present disclosure;
[0023] Figure 3a-3c is a schematic diagram of an application scenario of the method for converting data according to the present disclosure;
[0024] Figure 4 is a structural schematic diagram of an embodiment of a device for converting data according to the present disclosure;
[0025] Figure 5 It is a structural diagram of a computer system of an electronic device suitable for implementing an embodiment of the present disclosure. DETAILED DESCRIPTION
[0026] The present disclosure is further described in detail below in conjunction with the accompanying drawings and embodiments. It is understood that the specific embodiments described herein are only used to explain the relevant invention, rather than to limit the invention. It is also necessary to explain that, for ease of description, only the parts related to the relevant invention are shown in the accompanying drawings.
[0027] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present disclosure may be combined with each other. The present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0028] Figure 1 An exemplary system architecture 100 is shown to which embodiments of the method for converting data or the apparatus for converting data disclosed herein can be applied.
[0029] like Figure 1 As shown, system architecture 100 may include terminal devices 101 and 102. Terminal devices 101 and 102 are connected via a network. The network may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0030] The user can use the terminal device 101 to interact with the terminal device 102 through the network to receive or send messages, etc. Various communication client applications can be installed on the terminal devices 101 and 102, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0031] The user can share the text, pictures, audio, video and other information displayed by application A in the terminal device 101 with application B in another terminal device. The data types of text, pictures, audio and video required by the two applications are different, and corresponding data conversion is required. The text, pictures, audio, video and other information displayed by the terminal device 101 are converted into the data type required by application B.
[0032] It should be noted that the method for converting data provided in the embodiments of the present disclosure is generally executed by a terminal device, and accordingly, the apparatus for converting data is generally provided in the terminal device.
[0033] It should be understood that Figure 1 The number of terminal devices in the figure is only for illustration. Any number of terminal devices may be provided according to implementation requirements.
[0034] Continue to refer Figure 2 , shows a process 200 of an embodiment of a method for converting data according to the present disclosure. The method for converting data comprises the following steps:
[0035] Step 201 : in response to receiving data to be converted, identifying the category of the data.
[0036] In this embodiment, the execution subject of the method for converting data (eg Figure 1 The terminal device shown in the figure can receive the data to be converted from the terminal that the user uses to share data through a wired connection or a wireless connection. Then identify the category of the data. The category may include text, picture, audio, video, etc. The same category may include multiple types. For example, the type of picture data may include: application built-in picture R.drawable.xx type, Drawable type, Bitmap type, File file type, network Url type.
[0037] Step 202, converting the data into a binary stream according to the commonality of the categories.
[0038] In this embodiment, each type of data has commonality, for example, the commonality of pictures may include resource ID, network address, local file path, etc. The resources are processed in a common way, for example, whether the input resource ID, network address, local file path or other types of pictures are converted into binary streams, and various types of output are performed when needed. The converted binary streams can be stored in the memory.
[0039] In some optional implementations of this embodiment, if the source of the image to be shared in the application A of the terminal device 101 is a URL, and the application B of the destination terminal device 102 requires an image format such as bitmap, the terminal device 101 can download the source data according to the URL, convert the source data into a binary stream, and then share it with the application B of the terminal device 102.
[0040] In some optional implementations of this embodiment, the data may be searched in the memory before conversion to determine whether the data has been converted. If the data has been converted, it does not need to be converted this time and can be used directly, thereby improving the processing speed.
[0041] Step 203: Convert the binary stream into data of the target type.
[0042] In this embodiment, the binary stream can be converted into target type data according to the requirements of the application program of the target terminal. Figure 3a As shown, users can input any data type of a resource, and the resources will be processed in a common way internally. For example, no matter the input resource ID, network address, local file path or other types of images are converted into image binary streams, various types of outputs can be performed when needed.
[0043] When passing parameters in a function, directly use the resource converter as a parameter. This way, only the necessary data parameters need to be passed in, rather than constructing and overloading the parameters based on the data source type.
[0044] There are two conversion methods. One is to convert the binary stream into various types of data without knowing the type specified by the target application (R.drawable.xx type of built-in image, Drawable type, Bitmap type, File type, network Url type). There is always a type that matches the target application. The other method is to convert the binary stream into data of the target type when the target type specified by the target application is already known.
[0045] Figure 3b Flowchart for data conversion without knowing the type specified by the target application. Figure 3bHungry processing: directly convert different types of data into storage when input. Although this method consumes memory, it is fast because the data is converted in advance and used as a backup.
[0046] Figure 3b Flowchart for data conversion when the type specified by the target application is known. Figure 3c This is lazy processing: the conversion is performed before output. The data to be converted is stored in memory instead of a binary stream. This method saves memory and performs the conversion operation only after receiving the instruction to convert to the specified type.
[0047] In some optional implementations of this embodiment, the target type includes a URL category; and converting the binary stream into data of the target type includes: converting the binary stream into a downloadable file and uploading it to a designated server to obtain a download address; using the download address as data of the target type. In the case where the target application does not support certain file formats or in order to save traffic, the binary stream converted from the original file such as text, picture, audio, video, etc. can be restored to the original file and uploaded to a designated server to obtain a download address. Then the download address is notified to the target application, and the user can obtain the original file through the download address.
[0048] Further references Figure 4 As an implementation of the methods shown in the above figures, the present disclosure provides an embodiment of a device for converting data. Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0049] like Figure 4 As shown, the apparatus 400 for converting data in this embodiment includes: an identification unit 401, a first conversion unit 402, and a second conversion unit 403. The identification unit 401 is configured to identify the category of the data in response to receiving the data to be converted; the first conversion unit 402 is configured to convert the data into a binary stream according to the commonality of the category; and the second conversion unit 403 is configured to convert the binary stream into data of a target type.
[0050] In this embodiment, the specific processing of the identification unit 401, the first conversion unit 402 and the second conversion unit 403 of the apparatus 400 for converting data can be referred to in Figure 2 Corresponding to step 201, step 202, and step 203 in the embodiment.
[0051] In some optional implementations of this embodiment, the first conversion unit 402 is further configured to: in response to receiving an output request including a target type, convert the binary stream into data of the target type and output the data.
[0052] In some optional implementations of this embodiment, the device 400 further includes a storage unit 404 configured to: store the target type of data; and output the target type of data in response to receiving an output request.
[0053] In some optional implementations of this embodiment, the apparatus 400 further includes a storage unit 404 configured to store data of the target type before receiving an output request including the target type.
[0054] In some optional implementations of this embodiment, the commonality includes a website address; and the first conversion unit 402 is further configured to: download source data according to the website address; and convert the source data into a binary stream.
[0055] In some optional implementations of this embodiment, the target type includes a URL category; and the second conversion unit is further configured to: convert the binary stream into a downloadable file and upload it to a designated server to obtain a download address; and use the download address as data of the target type.
[0056] Reference below Figure 5 , which shows an electronic device (eg, Figure 1 The terminal device in the embodiment of the present disclosure may include but is not limited to mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The terminal device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0057] like Figure 5 As shown, the electronic device 500 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the electronic device 500 are also stored. The processing device 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0058] Typically, the following devices may be connected to the I / O interface 505: an input device 506 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 508 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 509. The communication device 509 may allow the electronic device 500 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 5 The electronic device 500 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead. Figure 5 Each block shown in the figure may represent one device, or may represent multiple devices as required.
[0059] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through a communication device 509, or installed from a storage device 508, or installed from a ROM 502. When the computer program is executed by the processing device 501, the above functions defined in the method of the embodiment of the present disclosure are executed. It should be noted that the computer-readable medium described in the embodiment of the present disclosure can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, - but not limited to - an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection with one or more conductors, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In an embodiment of the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, an apparatus, or a device. In an embodiment of the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in combination with an instruction execution system, an apparatus, or a device. The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to: wire, optical cable, RF (radio frequency), etc., or any suitable combination of the foregoing.
[0060] The computer-readable medium may be included in the electronic device, or may exist independently without being installed in the electronic device. The computer-readable medium carries one or more programs, and when the one or more programs are executed by the electronic device, the electronic device: in response to receiving data to be converted, identifies the category of the data; converts the data into a binary stream according to the commonality of the category; and converts the binary stream into data of the target type.
[0061] Computer program code for performing the operations of embodiments of the present disclosure may be written in one or more programming languages or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on a user's computer, partially on a user's computer, as a separate software package, partially on a user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0062] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0063] The units involved in the embodiments described in the present disclosure may be implemented by software or by hardware. The units described may also be provided in a processor, for example, may be described as: a processor includes an identification unit, a first conversion unit, and a second conversion unit. The names of these units do not, in some cases, constitute limitations on the units themselves, for example, the identification unit may also be described as "a unit that identifies the category of the data in response to receiving the data to be converted".
[0064] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present disclosure is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the inventive concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other.
Claims
1. A method for transforming data, include: In response to the data sharing terminal receiving the data to be converted, identifying the category of the data; Before the conversion, the data is searched in the memory to determine whether the data has been converted. If the data has not been converted, the data is converted into a binary stream according to the commonality of the categories, wherein the commonality of the image data includes a resource ID, a network address, and a local file path; Convert the binary stream into data of a target type according to the requirements of the application program of the destination terminal, or convert it into data of a different type for storage if the target type is not specified; The step of converting the data into a binary stream according to the commonality of the categories includes: Download source data according to the network address; Convert the source data into a binary stream.
2. The method according to claim 1, in, The step of converting the data into a binary stream according to the commonality of the categories comprises: In response to receiving an output request including a target type, the binary stream is converted into data of the target type and output.
3. The method according to claim 1, in, The method further comprises: Storing data of the target type; In response to receiving the output request, data of the target type is output.
4. The method according to claim 2, in, The method further comprises: Before receiving an output request including a target type, data of the target type is stored.
5. The method according to claim 1, in, The target type includes URL category; as well as The step of converting the binary stream into data of a target type comprises: Convert the binary stream into a downloadable file and upload it to a designated server to obtain a download address; The download address is used as data of the target type.
6. A device for converting data, include: an identification unit, configured to identify a category of the data in response to the terminal for data sharing receiving the data to be converted; A first conversion unit is configured to search the data in the memory before conversion to determine whether the data has been converted, and if not, convert the data into a binary stream according to the commonality of the category, wherein the commonality of the image data includes a resource ID, a network address, and a local file path; A second conversion unit is configured to convert the binary stream into data of a target type according to the requirements of an application program of a destination terminal, and if the target type is not specified, convert the binary stream into data of a different type for storage; The step of converting the data into a binary stream according to the commonality of the categories includes: Download source data according to the network address; Convert the source data into a binary stream.
7. The device according to claim 6, in, The first conversion unit is further configured to: In response to receiving an output request including a target type, the binary stream is converted into data of the target type and output.
8. The device according to claim 6, in, The device further comprises a storage unit configured to: Storing data of the target type; In response to receiving the output request, data of the target type is output.
9. The device according to claim 7, in, The device further comprises a storage unit configured to: Before receiving an output request including a target type, data of the target type is stored.
10. The device according to claim 6, in, The target type includes a URL category; and The second conversion unit is further configured to: Convert the binary stream into a downloadable file and upload it to a designated server to obtain a download address; The download address is used as data of the target type.
11. An electronic device for converting data, include: one or more processors; a storage device having one or more programs stored thereon, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 5.
12. A computer readable medium having a computer program stored thereon, in, When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
