Data processing method, device, equipment, storage medium and product
By introducing singleton objects to manage observers in the observer mode, monitoring attribute changes and encapsulating data delivery, the problem of difficulty in maintaining the life cycle of proxy objects during data delivery is solved, and the accuracy and maintainability of data delivery are improved.
Patent Information
- Application Number
- CN202111186042.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-11
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2041-10-11
AI Technical Summary
During the business iteration process, when the data delivery process is long in the observer mode, the life cycle maintenance of the proxy object is difficult, which can easily lead to data delivery failure or errors, affecting the maintainability and accuracy of data delivery.
Singleton objects are used to manage observers, and by creating the data structure of the singleton object, including the observer's information, monitoring attribute changes, and encapsulate data based on the protocol specification information, directly pass it to the target observer, reducing the number of proxy objects, and improving the maintainability and accuracy of data transmission.
Manage observers through singleton objects, simplify data delivery logic, reduce the number of object maintenance, avoid data delivery failures and errors, and improve the accuracy and maintainability of data delivery.
Smart Images

Figure CN115964186B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and more specifically, to a data processing method, device, electronic device, computer-readable storage medium, and computer program product. Background Art
[0002] At present, the observer pattern is usually used to handle the communication between multiple modules during the iteration process of the business. Among them, the proxy object serves as the intermediary for data transmission between observers. When the data transmission process of the business is long, the difficulty of maintaining the life cycle of the proxy object will be greatly increased, and data transmission failure or errors may also occur during the data transmission process of the business.
[0003] It can be seen that how to improve the maintainability and accuracy of data transmission is an urgent problem to be solved. Summary of the Invention
[0004] To solve the above technical problems, the embodiments of the present application provide a data processing method, device, electronic device, computer-readable storage medium and computer program product, which can improve the maintainability and accuracy of data transmission at least to a certain extent.
[0005] According to one aspect of an embodiment of the present application, a data processing method is provided, the method comprising: creating a singleton object, wherein the data structure of the singleton object contains information of an observer; in response to a first observer contained in the data structure of the singleton object monitoring a change in an attribute of the observed object, obtaining attribute data after the change, and generating custom header data; wherein the custom header data contains an identifier of a second observer as a data recipient; encapsulating the attribute data, the custom header data, and protocol specification information for data transmission between observers to generate first feature data; determining the address of the second observer from the data structure of the singleton object based on the identifier of the second observer, and sending the first feature data to the second observer according to the address of the second observer, so that the second observer obtains the attribute data in the first feature data according to the protocol specification information in the received first feature data.
[0006] According to one aspect of an embodiment of the present application, a data processing device is provided, comprising: a creation module configured to create a singleton object, wherein the data structure of the singleton object contains information of an observer; a monitoring and acquisition module configured to acquire attribute data after the change in response to a first observer contained in the data structure of the singleton object monitoring a change in an attribute of the observed object, and generate custom header data; wherein the custom header data contains an identifier of a second observer serving as a data recipient; an encapsulation module configured to encapsulate the attribute data, the custom header data, and protocol specification information for data transmission between observers to generate first feature data; a sending module configured to determine the address of the second observer from the data structure of the singleton object based on the identifier of the second observer, and to send the first feature data to the second observer according to the address of the second observer, so that the second observer obtains the attribute data according to the protocol specification information in the received first feature data.
[0007] In some embodiments of the present application, based on the aforementioned scheme, the encapsulation module includes: an encryption unit, configured to encrypt the acquired attribute data to obtain encrypted attribute data; an encapsulation unit, configured to encapsulate the encrypted attribute data, the custom header data, and the protocol specification information for data transmission between observers to generate first feature data.
[0008] In some embodiments of the present application, based on the aforementioned scheme, the encryption unit is specifically configured to convert the acquired attribute data into binary data, perform bit operations on the binary data, obtain the bit-operated data, and use the bit-operated data as the encrypted attribute data.
[0009] In some embodiments of the present application, based on the aforementioned scheme, the device also includes: a receiving module, configured for the second observer to receive the first feature data, and parse the first feature data to obtain the protocol specification information; a loading module, configured for the second observer to load the attribute data from the first feature data according to the parsed protocol specification information.
[0010] In some embodiments of the present application, based on the aforementioned scheme, the device also includes: a copy module, configured to copy the loaded attribute data if the second observer needs to modify the attribute data; a modification and execution module, configured to modify the copied attribute data and execute operations corresponding to the modified attribute data.
[0011] In some embodiments of the present application, based on the aforementioned scheme, the device also includes: a modification module, configured for the second observer to modify the identifier of the second observer contained in the parsed custom header data to the identifier of the third observer to generate the modified custom header data, and to add fields to the parsed protocol specification information to generate the modified protocol specification information; a generation module, configured to encapsulate the loaded attribute data, the modified custom header data, and the modified protocol specification information to generate second feature data; the sending module is also configured to determine the address of the third observer from the data structure of the singleton object based on the identifier of the third observer, and to send the second feature data to the third observer according to the address of the third observer, so that the third observer obtains the attribute data in the second feature data according to the protocol specification information in the received second feature data.
[0012] In some embodiments of the present application, based on the aforementioned scheme, the loading module includes: a parsing unit, configured for the second observer to parse the first feature data according to the parsed protocol specification information to obtain encrypted attribute data; a decryption unit, configured to decrypt the encrypted attribute data to obtain decrypted attribute data, and use the decrypted attribute data as the loaded attribute data.
[0013] In some embodiments of the present application, based on the aforementioned scheme, the decryption unit is specifically configured to convert the encrypted attribute data into binary data, and perform a bit inversion operation on the binary data to obtain the data after the bit inversion operation, and use the data after the bit inversion operation as the decrypted attribute data; wherein, the bit inversion operation is the opposite operation of the bit operation.
[0014] In some embodiments of the present application, based on the aforementioned scheme, the device further includes: an acquisition module, configured to acquire the identifier and address of the observer who visits for the first time if the observer's first visit is detected; a writing module, configured to write the identifier and address of the observer who visits for the first time into the data structure of the singleton object; wherein the data structure of the singleton object contains the information of the observer in a key-value pair relationship, the key element in the key-value pair relationship is used to represent the identifier of the observer, and the value element in the key-value pair relationship is used to represent the address of the observer.
[0015] In some embodiments of the present application, based on the aforementioned scheme, the device also includes: the receiving module, which is further configured to receive a deletion instruction; wherein the deletion instruction carries the identifier of the observer to be deleted; and the deletion module, which is configured to delete the information of the observer that matches the identifier of the observer to be deleted from the information of multiple observers contained in the data structure of the singleton object according to the identifier of the observer to be deleted.
[0016] In some embodiments of the present application, based on the aforementioned scheme, the creation module is specifically configured to determine the preset event for creating a singleton object from a preset type and trigger event mapping relationship table according to the business type; wherein the preset type and trigger event mapping relationship table presets multiple business types and trigger events corresponding to various business types; if it is monitored that the preset event is triggered, the singleton object is created.
[0017] In some embodiments of the present application, based on the aforementioned scheme, the monitoring and acquisition module includes: an adding unit, configured to add the protocol specification information to the custom header data to generate custom header data containing the protocol specification information; a generating unit, configured to encapsulate the attribute data and the custom header data containing the protocol specification information to generate the first feature data.
[0018] According to one aspect of an embodiment of the present application, an electronic device is provided, comprising one or more processors; and a storage device for storing one or more programs, which, when executed by the electronic device, enables the electronic device to implement the data processing method described above.
[0019] According to one aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the data processing method described above is implemented.
[0020] According to one aspect of an embodiment of the present application, a computer program product is provided. The computer program product includes computer instructions. When the computer instructions are executed by a processor, the data processing method described above is implemented.
[0021] In the technical solution provided by the embodiments of the present application, on the one hand, by creating a singleton object, the data structure of the singleton object contains the information of the observer. Due to the single characteristic of the singleton object, only one singleton object is created for a business, that is, there is only one singleton object corresponding to a business. By using the created singleton object to manage observers, the number of objects that need to be maintained during data transmission can be greatly reduced. That is, at this time, the objects that need to be maintained during data transmission are only a singleton object and the observers involved. Compared with the multiple proxy objects and the observers involved that need to be maintained during data transmission in related technologies, the multiple proxy objects that need to be maintained become a singleton object, thereby improving the maintainability of data transmission; at the same time, it also avoids the phenomenon of data transmission failure caused by the premature release of one or some proxy objects with more complex relationships due to external logical errors due to the excessive number of proxy objects, and also avoids the phenomenon of data transmission errors caused by the erroneous calling of certain methods by one or some proxy objects with more complex relationships due to external logical errors, thereby greatly improving the accuracy of data transmission. On the other hand, when the first observer detects that the attributes of the observed object have changed, it encapsulates the changed attribute data, custom header data, and protocol specification information used for data transmission between observers to obtain first feature data, and then sends the first feature data to the second observer corresponding to the identifier of the second observer contained in the custom header data. In this way, the second observer as the data recipient can obtain the attribute data contained in the first feature data based on the protocol specification information contained in the first feature data, so that the attribute data can be accurately transmitted, further improving the accuracy of data transmission.
[0022] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The accompanying drawings are incorporated into and constitute a part of the specification, illustrating embodiments consistent with the present application and, together with the specification, serving to explain the principles of the present application. It is obvious that the drawings described below are merely some embodiments of the present application, and a person of ordinary skill in the art can derive other drawings based on these drawings without inventive effort. In the drawings:
[0024] Figure 1 It is a schematic diagram of passing data through proxy objects;
[0025] Figure 2 is a schematic diagram of an exemplary system architecture to which the technical solutions of the embodiments of the present application can be applied;
[0026] Figure 3is a flow chart of a data processing method shown in an exemplary embodiment of the present application;
[0027] Figure 4 is a flow chart of a data processing method shown in an exemplary embodiment of the present application;
[0028] Figure 5 is a flow chart of a data processing method shown in an exemplary embodiment of the present application;
[0029] Figure 6 is a flow chart of a data processing method shown in an exemplary embodiment of the present application;
[0030] Figure 7 is a flow chart of a data processing method shown in an exemplary embodiment of the present application;
[0031] Figure 8 is a flow chart of a data processing method shown in an exemplary embodiment of the present application;
[0032] Figure 9 is a schematic diagram of the structure of a singleton object shown in an exemplary embodiment of the present application;
[0033] Figure 10 is a flow chart of a data processing method shown in an exemplary embodiment of the present application;
[0034] Figure 11 is a block diagram of a data processing device shown in an exemplary embodiment of the present application;
[0035] Figure 12 It is a structural diagram of a computer system suitable for implementing the electronic device of the embodiment of the present application. DETAILED DESCRIPTION
[0036] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. When the following description refers to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all embodiments applicable to the present application. Rather, they are merely examples of apparatus and methods applicable to certain aspects of the present application, as detailed in the appended claims.
[0037] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically separate entities. That is, these functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0038] The flowcharts shown in the accompanying drawings are for illustrative purposes only and do not necessarily include all contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may be decomposed, while others may be combined or partially combined. Therefore, the actual execution order may vary depending on the actual situation.
[0039] It should be noted that the term "plurality" used in this application refers to two or more. "And / or" describes the relationship between associated objects, indicating that three possible relationships exist. For example, "A and / or B" can represent: A alone, A and B together, or B alone. The character " / " generally indicates that the associated objects are in an "or" relationship.
[0040] The Observer Pattern (KVO) is a commonly used pattern in mobile application design. It refers to a one-to-many dependency relationship between multiple objects. When the state of an object changes, all objects that depend on it are notified and automatically updated. The KVO mechanism involves the concepts of observed objects (i.e., observed objects) and observer objects (i.e., observers). The observed object refers to the initiator of the event, and the observer is the responder who needs to receive the event and respond (the observer's response is called executing a KVO operation). For example, in a game application scenario, when the protagonist moves into the effective range of a monster, the monster will attack the protagonist. The protagonist is the observed object, and the monster is the observer. The protagonist's movement indicates that the state / attribute of the observed object has changed (that is, the protagonist has triggered the movement event). At this time, the monster can receive the event of the protagonist's movement and respond by attacking the protagonist. The relationship between the observed object and the observer is that the observed object can register one or more observers. For example, in the aforementioned example, the observed object "protagonist" can register the observer "monster", and can also register the observer "trap" (when the protagonist moves into the effective range of the trap, the trap will trap the protagonist), the observer "treasure" (when the protagonist moves into the effective range of the treasure, the treasure will add blood to the protagonist), etc.; each observer can observe multiple attributes of the observed object. For example, the observers "monster", "trap" and "treasure" all observe the attribute of the observed object "protagonist" movement, and can also observe other attributes of the observed object "protagonist".
[0041] In related technologies, the observer pattern KVO is often used to handle communication between multiple modules during the iteration process of the business, and the proxy object is used as the intermediary for data transmission between observers. For example, in the above example, after the observer "Monster" receives the status / attribute data of the protagonist's movement, it needs to pass the data to another observer such as "Beast". In this case, the data transmission is carried out by the proxy object. To better understand the process of data transmission between observers by proxy objects in related technologies, please refer to Figure 1 In a certain business logic, there are proxy objects A and B, multiple observers 1, 2, 3, M, N, and observation objects. The relationship between the proxy object and the observer is that the proxy object holds the observer, and the observer can perform KVO operations on the proxy object and observe the proxy object. The relationship between the proxy object and the observation object is that the observation object holds the proxy object, and the proxy object can observe the observation object. Among them, if observers 1, 2, and 3 want to send data to observer M, they need to pass through proxy object A. Correspondingly, if observers 1, 2, and 3 want to send data to observer N, they also need to pass through proxy object A. It can be understood that Figure 1 The example shown here only shows a proxy object acting as an intermediary for data transfer between observers. In reality, many business logics are not this simple. Business data transfer processes are often lengthy, requiring multiple proxy objects to transfer data. Therefore, the longer the data transfer process, the more proxy objects are required, significantly increasing the difficulty of maintaining the lifecycle of proxy objects during data transfer. Furthermore, due to the large number of proxy objects involved in data transfer, one or more proxy objects with complex relationships may be prematurely released due to external logic errors, causing data transfer failure. For example, when KVO relationships are complex, proxy object A may be prematurely released due to external logic errors, leading to data transfer failure. At the same time, due to the large number of proxy objects in the data transmission process, one or some proxy objects with more complex relationships may incorrectly call certain methods due to external logic errors, resulting in data transmission errors. For example, proxy object A incorrectly calls certain methods, resulting in data that should have been passed to observer M being incorrectly passed to observer Q; and data transmission errors may also cause the application to crash. For example, in the application scenario of playing a video, after the playback observation object generates a playback record, the playback control observer passes the data to the playback record observer. At this time, if the playback control observer receives a playback request from other observers, it will overwrite the playback record generated by the playback observation object. This will cause the playback record passed to the playback record observer to be wrong. The application may crash due to a series of logical errors caused by the playback record transmission error.
[0042] Based on this, the embodiments of the present application propose a data processing method, device, electronic device, computer-readable storage medium and computer program product, which improve the maintainability and accuracy of data transmission, and the implementation logic of data transmission is simple.
[0043] See also Figure 2 , Figure 2 2 is a schematic diagram of an exemplary system architecture of the present application; the system architecture includes a terminal device 210 and a server 220, and the terminal device 210 and the server 220 communicate with each other through a wired or wireless network.
[0044] In one embodiment of the present application, a playback application is installed in the terminal device 210, in which data transmission is involved between various modules in the playback application, such as the playback module (also called the playback observer when the observer mode is used), the advertising module (also called the advertising observer when the observer mode is used), and the downloader module (also called the downloader observer when the observer mode is used); the terminal device 210 can create a singleton object, and when the first observer contained in the data structure of the singleton object detects that the attribute of the observed object has changed, it obtains the changed attribute data and generates custom header data, and then encapsulates the attribute data, the custom header data, and the protocol specification information for data transmission between observers to generate first feature data, and determines the address of the second observer from the data structure of the singleton object based on the identifier of the second observer, and sends the first feature data to the second observer according to the address of the second observer, so that the second observer can obtain the attribute data in the first feature data according to the protocol specification information in the received first feature data, thereby realizing data transmission between observers; wherein the first observer can be a playback observer, and the second observer can be an advertising observer and / or a downloader observer. The terminal device 210 and the server 220 communicate with each other via a wired or wireless network to achieve normal use of playback applications. For example, the terminal device 210 can request playback resources from the server 220.
[0045] In one embodiment of the present application, a shopping application is installed in the terminal device 210, wherein data transmission is involved between various modules in the shopping application, such as the order module, payment module, update module, etc.; it can be understood that the terminal device 210 sends the data obtained by each module to the server 220, wherein the server 220 has processing modules corresponding to each module in the terminal device 210, such as the order processing module (also called the order processing observer when the observer pattern is used), the payment processing module (also called the payment processing observer when the observer pattern is used), and the update processing module (also called the update processing observer when the observer pattern is used); then the server 220 can create a singleton object, and the first observer included in the data structure of the singleton object When the observer detects that the attributes of the observed object have changed, it obtains the changed attribute data and generates custom header data, and then encapsulates the attribute data, custom header data, and protocol specification information for data transmission between observers to generate first feature data, and determines the address of the second observer from the data structure of the singleton object based on the identifier of the second observer, and sends the first feature data to the second observer according to the address of the second observer, so that the second observer can obtain the attribute data in the first feature data according to the protocol specification information in the received first feature data, thereby realizing data transmission between observers; the first observer can be an order processing observer, and the second observer can be a payment processing observer and / or an update processing observer.
[0046] Among them, the terminal device 210 can be an electronic device such as a smart phone, tablet, laptop, computer, car terminal, etc.; the server 220 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), big data and artificial intelligence platforms and other basic cloud computing services. This is not restricted here.
[0047] based on Figure 2 The application scenario shown, after adopting the technical solution of the embodiment of the present application, improves the maintainability and accuracy of data transmission, and the implementation logic of data transmission is simple.
[0048] The following describes in detail the various implementation details of the technical solutions of the embodiments of the present application:
[0049] See also Figure 3 , Figure 3 It is a flow chart of a data processing method shown in one embodiment of the present application.
[0050] like Figure 3 As shown, the data processing method includes at least steps S301 to S304, which are described in detail as follows:
[0051] Step S301: Create a singleton object, the data structure of which contains information about the observer.
[0052] In the embodiment of the present application, a singleton object refers to an object created by a singleton pattern. Among them, the singleton pattern is used to create a unique object of a class in a process, that is, a single object is created in the singleton pattern, and the class to which the object belongs provides a method to access its unique object (i.e., the object). The class to which the object belongs can be to instantiate the object at the beginning (regardless of whether other classes need to access / call the object, the object is instantiated first, and when other classes need to access / call the object later, it can be directly returned), or it can be to instantiate the object when other classes want to access / call it for the first time (the object is instantiated only when other classes need to access / call the object, and the instantiated object is returned). In this way, when other classes want to access / call the object, there is no need to instantiate the object again within other classes; it is understandable that there can be multiple different classes in a process, for example, there are classes 1, 2, and 3 in a process, and any of classes 1, 2, and 3 can adopt the singleton pattern.
[0053] In the embodiment of the present application, the data structure of a singleton object refers to a collection of data elements that have one or more specific relationships with each other, that is, a collection of data elements with a "structure". Among them, "structure" refers to the relationship between data elements, which is divided into logical structure and storage structure; the logical structure is a data structure used to characterize the logical relationship between data elements, usually referring to the relationship between the front and back of the data elements, and has nothing to do with the storage location in the computer. The logical structure can include a set (that is, the elements in the data structure have no other relationship except the relationship of "belonging to the same set"), a linear structure (that is, the elements in the data structure have a one-to-one relationship), a tree structure (the elements in the data structure have a one-to-many relationship), and a graph structure (the elements in the data structure have a many-to-many relationship), etc.; the storage structure is used to characterize the storage form of the logical structure of data in the computer storage space. Usually, the logical structure of a data can be represented as a variety of storage structures as needed. The storage structure can include sequential storage, chain storage, index storage, and hash storage, etc.
[0054] Among them, data structures in programming include but are not limited to arrays, stacks, queues, linked lists, trees, graphs, heaps, and hash tables.
[0055] In an optional embodiment, the data structure of the singleton object may refer to the global dictionary corresponding to the singleton object. A global dictionary is a data structure that stores data in the form of key-value pairs. The value element corresponding to the key element can be found by using the key element. The key element in the global dictionary is the index of the value element in the global dictionary. For example, in the name-phone number pair, the corresponding phone number can be found by using the name. The name is the key element, and the phone number is the value element. For the JavaScript programming language, the foundation of the global dictionary class is an array.
[0056] It is understandable that a singleton object can also create its own objects, such as creating observers according to business needs. In this case, the observers created can be registered in the global dictionary, that is, the singleton object manages the observers in the global dictionary through the global dictionary.
[0057] The data structure of the singleton object in the embodiment of the present application contains information about one or more (two or more) observers; wherein, each observer has its corresponding observed object, different observers correspond to different observers, and each observer can observe one or more attributes of its corresponding observed object. It should be noted that the singleton object created in the embodiment of the present application itself can also serve as an observer, so the first observer contained in the data structure of the singleton object can also be itself.
[0058] In the embodiment of the present application, the information of the observer includes but is not limited to the identifier of the observer and the address of the observer. In this way, the singleton object can manage the data transfer between observers based on the information of the observer. For example, the identifier of the observer can be added to the custom header data to indicate the data recipient, and the address of the observer can be determined based on the identifier of the observer as the data recipient, so as to send feature data to the observer based on the address of the observer, thereby realizing data transfer between observers, without the need to use multiple proxy objects to realize data transfer between multiple observers, greatly reducing the number of maintainable objects and greatly improving the maintainability of data transfer.
[0059] In one embodiment of the present application, the process of creating a singleton object in step S301 may include the following steps:
[0060] Determine the preset event for creating the singleton object from a preset type and trigger event mapping relationship table according to the business type; wherein the preset type and trigger event mapping relationship table presets multiple business types and trigger events corresponding to the various business types;
[0061] If a preset event is detected to be triggered, a singleton object is created.
[0062] That is, in an optional embodiment, the preset event for creating a singleton object is determined from a preset type-to-trigger event mapping table based on the business type, and the preset event is then monitored. If the preset event is detected to be triggered, the singleton object needs to be created at this time. If the preset event is not detected to be triggered, monitoring continues until the preset event is detected to be triggered. In this way, the timing of creating a singleton object varies depending on the business type, which to a certain extent improves the flexibility of singleton object creation and better meets the needs of application scenarios.
[0063] For example, if the current business type is playback, it is necessary to monitor the playback application startup event. If it is detected that the playback application startup is triggered, a singleton object needs to be created at this time; among which, the playback application startup event corresponding to the playback business type can be found from the preset type and trigger event mapping relationship table.
[0064] It is understood that the preset type and trigger event mapping relationship table contains a variety of business types and the trigger events corresponding to each business type. The preset type and trigger event mapping relationship table is flexibly configured by relevant development personnel based on application scenario requirements. Please refer to Table 1 below for an example of a preset type and trigger event mapping relationship table.
[0065] Business Type Trigger Event Business Type A Event 1 Business Type B Event 2 Business Type C Event 3 …… ……
[0066] Table 1
[0067] In one embodiment of the present application, after the process of creating the singleton object in step S301, the following steps may also be included:
[0068] If the observer's first visit is detected, the identifier and address of the observer who visited for the first time are obtained;
[0069] The identifier and address of the observer who visits for the first time are written into the data structure of the singleton object, where the data structure of the singleton object contains the information of the observer in a key-value pair relationship, the key element in the key-value pair relationship is used to represent the identifier of the observer, and the value element in the key-value pair relationship is used to represent the address of the observer.
[0070] That is, in an optional embodiment, after the singleton object is created, the observer's access is monitored; if it is monitored that the observer is accessing for the first time, it is necessary to obtain the identifier and address of the observer who is accessing for the first time, and write the obtained identifier and address of the observer who is accessing for the first time into the data structure of the singleton object. If it is monitored that the observer is not accessing for the first time, no processing is required at this time.
[0071] In an optional embodiment, the observer's identification refers to information used to uniquely characterize the observer's identity; wherein the observer's identification includes but is not limited to the observer's identification number, name, etc.
[0072] In an optional embodiment, the address of the observer refers to the location information of the observer, which is also a unique address.
[0073] It is understandable that the observer's first visit refers to the observer being created. If the observer is not accessed for the first time, then the observer has been created, that is, the observer's identifier and address have been written into the data structure of the singleton object.
[0074] It can be understood that the identifier and address of the first-access observer are written into the data structure of the singleton object in the form of a key-value pair relationship; the key element is used to represent the identifier of the observer, and the value element is used to represent the address of the observer. This makes it easier to quickly find the address of the observer based on the identifier of the observer, thereby improving the search speed.
[0075] For example, you can call the put method of hashmap, specifically, hashmap.put(observer.id, observer.address), where observer.id is the observer's identifier and observer.address is the observer's address. In this way, the observer's identifier and address are written / stored into the data structure of the singleton object in the form of a key-value pair. It is understandable that the observer's identifier and the observer's address can be of any data type, such as byte (8-bit, signed integer represented in two's complement), short (16-bit, signed integer represented in two's complement), int (32-bit, signed integer represented in two's complement), long (64-bit, signed integer represented in two's complement), float (single-precision, 32-bit, floating-point number compliant with the IEEE 754 standard), double (double-precision, 64-bit, floating-point number compliant with the IEEE 754 standard), boolean (one bit of information, only true and false values), char (a single 16-bit Unicode character). Correspondingly, you can call the get method of hashmap, specifically, hashmap.get(observer.id), and what is returned is the observer.address corresponding to the observer.id, so that you can get the address corresponding to the observer's identifier.
[0076] In one embodiment of the present application, after writing the identifier and address of the observer accessed for the first time into the data structure of the singleton object, the following steps may be further included:
[0077] Receive a delete instruction; wherein the delete instruction carries the identifier of the observer to be deleted;
[0078] According to the identifier of the observer to be deleted, the information of the observer that matches the identifier of the observer to be deleted is deleted from the information of multiple observers contained in the data structure of the singleton object.
[0079] That is, in an optional embodiment, according to the needs of the application scenario, relevant development staff can issue a deletion instruction. Then, after receiving the deletion instruction, it is necessary to delete the information of the observer that matches the identifier of the observer to be deleted from the information of multiple observers contained in the data structure of the singleton object based on the identifier of the observer to be deleted carried in the deletion instruction. In this way, when one / some observers do not have logical tasks or have adjusted their logical tasks, they can be deleted, realizing real-time adjustment of the observers managed in the singleton object and improving the flexibility and convenience of the singleton object in managing observers.
[0080] Step S302, in response to the first observer contained in the data structure of the singleton object monitoring the change of the attribute of the observed object, obtain the changed attribute data and generate custom header data; wherein the custom header data includes the identifier of the second observer as the data receiver.
[0081] In the embodiment of the present application, the first observer is an observer contained in the data structure of the singleton object, and it will monitor the properties of the observed object after being written into the data structure of the singleton object; wherein, if the first observer detects that the properties of the observed object have changed, the changed property data is obtained and custom header data is generated. If the first observer does not detect that the properties of the observed object have changed, the monitoring continues until the properties of the observed object are detected to have changed.
[0082] In the embodiment of the present application, the custom header data generated by the first observer includes the identification of the second observer as the data recipient; wherein, the identification of the second observer as the data recipient included in the custom header data may be one or more (two or more) to indicate which observer(s) are the data recipients.
[0083] Among them, the second observer can be the observer contained in the data structure of the singleton object; for example, the identifier of the second observer as the data receiver contained in the custom header data is "TMFOffline", and the data structure of the singleton object also contains the observer identifier "TMFOffline".
[0084] Among them, the second observer may not be the observer contained in the data structure of the singleton object; for example, the identifier of the second observer as the data receiver contained in the custom header data is "TMFOffline", but the data structure of the singleton object does not contain the observer identifier "TMFOffline".
[0085] Among them, the second observer may be partially an observer included in the data structure of the singleton object, and may be partially not an observer included in the data structure of the singleton object; for example, the identifiers of the second observer as the data receiver included in the custom header data are "TMFOffline" and "TMFLive", among which the data structure of the singleton object contains the observer identifier "TMFOffline" but does not contain the observer identifier "TMFLive".
[0086] Step S303: Encapsulate the attribute data, the custom header data, and the protocol specification information for data transmission between observers to generate first feature data.
[0087] In the embodiment of the present application, after the first observer monitors the change in the attributes of the observed object, obtains the changed attribute data, and generates custom header data, the attribute data, custom header data, and protocol specification information for data transmission between observers can be encapsulated to generate first feature data, that is, generate data to be transmitted.
[0088] In one embodiment of the present application, the process of encapsulating the attribute data, the custom header data, and the protocol specification information for data transmission between observers in step S303 to generate the first feature data may include the following steps:
[0089] Encrypting the acquired attribute data to obtain encrypted attribute data;
[0090] The encrypted attribute data, the custom header data, and the protocol specification information for data transmission between observers are encapsulated to generate first feature data.
[0091] Specifically, in an optional embodiment, the acquired attribute data is first encrypted to obtain encrypted attribute data. The encrypted attribute data, along with custom header data and protocol specification information for data transmission between observers, are then encapsulated to generate the first feature data. This encryption of the acquired attribute data and encapsulation based on the encrypted attribute data enhances the security of the attribute data and prevents attribute data leakage due to attacks.
[0092] In one embodiment of the present application, the process of encrypting the acquired attribute data to obtain the encrypted attribute data may include the following steps:
[0093] The acquired attribute data is converted into binary data, and bit operations are performed on the binary data to obtain data after bit operations, and the data after bit operations is used as encrypted attribute data.
[0094] That is, in an optional embodiment, the acquired attribute data is first converted into binary data, and then bitwise operations are performed on the converted binary data to obtain bitwise operated data. The bitwise operated data obtained at this time is the encrypted attribute data, thereby achieving encryption of the acquired attribute data. This attribute data encryption logic is simple and easy to implement.
[0095] Optional bit operations in the embodiment include but are not limited to and operation & (logical AND operation), or operation | (logical OR operation), xor operation ^ (exclusive OR operation), not operation ~ (logical NOT operation), shl operation << and shr operation >>, etc. In actual application, they can be flexibly selected according to the application scenario, and the present invention does not make specific limitations on this.
[0096] In one embodiment of the present application, the process of encapsulating the attribute data, the custom header data, and the protocol specification information for data transmission between observers in step S303 to generate the first feature data may include the following steps:
[0097] Adding the protocol specification information to the custom header data to generate the custom header data containing the protocol specification information;
[0098] The attribute data and the custom header data including the protocol specification information are encapsulated to generate first feature data.
[0099] That is, in an optional embodiment, the protocol specification information is first added to the custom header data to generate custom header data containing the protocol specification information. That is, the custom header data includes not only the identifier of the second observer serving as the data recipient, but also the protocol specification information. The attribute data and the custom header data containing the protocol specification information (which also includes the identifier of the second observer) are then encapsulated to generate the first feature data. This adds both the protocol specification information and the identifier of the second observer to the custom header data, eliminating the need to use separate fields to represent the protocol specification information. This improves maintainability, reduces the number of fields, and increases the data transmission rate.
[0100] Step S304: determine the address of the second observer from the data structure of the singleton object based on the identifier of the second observer, and send the first feature data to the second observer according to the address of the second observer, so that the second observer obtains the attribute data in the first feature data according to the protocol specification information in the received first feature data.
[0101] In an embodiment of the present application, attribute data, custom header data, and protocol specification information for data transmission between observers are encapsulated. After the first feature data is generated, it is necessary to determine the address of the second observer from the data structure of the singleton object based on the identifier of the second observer, and send the first feature data to the second observer according to the address of the second observer, so that the second observer can obtain the attribute data in the first feature data based on the protocol specification information in the received first feature data.
[0102] In some embodiments of this application, please refer to Figure 4 After the process of sending the first feature data to the second observer according to the address of the second observer in step S304, the following steps may be further included:
[0103] Step S401: The second observer receives the first feature data and parses the first feature data to obtain protocol specification information;
[0104] Step S402: The second observer loads attribute data from the first feature data according to the parsed protocol specification information.
[0105] That is, in an optional embodiment, after receiving the first characteristic data, the second observer must first parse the first characteristic data to obtain protocol specification information, and then load the attribute data from the first characteristic data based on the parsed protocol specification information. In other words, the protocol specification information is the medium for obtaining / loading attribute data from the first characteristic data. Only after parsing the protocol specification information from the first characteristic data can the attribute data in the first characteristic data be obtained / loaded using the parsed protocol specification information.
[0106] In some embodiments of the present application, the process of the second observer loading the attribute data from the first feature data according to the parsed protocol specification information in step S402 may include the following steps:
[0107] The second observer parses the first feature data according to the parsed protocol specification information to obtain encrypted attribute data;
[0108] The encrypted attribute data is decrypted to obtain decrypted attribute data, and the decrypted attribute data is used as the loaded attribute data.
[0109] That is, in an optional embodiment, when the first observer as the data sender encapsulates the attribute data, custom header data, and protocol specification information for data transmission between observers to generate the first characteristic data, the attribute data is encrypted for security reasons. Then, when the second observer as the data receiver receives the first characteristic data, it needs to first parse the first characteristic data according to the parsed protocol specification information to obtain the encrypted attribute data, and then decrypt the encrypted attribute data to obtain the decrypted attribute data. The decrypted attribute data obtained at this time is the loaded attribute data. In this way, the second observer as the data receiver can successfully obtain the attribute data in the first characteristic data.
[0110] In one embodiment of the present application, decrypting the encrypted attribute data to obtain the decrypted attribute data may include the following steps:
[0111] The encrypted attribute data is converted into binary data, and an inverse operation is performed on the binary data to obtain data after the inverse operation, and the data after the inverse operation is used as the decrypted attribute data; wherein the inverse operation is the opposite operation of the bit operation.
[0112] That is, in an optional embodiment, the first observer as the data sender encrypts the attribute data through bit operations. Then, when the second observer as the data receiver decrypts the attribute data, it is necessary to first convert the encrypted attribute data into binary data, and perform a bit inversion operation on the binary data to obtain the data after the bit inversion operation, and use the data after the bit inversion operation as the decrypted attribute data; it can be understood that the bit inversion operation is the opposite operation of the bit operation.
[0113] In one embodiment of the present application, see Figure 5 After the second observer loads the attribute data from the first feature data according to the parsed protocol specification information in step S402, the following steps may also be included:
[0114] Step S501: If the second observer needs to modify the attribute data, the loaded attribute data is copied;
[0115] Step S502: modify the copied attribute data and perform operations corresponding to the modified attribute data.
[0116] That is, in an optional embodiment, after the second observer loads the attribute data from the first characteristic data according to the parsed protocol specification information, if it is determined that the attribute data needs to be modified at this time, the loaded attribute data can be copied, and then the copied attribute data can be modified, and the operation corresponding to the modified attribute data can be performed, or the operation corresponding to the copied attribute data can be performed. In this way, the attribute data modified by the second observer is the attribute data it copied, and the attribute data in the first characteristic data is not modified, which can avoid the phenomenon that the first characteristic data is transmitted to other second observers as data recipients, that is, the attribute data received by other second observers as data recipients is still the attribute data in the first characteristic data (original, without any changes).
[0117] In one embodiment of the present application, see Figure 6 The second observer parses the first feature data and obtains the custom header data. After the second observer loads the attribute data from the first feature data according to the parsed protocol specification information in step S402, the following steps may also be included:
[0118] Step S601: The second observer modifies the second observer's identifier contained in the parsed custom header data to the identifier of the third observer to generate modified custom header data, and adds fields to the parsed protocol specification information to generate modified protocol specification information.
[0119] Step S602: Encapsulate the loaded attribute data, the modified custom header data, and the modified protocol specification information to generate second feature data;
[0120] Step S603: Determine the address of the third observer from the data structure of the singleton object based on the identifier of the third observer, and send the second characteristic data to the third observer according to the address of the third observer, so that the third observer obtains the attribute data in the second characteristic data according to the protocol specification information in the received second characteristic data.
[0121] That is, in an optional embodiment, the second observer parses the first characteristic data to obtain custom header data and protocol specification information, and then the second observer can simultaneously modify the parsed custom header data and protocol specification information to obtain modified custom header data and modified protocol specification information, and then encapsulate the loaded attribute data, modified custom header data and modified protocol specification information to generate second characteristic data.
[0122] In an optional embodiment, the second observer modifies the custom header data obtained by parsing, and specifically, the identifier of the second observer contained in the custom header data is modified, for example, to the identifier of the third observer, or the identifier of the third observer is added; wherein the third observer corresponding to the added identifier of the third observer is the next data recipient, and accordingly, the second observer now acts as the data sender, and the third observer is used to receive the second characteristic data sent by the second observer.
[0123] In an optional embodiment, the second observer modifies the protocol specification information obtained by parsing, specifically by adding a field to the protocol specification information; wherein the added field is used to indicate that the second observer has received the attribute data in the first characteristic data, that is, the next third observer as the data recipient parses the protocol specification information (that is, the protocol specification information modified by the second observer) from the second characteristic data when receiving the second characteristic data sent by the second observer, so that it can be determined according to the protocol specification information which observers have received the attribute data in the second characteristic data (also the attribute data in the first characteristic data, because only the protocol specification information and the identifier of the observer as the data recipient have changed in the first characteristic data and the second characteristic data, and the attribute data has not changed), and the attribute data should be loaded from the second characteristic data according to the protocol specification information.
[0124] In one embodiment of the present application, if the second observer is not an observer contained in the data structure of the singleton object, then the first observer needs to determine the address of the second observer from the data structure of other objects based on the identifier of the second observer, and then send the first feature data to the second observer according to the address of the second observer, so that the second observer obtains the attribute data in the first feature data according to the protocol specification information in the received first feature data.
[0125] In one embodiment of the present application, if the second observer is not an observer contained in the data structure of the singleton object, then the first observer can determine that the identifier of the second observer is an invalid identifier, that is, it is an invalid data recipient. At this time, there is no need to send the first feature data, and it can further be confirmed whether the identifier of the second observer is incorrect.
[0126] In the embodiment of the present application, singleton objects are used to manage observers, which can greatly reduce the objects that need to be maintained in data transmission. At the same time, it can also avoid the phenomenon of data transmission errors caused by too many objects in related technologies, thereby improving the accuracy of data transmission; and when the observer monitors that the attributes of the observed object have changed, the characteristic data it transmits contains the protocol specification information for data transmission between observers. In this way, the observer as the data receiver can obtain the attribute data contained in the characteristic data based on the protocol specification information, so that the attribute data can be accurately transmitted, which greatly improves the accuracy of data transmission.
[0127] The following is a detailed description of a specific application scenario of the embodiment of the present application:
[0128] See also Figure 7 , is a flow chart of an exemplary data processing method; the data processing method may include the following steps, which are described in detail as follows:
[0129] Step S701: Create a singleton object, the data structure of which contains information about the observer.
[0130] The preset event for creating a singleton object may be determined from a preset type and trigger event mapping table according to the business type, and if the preset event is detected to be triggered, the singleton object is created.
[0131] Step S702: If the first observer included in the data structure of the singleton object detects that the attribute of the observed object has changed, the changed attribute data is obtained and custom header data is generated.
[0132] The protocol specification information and the identifier of the second observer as the data receiver may be added to the custom header data to generate custom header data containing both the protocol specification information and the identifier of the second observer.
[0133] Step S703: The first observer encrypts the acquired changed attribute data to obtain encrypted attribute data.
[0134] The first observer encrypts the acquired changed attribute data to obtain the encrypted attribute data. This may be done by converting the acquired attribute data into binary data and then performing a bitwise operation on the binary data to obtain the bitwise-operated data. The bitwise-operated data is then the encrypted attribute data. Alternatively, the specific implementation of step S703 may refer to the technical solutions of the aforementioned embodiments.
[0135] In step S704 , the first observer encapsulates the encrypted attribute data, the custom header data, and the protocol specification information for data transmission between observers to generate first feature data.
[0136] The first observer encapsulates the encrypted attribute data, custom header data, and protocol specification information for data transmission between observers to generate the first characteristic data. This may be accomplished by encapsulating the attribute data and custom header data containing both the protocol specification information and the identifier of the second observer to generate the first characteristic data. Optionally, the specific implementation of step S704 may refer to the technical solutions of the aforementioned embodiments.
[0137] Step S705: The first observer determines the address of the second observer from the data structure of the singleton object based on the identifier of the second observer, and sends the first feature data to the second observer according to the address of the second observer.
[0138] The data structure of the singleton object may contain information about the observer, including a key-value pair relationship, where the key element in the key-value pair relationship is used to represent the observer's identifier, and the value element in the key-value pair relationship is used to represent the observer's address. Therefore, the first observer can determine the address of the second observer from the data structure of the singleton object based on the second observer's identifier, and can then send the first feature data to the second observer based on the determined address of the second observer. Optionally, the specific implementation process of step S705 can refer to the technical solution of the aforementioned embodiment.
[0139] In step S706 , the second observer receives the first feature data and parses the first feature data to obtain custom header data and protocol specification information.
[0140] The first observer sends the first characteristic data to the second observer. The second observer receives the first characteristic data and then parses the received first characteristic data to obtain custom header data and protocol specification information. It is understood that since the attribute data in the first characteristic data needs to be loaded with the aid of the protocol specification information in the first characteristic data, only the custom header data and protocol specification information are parsed here. Optionally, the specific implementation process of step S706 can refer to the technical solution of the aforementioned embodiment.
[0141] In step S707 , the second observer parses the first feature data according to the parsed protocol specification information to obtain encrypted attribute data.
[0142] After the second observer parses the first feature data to obtain the protocol specification information, it can then further parse the first feature data based on the parsed protocol specification information to obtain encrypted attribute data. It is understood that if the first observer does not encrypt the attribute data when encapsulating the first feature data, then the attribute data further parsed from the first feature data by the second observer based on the parsed protocol specification information is also unencrypted. Alternatively, the specific implementation process of step S707 may refer to the technical solutions of the aforementioned embodiments.
[0143] In step S708, the second observer decrypts the encrypted attribute data to obtain decrypted attribute data, and uses the decrypted attribute data as the loaded attribute data.
[0144] Among them, the second observer decrypts the encrypted attribute data to obtain the decrypted attribute data. The encrypted attribute data can be converted into binary data, and the binary data is inversely operated to obtain the data after the inverse operation. At this time, the data after the inverse operation is the decrypted attribute data; the inverse operation is the opposite operation of the bit operation.
[0145] If the second observer needs to modify the loaded attribute data, the loaded attribute data is copied, and then the copied attribute data is modified and the operation corresponding to the modified attribute data is performed. Optionally, the specific implementation process of step S708 can refer to the technical solution of the above embodiment.
[0146] In step S709, the second observer modifies the identifier of the second observer contained in the parsed custom header data to the identifier of the third observer to generate modified custom header data, and adds fields to the parsed protocol specification information to generate modified protocol specification information.
[0147] The third observer corresponding to the third observer identifier added by the second observer is the next data receiver. Accordingly, the second observer serves as the data sender at this time, and the third observer is used to receive the second feature data sent by the second observer.
[0148] The field added by the second observer is used to indicate that the second observer has received the attribute data in the first characteristic data. This allows the third observer, acting as the next data recipient, to parse the protocol specification information from the second characteristic data upon receiving the second characteristic data sent by the second observer. This allows the third observer, acting as the next data recipient, to determine which observers have received the attribute data in the second characteristic data based on the protocol specification information and to load the attribute data from the second characteristic data in accordance with the protocol specification information. Optionally, the specific implementation process of step S709 may refer to the technical solutions of the aforementioned embodiments.
[0149] In step S710 , the second observer encapsulates the loaded attribute data, the modified custom header data, and the modified protocol specification information to generate second feature data.
[0150] The second observer encapsulates the loaded attribute data, the modified custom header data, and the modified protocol specification information to generate the second characteristic data. This may be accomplished by encapsulating the attribute data and the custom header data containing both the modified protocol specification information and the identifier of the third observer to generate the first characteristic data. Alternatively, the specific implementation of step S710 may refer to the technical solutions of the aforementioned embodiments.
[0151] In step S711 , the second observer determines the address of the third observer from the data structure of the singleton object based on the identifier of the third observer, and sends the second feature data to the third observer according to the address of the third observer.
[0152] In the embodiment of the present application, data transmission between observers is realized through a singleton object, which not only reduces the objects that need to be maintained in data transmission (such as proxy objects in related technologies) and improves the maintainability of data transmission, but also encrypts the acquired changed attribute data to ensure the security of the attribute data. At the same time, when each observer receives the transmitted feature data, a field of protocol specification information in the feature data will be added to indicate that the feature data has been received.
[0153] The following is a detailed description of another specific application scenario of an embodiment of the present application. In this application scenario, the observation object is a video, and the observers contained in the global dictionary of the singleton object are playback observers, offline observers, live observers, and advertising observers. Information is used as an example for explanation:
[0154] See also Figure 8 , is a flow chart of an exemplary data processing method; the data processing method may include the following steps, which are described in detail as follows:
[0155] Step S801: If a playback application startup event is detected, a singleton object is created.
[0156] The singleton object SO may be created by establishing a one-time method (dispatch_once) in GCD (Grand Central Dispatch, multi-core programming).
[0157] Among them, see Figure 9, which is a schematic diagram of an exemplary singleton object; the singleton object includes a global dictionary module 901, a monitoring module 902, an encryption module 903, and a data parsing module 904, wherein:
[0158] The global dictionary module 901 contains the information of the observer; the information of each observer is stored in a key-value pair relationship. When each observer is first accessed, the observer's identifier and address are registered / written into the global dictionary module 901 of the singleton object, so the address of the corresponding observer can be obtained later through the observer's identifier k. Optionally, the observer information contained in the global dictionary module 901 can be registered / written by adding an observer method (addObserver), and can be deleted by removing the observer method (removeObserver). The monitoring module 902 is used to monitor whether the playback application startup event is triggered. The encryption module 903 is used to encrypt the acquired attribute data (for details, please refer to the introduction in step S803 below). The data parsing module 904 is used to parse the first feature data to obtain the attribute data, custom header data and protocol specification information in the first feature data (for details, please refer to the introduction in steps S806 to S807 below).
[0159] Step S802: If the first observer included in the global dictionary of the singleton object detects that the attribute of the observed object has changed, the changed attribute data is obtained and custom header data is generated; wherein the custom header data includes the identifier of the second observer as the data receiver.
[0160] Among them, the first observer can be a playback observer contained in the global dictionary of the singleton object. If the first observer detects that the attribute of the observed object has changed, the changed attribute data can be obtained by observing the current value change of the attribute (observeValueForKeyPath).
[0161] The protocol specification information and the identifier of the second observer as the data receiver may be added to the custom header data to generate the custom header data including both the protocol specification information and the identifier of the second observer.
[0162] In step S803, the first observer converts the acquired changed attribute data into binary data, performs an XOR operation on the binary data to obtain XOR-operated data, and uses the XOR-operated data as encrypted attribute data.
[0163] Among them, a bitwise operation such as a logical AND operation, a logical OR operation, or a logical NOT operation may also be performed on the binary data, so that the logic for encrypting the attribute data is simple and easy to implement.
[0164] In step S804 , the first observer encapsulates the encrypted attribute data, the custom header data, and the protocol specification information for data transmission between observers to generate first feature data.
[0165] The generated exemplary first feature data may be:
[0166]
[0167]
[0168] Therefore, it can be seen from the above exemplary first characteristic data that the custom header data contains both protocol specification information and the identifier of the second observer as the data receiver, wherein the identifier of the second observer as the data receiver is an offline observer and a live broadcast observer.
[0169] Step S805: The first observer determines the address of the second observer from the data structure of the singleton object based on the identifier of the second observer, and sends the first feature data to the second observer according to the address of the second observer.
[0170] Optionally, the specific implementation process of step S805 may refer to the technical solution of the aforementioned embodiment.
[0171] In step S806 , the second observer receives the first feature data and parses the first feature data to obtain custom header data and protocol specification information.
[0172] Optionally, the specific implementation process of step S806 may refer to the technical solution of the aforementioned embodiment.
[0173] Step S807: The second observer loads the encrypted attribute data from the first feature data according to the parsed protocol specification information.
[0174] Optionally, the specific implementation process of step S807 may refer to the technical solution of the aforementioned embodiment.
[0175] In step S808, the second observer converts the encrypted attribute data into binary data, performs an inverse XOR operation on the binary data, obtains data after the inverse XOR operation, and uses the data after the inverse XOR operation as the decrypted attribute data.
[0176] Optionally, the specific implementation process of step S808 may refer to the technical solution of the aforementioned embodiment.
[0177] Step S809: The second observer copies the decrypted attribute data and performs an operation corresponding to the decrypted attribute data.
[0178] Among them, the offline observer among the second observer can copy the decrypted attribute data and perform offline download operations based on the copied attribute data; the live broadcast observer among the second observer can directly perform live broadcast operations based on the decrypted attribute data obtained, that is, the live broadcast observer only needs to obtain the decrypted attribute data and does not need to copy the decrypted attribute data.
[0179] In step S810, the second observer modifies the identifier of the second observer contained in the parsed custom header data to the identifier of the third observer to generate modified custom header data, and adds fields to the parsed protocol specification information to generate modified protocol specification information.
[0180] Among them, the protocol specification information is the declared protocol for data transmission between observers. Because the observer as the data sender may pass through multiple observers in the process of transmitting data to the observer as the data receiver, the observer as the data receiver needs to add a field to the protocol specification information to indicate that the attribute data in the first feature data has been received (and this attribute data depends on the protocol specification information in the first feature data to be loaded).
[0181] Among them, the offline observer among the second observers modifies the observer identifier contained in the custom header data as needed, for example, it changes it to "TMFAdver", that is, "receiver_class": "TMFAdver", or "receiver_class": "TMFOffline\\TMFLive\\TMFAdver"; and it is necessary to add fields to the parsed protocol specification information at the same time, for example, add "text / plain", that is, "datas_type": "application / json, text / html, text / plain".
[0182] In step S811 , the second observer encapsulates the loaded attribute data, the modified custom header data, and the modified protocol specification information to generate second feature data.
[0183] Among them, the offline observer in the second observer encapsulates the loaded attribute data (i.e. "customDatas"...), the modified custom header data (i.e. "receiver_class": "TMFOffline\\TMFLive\\TMFAdver"), and the modified protocol specification information (i.e. "datas_type": "application / json, text / html, text / plain") to generate the second feature data.
[0184] Step S812: The second observer determines the address of the third observer from the data structure of the singleton object based on the identifier of the third observer, and sends the second feature data to the third observer according to the address of the third observer.
[0185] Among them, after the third observer (i.e., the advertising observer TMFAdver) receives the second characteristic data sent by the offline observer among the second observers, it needs to parse the second characteristic data to obtain the custom header data and protocol specification information in the second characteristic data. Then, the third observer loads the attribute data from the second characteristic data according to the parsed protocol specification information, and then can perform the advertising playback operation corresponding to the attribute data, or generate the third characteristic data again. The generation of the third characteristic data can refer to the process of generating the second characteristic data in the aforementioned embodiment.
[0186] See also Figure 10 , is a flow chart of an exemplary data processing method; the data processing method may include the following steps, which are described in detail as follows:
[0187] Step S1001: A first observer included in the data structure of a singleton object monitors properties of an observed object.
[0188] In step S1002, when the first observer included in the data structure of the singleton object detects that the attribute of the observed object has changed, the method for obtaining the change of the current value of the observed attribute (observeValueForKeyPath) is called to obtain the attribute data after the change.
[0189] Step S1003: Retrieve the identifier of the second observer serving as the data receiver from the data structure of the singleton object.
[0190] Step S1004: Generate custom header data according to the identifier of the second observer, and encapsulate the attribute data, custom header data, and protocol specification information for data transmission between observers to construct first feature data, and send it to the second observer.
[0191] In step S1005 , the second observer receives the first feature data and determines whether the attribute data needs to be modified; if so, step S1006 is executed; if not, step S1007 is executed.
[0192] Step S1006: copy the attribute data in the first feature data, modify the copied attribute data, and generate the second feature data.
[0193] Step S1007: recursively extract the observer contained in the data structure of the singleton object to transfer the second feature data.
[0194] Step S1008, determining whether the next observer is the data recipient specified in the custom header data in the second feature data; if so, executing step S1009, if not, returning to executing step S1007.
[0195] Step S1009: parse the second feature data and output the attribute data in the second feature data.
[0196] Optionally, the specific implementation process of steps S1001 to S1009 may refer to the technical solutions of the aforementioned embodiments.
[0197] Figure 11 FIG. 1 is a block diagram of a data processing device according to an embodiment of the present application. Figure 11 As shown, the device includes:
[0198] A creation module 1101 is configured to create a singleton object, wherein the data structure of the singleton object includes information about the observer;
[0199] The monitoring and acquisition module 1102 is configured to, in response to a first observer included in the data structure of the singleton object detecting a change in an attribute of the observed object, acquire the changed attribute data and generate custom header data; wherein the custom header data includes an identifier of a second observer serving as a data recipient;
[0200] The encapsulation module 1103 is configured to encapsulate the attribute data, the custom header data, and the protocol specification information for data transmission between observers to generate first feature data;
[0201] The sending module 1104 is configured to determine the address of the second observer from the data structure of the singleton object based on the identifier of the second observer, and send the first characteristic data to the second observer according to the address of the second observer, so that the second observer obtains the attribute data according to the protocol specification information in the received first characteristic data.
[0202] In the embodiment of the present application, the use of singleton objects to manage observers can greatly reduce the objects that need to be maintained in data transmission, and at the same time avoid the phenomenon of data transmission errors caused by too many objects in related technologies, thereby improving the accuracy of data transmission; and, when the observer monitors that the attributes of the observed object have changed, the characteristic data it transmits contains the protocol specification information for data transmission between observers, so that the observer as the data receiver can obtain the attribute data contained in the characteristic data based on the protocol specification information, so that the attribute data can be accurately transmitted, which greatly improves the accuracy of data transmission.
[0203] In one embodiment of the present application, the encapsulation module 1103 includes:
[0204] an encryption unit configured to encrypt the acquired attribute data to obtain encrypted attribute data;
[0205] The encapsulation unit is configured to encapsulate the encrypted attribute data, the custom header data, and the protocol specification information for data transmission between observers to generate first feature data.
[0206] In one embodiment of the present application, the encryption unit is specifically configured to convert the acquired attribute data into binary data, perform bit operations on the binary data, obtain bit-operated data, and use the bit-operated data as encrypted attribute data.
[0207] In one embodiment of the present application, the apparatus further comprises:
[0208] a receiving module configured to receive the first characteristic data as a second observer, and parse the first characteristic data to obtain protocol specification information;
[0209] The loading module is configured for the second observer to load the attribute data from the first feature data according to the parsed protocol specification information.
[0210] In one embodiment of the present application, the apparatus further comprises:
[0211] a copy module configured to copy the loaded attribute data if the second observer needs to modify the attribute data;
[0212] The modification and execution module is configured to modify the copied attribute data and execute operations corresponding to the modified attribute data.
[0213] In one embodiment of the present application, the apparatus further comprises:
[0214] a modification module configured to cause the second observer to modify the identifier of the second observer contained in the parsed custom header data to the identifier of the third observer to generate modified custom header data, and to add fields to the parsed protocol specification information to generate modified protocol specification information;
[0215] a generating module configured to encapsulate the loaded attribute data, the modified custom header data, and the modified protocol specification information to generate second feature data;
[0216] The sending module 1104 is also configured to determine the address of the third observer from the data structure of the singleton object based on the identifier of the third observer, and send the second characteristic data to the third observer according to the address of the third observer, so that the third observer obtains the attribute data in the second characteristic data according to the protocol specification information in the received second characteristic data.
[0217] In one embodiment of the present application, the loading module includes:
[0218] a parsing unit configured to parse the first feature data according to the parsed protocol specification information to obtain encrypted attribute data by the second observer;
[0219] The decryption unit is configured to decrypt the encrypted attribute data to obtain the decrypted attribute data, and use the decrypted attribute data as the loaded attribute data.
[0220] In one embodiment of the present application, the decryption unit is specifically configured to convert the encrypted attribute data into binary data, perform a bit inversion operation on the binary data, obtain the data after the bit inversion operation, and use the data after the bit inversion operation as the decrypted attribute data; wherein the bit inversion operation is the opposite operation of the bit operation.
[0221] In one embodiment of the present application, the apparatus further comprises:
[0222] an acquisition module, configured to acquire the identifier and address of the observer who made the first visit if the observer's first visit is detected;
[0223] A writing module is configured to write the identifier and address of the observer who visits for the first time into the data structure of the singleton object; wherein the data structure of the singleton object contains the information of the observer in a key-value pair relationship, the key element in the key-value pair relationship is used to represent the identifier of the observer, and the value element in the key-value pair relationship is used to represent the address of the observer.
[0224] In one embodiment of the present application, the apparatus further comprises:
[0225] The receiving module is further configured to receive a deletion instruction; wherein the deletion instruction carries the identifier of the observer to be deleted;
[0226] The deletion module is configured to delete the information of the observer that matches the identifier of the observer to be deleted from the information of multiple observers contained in the data structure of the singleton object according to the identifier of the observer to be deleted.
[0227] In one embodiment of the present application, the creation module 1101 is specifically configured to determine the preset event for creating a singleton object from a preset type and trigger event mapping relationship table based on the business type; wherein the preset type and trigger event mapping relationship table presets multiple business types and trigger events corresponding to various business types; if it is monitored that the preset event is triggered, a singleton object is created.
[0228] In one embodiment of the present application, the monitoring and acquisition module 1102 includes:
[0229] an adding unit configured to add the protocol specification information to the custom header data to generate the custom header data including the protocol specification information;
[0230] The generating unit is configured to encapsulate the attribute data and the custom header data including the protocol specification information to generate first feature data.
[0231] It should be noted that the apparatus provided in the above embodiment and the method provided in the above embodiment belong to the same concept, wherein the specific manner in which each module and unit performs operations has been described in detail in the method embodiment and will not be repeated here.
[0232] An embodiment of the present application also provides an electronic device, comprising one or more processors and a storage device, wherein the storage device is used to store one or more programs, and when the one or more programs are executed by the electronic device, the above data processing method is implemented.
[0233] Figure 12 A schematic diagram of the structure of a computer system suitable for implementing an electronic device according to an embodiment of the present application is shown.
[0234] It should be noted that Figure 12 The computer system 1200 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0235] like Figure 12As shown, the computer system 1200 includes a central processing unit (CPU) 1201, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1202 or the program loaded from the storage part 1208 to the random access memory (RAM) 1203, such as executing the method in the above embodiment. Various programs and data required for system operation are also stored in the RAM 1203. The CPU 1201, ROM 1202 and RAM 1203 are connected to each other via a bus 1204. An input / output (I / O) interface 1205 is also connected to the bus 1204.
[0236] The following components are connected to the I / O interface 1205: an input section 1206 including a keyboard, a mouse, and the like; an output section 1207 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and speakers; a storage section 1208 including a hard disk; and a communication section 1209 including a network interface card such as a LAN (Local Area Network) card or a modem. The communication section 1209 performs communication processing via a network such as the Internet. A drive 1210 is also connected to the I / O interface 1205 as needed. Removable media 1211, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 1210 as needed, so that computer programs read from the removable media can be installed in the storage section 1208 as needed.
[0237] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 1209, and / or installed from a removable medium 1211. When the computer program is executed by the central processing unit (CPU) 1201, the various functions defined in the system of the present application are executed.
[0238] It should be noted that the computer-readable medium shown in the embodiments of the present application 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, 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 can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a 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 the present application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable computer program. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. A computer program embodied on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wired, or any suitable combination thereof.
[0239] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. Among them, each box in the flowchart or block diagram can represent a module, program segment, or part of the code, and the above-mentioned module, program segment, or part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two 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 box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0240] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. In some cases, the names of these units do not constitute limitations on the units themselves.
[0241] Another aspect of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the aforementioned data processing method. The computer-readable storage medium may be included in the electronic device described in the above embodiments, or may exist independently and not be incorporated into the electronic device.
[0242] Another aspect of the present application further provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the data processing method provided in each of the above embodiments.
[0243] The above content is only a preferred exemplary embodiment of the present application and is not intended to limit the implementation scheme of the present application. Ordinary technicians in this field can easily make corresponding changes or modifications based on the main ideas and spirit of the present application. Therefore, the scope of protection of the present application shall be based on the scope of protection required by the claims.
Claims
1. A data processing method, characterized in that: The method comprises: Create a singleton object, the data structure of which contains information about the observer; In response to a first observer included in the data structure of the singleton object detecting a change in an attribute of the observed object, acquiring the changed attribute data and generating custom header data; wherein the custom header data includes an identifier of a second observer as a data receiver; Encapsulating the attribute data, the custom header data, and protocol specification information for data transmission between observers to generate first feature data; Based on the identifier of the second observer, the address of the second observer is determined from the data structure of the singleton object, and the first feature data is sent to the second observer according to the address of the second observer, so that the second observer obtains the attribute data in the first feature data according to the protocol specification information in the received first feature data.
2. The data processing method according to claim 1, wherein: The encapsulating the attribute data, the custom header data, and the protocol specification information for data transmission between observers to generate the first feature data includes: Encrypting the acquired attribute data to obtain encrypted attribute data; The encrypted attribute data, the custom header data, and protocol specification information for data transmission between observers are encapsulated to generate first feature data.
3. The data processing method according to claim 2, wherein: The step of encrypting the acquired attribute data to obtain encrypted attribute data includes: The acquired attribute data is converted into binary data, and a bit operation is performed on the binary data to obtain data after the bit operation, and the data after the bit operation is used as the encrypted attribute data.
4. The data processing method according to claim 1, wherein: After sending the first feature data to the second observer according to the address of the second observer, the method further includes: The second observer receives the first feature data and parses the first feature data to obtain the protocol specification information; The second observer loads the attribute data from the first feature data according to the parsed protocol specification information.
5. The data processing method according to claim 4, wherein: After the second observer loads the attribute data from the first feature data according to the parsed protocol specification information, the method further includes: If the second observer needs to modify the attribute data, the loaded attribute data is copied; The copied attribute data is modified, and an operation corresponding to the modified attribute data is performed.
6. The data processing method according to claim 4, wherein: The second observer analyzes the first feature data to obtain the custom header data; the method further includes: The second observer modifies the identifier of the second observer contained in the parsed custom header data to the identifier of the third observer to generate modified custom header data, and adds a field to the parsed protocol specification information to generate modified protocol specification information; Encapsulating the loaded attribute data, the modified custom header data, and the modified protocol specification information to generate second feature data; Based on the identifier of the third observer, the address of the third observer is determined from the data structure of the singleton object, and the second feature data is sent to the third observer according to the address of the third observer, so that the third observer obtains the attribute data in the second feature data according to the protocol specification information in the received second feature data.
7. The data processing method according to claim 4, wherein: The second observer loads the attribute data from the first feature data according to the parsed protocol specification information, including: The second observer parses the first feature data according to the parsed protocol specification information to obtain encrypted attribute data; The encrypted attribute data is decrypted to obtain decrypted attribute data, and the decrypted attribute data is used as the loaded attribute data.
8. The data processing method according to claim 7, wherein: Decrypting the encrypted attribute data to obtain the decrypted attribute data includes: The encrypted attribute data is converted into binary data, and an inverse operation is performed on the binary data to obtain data after the inverse operation, and the data after the inverse operation is used as the decrypted attribute data; wherein the inverse operation is the opposite operation of the bit operation.
9. The data processing method according to any one of claims 1 to 8, characterized in that: After creating the singleton object, the method further includes: If the observer's first visit is detected, the identifier and address of the observer who visited for the first time are obtained; The identifier and address of the observer who visits for the first time are written into the data structure of the singleton object; wherein the data structure of the singleton object contains the information of the observer in a key-value pair relationship, the key element in the key-value pair relationship is used to represent the identifier of the observer, and the value element in the key-value pair relationship is used to represent the address of the observer.
10. The data processing method according to claim 9, wherein: After writing the identifier and address of the first-accessed observer into the data structure of the singleton object, the method further includes: Receiving a deletion instruction; wherein the deletion instruction carries the identifier of the observer to be deleted; According to the identifier of the observer to be deleted, the information of the observer that matches the identifier of the observer to be deleted is deleted from the information of multiple observers contained in the data structure of the singleton object.
11. The data processing method according to any one of claims 1 to 8, characterized in that: The creation of a singleton object includes: Determine, according to the business type, from a preset type and trigger event mapping relationship table, a preset event for creating a singleton object; wherein the preset type and trigger event mapping relationship table is preset with multiple business types and trigger events corresponding to the various business types; If it is detected that the preset event is triggered, the singleton object is created.
12. The data processing method according to any one of claims 1 to 8, characterized in that: The encapsulating the attribute data, the custom header data, and the protocol specification information for data transmission between observers to generate the first feature data includes: Adding the protocol specification information to the custom header data to generate the custom header data including the protocol specification information; The attribute data and the custom header data including the protocol specification information are encapsulated to generate the first feature data.
13. A data processing device, characterized in that: The device comprises: A creation module is configured to create a singleton object, wherein the data structure of the singleton object includes information about the observer; a monitoring and acquisition module configured to, in response to a first observer included in the data structure of the singleton object detecting a change in an attribute of the observed object, acquire the changed attribute data and generate custom header data; wherein the custom header data includes an identifier of a second observer serving as a data recipient; an encapsulation module configured to encapsulate the attribute data, the custom header data, and protocol specification information for data transmission between observers to generate first feature data; A sending module is configured to determine the address of the second observer from the data structure of the singleton object based on the identifier of the second observer, and send the first characteristic data to the second observer according to the address of the second observer, so that the second observer obtains the attribute data according to the protocol specification information in the received first characteristic data.
14. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs, which, when executed by the electronic device, enables the electronic device to implement the data processing method according to any one of claims 1 to 12.
15. A computer-readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the data processing method according to any one of claims 1 to 12 is implemented.
16. A computer program product comprising computer instructions, characterized in that When the computer instructions are executed by a processor, the data processing method according to any one of claims 1 to 12 is implemented.
Citation Information
Patent Citations
Method and device for controlling content to be refreshed in real time
CN108228300A
Cross-platform communication method and device and electronic equipment
CN111182019A