Player data serialization method, apparatus, and electronic device
Patent Information
- Application Number
- CN202211399460.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-09
- Publication Date
- 2026-09-25
- Estimated Expiration
- 2042-11-09
AI Technical Summary
[0003]相关技术中,对玩家数据序列化的方法通常是对所有的类进行序列化,所有类包括游戏中的小怪、地图、道具、装备等等,然后手动筛选出序列化后的类对应的数据中的玩家数据,该手动筛选需要消耗大量的人力成本;同时,对所有类进行序列化需要对所有类进行穷举,耗时较高
[0010]本发明提供的一种玩家数据序列化方法、装置和电子设备,首先从预设的代码文件中,获取包含有预设关键字的玩家数据类;进而基于预设关键字的声明,确定玩家数据类对应的玩家数据的数据类型;然后根据玩家数据的数据类型指示的序列化方式,对玩家数据进行序列化处理,得到玩家数据的序列化结果。该方式在代码文件中通过预设关键字标记玩家数据类,以在玩家数据序列化阶段直接根据预设关键字确定玩家数据类,并仅对玩家数据类进行序列化,该方式无需对代码文件中所有的类进行序列化,降低了序列化运算复杂度,也提高了数据序列化的效率;同时,该方式无需从序列化后的数据中人工筛选出玩家数据,节省了人力成本。
Smart Images

Figure CN115845390B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and in particular to a method, apparatus and electronic device for serializing player data. Background Technology
[0002] Game designers typically use an attribute editor to edit serialized player data in real time; this data includes in-game items, equipment, character attributes, and more. By editing player data, designers can observe the game effects of different player values and thus optimize the player experience.
[0003] In related technologies, the method for serializing player data usually involves serializing all classes, including monsters, maps, items, equipment, etc. in the game, and then manually filtering out the player data in the data corresponding to the serialized classes. This manual filtering requires a lot of manpower. At the same time, serializing all classes requires exhaustively listing all classes, which is time-consuming. Summary of the Invention
[0004] The purpose of this invention is to provide a player data serialization method, apparatus, and electronic device to improve the efficiency of player data serialization.
[0005] In a first aspect, the present invention provides a player data serialization method, the method comprising: obtaining a player data class containing a preset keyword from a preset code file; determining the data type of the player data corresponding to the player data class based on the declaration of the preset keyword; wherein the data type is used to indicate the serialization method corresponding to the player data; and performing serialization processing on the player data according to the serialization method indicated by the data type of the player data to obtain the serialization result of the player data.
[0006] Secondly, the present invention provides a player data serialization device, the device comprising: a data class acquisition module, configured to acquire a player data class containing a preset keyword from a preset code file; a data type determination module, configured to determine the data type of the player data corresponding to the player data class based on the declaration of the preset keyword; wherein the data type is used to indicate the serialization method corresponding to the player data; and a data serialization module, configured to perform serialization processing on the player data according to the serialization method indicated by the data type of the player data, to obtain the serialization result of the player data.
[0007] Thirdly, the present invention provides an electronic device including a processor and a memory, the memory storing machine-executable instructions that can be executed by the processor, the processor executing the machine-executable instructions to implement the above-described player data serialization method.
[0008] Fourthly, the present invention provides a computer-readable storage medium storing computer-executable instructions that, when invoked and executed by a processor, cause the processor to implement the aforementioned player data serialization method.
[0009] The embodiments of the present invention bring the following beneficial effects:
[0010] This invention provides a player data serialization method, apparatus, and electronic device. First, it obtains player data classes containing preset keywords from a preset code file. Then, based on the declaration of the preset keywords, it determines the data type of the player data corresponding to each player data class. Next, it serializes the player data according to the serialization method indicated by the data type, obtaining the serialized result of the player data. This method marks player data classes in the code file using preset keywords, allowing direct determination of player data classes during the player data serialization stage. Only player data classes are serialized, eliminating the need to serialize all classes in the code file, reducing the complexity of serialization operations, and improving the efficiency of data serialization. Furthermore, this method eliminates the need for manual selection of player data from the serialized data, saving labor costs.
[0011] Other features and advantages of the invention will be set forth in the following description, or some features and advantages may be inferred from the description or determined without doubt, or may be learned by practicing the techniques described above.
[0012] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0013] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0014] Figure 1 A flowchart illustrating a player data serialization method provided in an embodiment of the present invention;
[0015] Figure 2 A flowchart illustrating another player data serialization method provided in an embodiment of the present invention;
[0016] Figure 3 A flowchart illustrating another player data serialization method provided in an embodiment of the present invention;
[0017] Figure 4 This is a schematic diagram of the structure of a player data serialization device provided in an embodiment of the present invention;
[0018] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0019] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0020] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0021] Game designers edit player data to observe its effects on the game under different values, thereby optimizing the player experience. Specifically, game designers typically use an attribute editor to edit serialized player data in real time. This player data includes in-game items, equipment, character attributes, etc. Serialization refers to converting data structures into a format that can be saved or buffered for network or file transmission, facilitating recovery in another environment or software.
[0022] In related technologies, the method for serializing player data typically involves serializing all classes (including monsters, maps, items, equipment, etc. in the game), and then manually filtering out the player data from the data corresponding to the serialized classes. The entire process is as follows:
[0023] (1) Scan the code file to identify all classes and the keywords of class member variables; where class member variables are the data corresponding to the class.
[0024] (2) Determine the data type of class member variables.
[0025] (3) Traverse all classes, recursively perform inheritance based on inheritance relationships, eliminate nested declarations, and complete the serialization of all class member variables.
[0026] (4) Manual screening to determine which member variables in the serialized class are player data.
[0027] The aforementioned method for serializing player data requires program intervention. Furthermore, as versions iterate, the keys of class member variables change, necessitating a re-filtering of player data, which incurs significant manpower costs. Additionally, the recursive process exhaustively enumerates all classes, resulting in a time complexity of O(n^2). 2 It takes a relatively long time.
[0028] To address the aforementioned issues, embodiments of the present invention provide a player data serialization method, apparatus, and electronic device. This technology can be applied to scenarios involving the processing of player data within games, particularly scenarios involving the serialization and editing of player data.
[0029] To facilitate understanding of the embodiments of the present invention, a player data serialization method disclosed in the embodiments of the present invention will first be described in detail, such as... Figure 1 As shown, the method includes the following specific steps:
[0030] Step S102: Obtain the player data class containing preset keywords from the preset code file.
[0031] The aforementioned code files typically store the code programs written by programmers that run the game. In the actual implementation, during the code definition process within these files, player data classes need to be marked with preset keywords. These keywords are used to identify the player data class during data serialization. Specifically, if a class contains member variables representing player data, then that class is the player data class. The specific form of these preset keywords can be determined based on the code definition during development and is not specifically limited here. For example, the preset keyword could be `Property` or `AAAA`, etc.
[0032] In the actual implementation, during the code definition process, the player data class is marked with a preset keyword. That is, the member variables of the player data type are declared with the preset keyword. Specifically, the preset keyword can declare the variable name, variable type and access permissions of the member variable.
[0033] It should be noted that only the player data class in the code file is marked with the preset keyword. All other classes in the code file do not use the preset keyword. Therefore, only the class marked with the preset keyword is the player data class in the code text, and the member variables of the player data class are the player data that needs to be serialized.
[0034] Step S104: Based on the declaration of preset keywords, determine the data type of the player data corresponding to the player data class; wherein, the data type is used to indicate the serialization method corresponding to the player data.
[0035] In practical implementation, the code file contains at least one player data class. When there are multiple player data classes in the code text, the variable type of the member variables corresponding to each player data class can be determined based on the declaration of the preset keyword corresponding to that player data class. Specifically, the variable type of the member variables is also the data type of the player data corresponding to the player data class.
[0036] Step S106: Serialize the player data according to the serialization method indicated by the data type of the player data to obtain the serialization result of the player data.
[0037] The data type of the player data corresponds to the storage format of the data in the serialization result (which corresponds to the serialization method indicated by the data type). For example, if the data type of the player data is int, then the serialized data occupies 8 bits; if the data type of the player data is str, then the serialized data occupies variable-length characters; if the data type of the player data is float, then the serialized data occupies 32 bits.
[0038] In the specific implementation, when the code text contains multiple player data classes, for each player data class, the player data corresponding to that player data class is serialized according to the serialization method indicated by the data type of the player data corresponding to that player data class, and the serialization result of that player data is obtained.
[0039] This invention provides a player data serialization method. First, it obtains player data classes containing preset keywords from a preset code file. Then, based on the declaration of the preset keywords, it determines the data type of the player data corresponding to each player data class. Next, it serializes the player data according to the serialization method indicated by the data type, obtaining the serialized result. This method marks player data classes in the code file with preset keywords, allowing direct determination of player data classes during the serialization stage. Only player data classes are serialized, eliminating the need to serialize all classes in the code file, reducing serialization computation complexity, and improving data serialization efficiency. Furthermore, this method eliminates the need for manual selection of player data from the serialized data, saving labor costs.
[0040] This invention also provides another player data serialization method, which is implemented based on the above embodiments. This method focuses on describing the specific process of determining the data type of player data corresponding to the player data class based on the declaration of preset keywords (specifically implemented through step S204 below); such as Figure 2 As shown, the method includes the following specific steps:
[0041] Step S202: Obtain the player data class containing preset keywords from the preset code file.
[0042] In the specific implementation, before retrieving the player data class containing the preset keyword from the preset code file, the player data class needs to be marked with the preset keyword in the code file. That is, the player data class is declared in the code file using the preset keyword; the declaration of the preset keyword includes: the variable name, variable type, and access permissions corresponding to the player data class; the variable type is used to indicate the data type of the player data corresponding to the player data class.
[0043] In practical applications, the player data class first needs to be manually marked using preset keywords during code definition. Then, during serialization, the player data class is determined based on the markings, and the player data corresponding to the player data class is directly serialized. During code definition, member variables of the player data class can be marked using the format of preset keywords (variable name, variable type, access permissions). These member variables are equivalent to the player data corresponding to the player data class (i.e., the player data that needs to be serialized). Alternatively, it can be understood that only classes in the code file that use the format of preset keywords (variable name, variable type, access permissions) are player data types.
[0044] To facilitate understanding of the embodiments of the present invention, it is assumed that the preset keyword is Property, and the code definition process is represented by Tables 1 and 2 below:
[0045] Table 1
[0046] Property("name", str, CLIENT) Property("level",int,CLIENT) Property("exp", int, CLIENT)
[0047] Table 2
[0048] Property("item",dict,CLIENT) Property("item_use_time",dict,CLIENT) Property("item_detail",dict,CLIENT)
[0049] As shown in Tables 1 and 2 above, the Player class inherits from the Asset class; both are player data classes. The Property(item, dict, CLIENT) marker in the Asset class declares a member variable `item` of type dictionary `dict`, accessible only to the client `CLIENT`. During the creation of an Asset object, the `item` member variable needs to be initialized according to the declaration. The meanings of other class member variables marked with Property are similar to those of `item`.
[0050] Step S204: Obtain the variable type from the declaration of the preset keyword and determine the variable type as the data type of the player data corresponding to the player data class.
[0051] For each player data class, the variable type is obtained from the declaration of the preset keyword corresponding to the current player class, which is to say, the data type of the player data corresponding to the current player data class is obtained. This data type is used to indicate the serialization method of the player data, which is the storage format of the player data corresponding to the current player data after serialization.
[0052] Step S206: Serialize the player data according to the serialization method indicated by the data type of the player data to obtain the serialization result of the player data.
[0053] The aforementioned player data serialization method first retrieves player data classes containing preset keywords from a pre-defined code file; then, it obtains the variable types from the declarations of the preset keywords and determines the variable types to be the data types of the player data corresponding to the player data class; finally, it serializes the player data according to the serialization method indicated by the player data data type, obtaining the serialized result of the player data. In this method, during the serialization stage, the preset keywords can directly determine which classes in the code file are player data classes, and the player data corresponding to those classes can be directly serialized, eliminating the need for filtering the serialized data in related technologies. Furthermore, this method changes from traversing all classes to directly traversing the player data class, resulting in lower complexity and improved efficiency in player data serialization.
[0054] This invention also provides another player data serialization method, which is implemented based on the above embodiments. This method focuses on describing the specific process of serializing player data according to the serialization method indicated by the data type of the player data when multiple player data containing preset keywords are obtained, to obtain the serialization result of the player data (specifically implemented through the following steps S306-S314); such as Figure 3 As shown, the method includes the following specific steps:
[0055] Step S302: Obtain the player data class containing preset keywords from the preset code file.
[0056] Step S304: Determine the data type of player data corresponding to each player data class based on the declaration of the preset keywords corresponding to each player data class.
[0057] Step S306: Determine whether there is an inheritance relationship between multiple player data classes; if there is no inheritance relationship, proceed to step S308; otherwise, proceed to step S310.
[0058] In the actual implementation, it is necessary to traverse all the player data classes obtained from the code file to determine whether there is a class inheritance relationship among all the player data classes. Here, class inheritance relationship means that there is a class that inherits from another class. The inherited class can be called the base class, and the class that inherits from the inherited class can be called the derived class.
[0059] Step S308: For each player data class, serialize the player data corresponding to the player data class according to the serialization method indicated by the data type corresponding to the player data class, and obtain the serialization result of the player data corresponding to the player data class.
[0060] If there is no inheritance relationship between all the player data classes obtained from the code file, the player data classes can be serialized directly. That is, the player data corresponding to each player data class is serialized according to the serialization method indicated by the data type of each player data class, so as to obtain the serialization result of each player data.
[0061] Step S310: Determine the base class and derived class in multiple player data classes; wherein the derived class inherits from the base class.
[0062] If there is an inheritance relationship between all the player data classes obtained from the code file, it is necessary to determine which are the base classes and which are the derived classes from all the player data classes. Then, the base classes are serialized first, and the serialization result of the base classes is used for the derived classes. Finally, the inheritance relationship is eliminated by recursion.
[0063] Step S312: Serialize the player data corresponding to the base class according to the serialization method indicated by the data type corresponding to the base class to obtain the serialization result of the player data corresponding to the base class.
[0064] Step S314: Based on the serialization result of the player data corresponding to the base class, determine the serialization result of the player data corresponding to the derived class.
[0065] In the specific implementation, for each derived class, the following operations are performed: First, determine the base class corresponding to the current derived class. If the current derived class has target player data that is the same as the base class corresponding to the current derived class, then use the serialization result of the target player data corresponding to the base class of the current derived class as the serialization result of the target player data corresponding to the current derived class. Then, for other player data in the current derived class besides the target player data, serialize the other player data according to the serialization method indicated by the data type of the other player data. For example, if player data class B inherits from player data class A, and they both have member variable X (that is, they both have player data X), then X in player data class B can directly use the serialization result of player data class A.
[0066] In practical applications, if the current derived class does not have target player data that is the same as the base class corresponding to the current derived class, the player data is serialized directly according to the serialization indicated by the data type of the player data corresponding to the current derived class, and the serialization result of the player data corresponding to the current derived class is obtained.
[0067] The above player data serialization method identifies player data classes by using preset keywords. Only class member variables declared with preset keywords are considered player data, and the class is then classified as a player data class. During serialization, the player data class is serialized directly, reducing the complexity of serialization.
[0068] In accordance with the above method embodiments, this invention also provides a player data serialization device, such as... Figure 4 As shown, the device includes:
[0069] The data acquisition module 40 is used to acquire player data classes containing preset keywords from preset code files.
[0070] The data type determination module 41 is used to determine the data type of player data corresponding to the player data class based on the declaration of preset keywords; wherein, the data type is used to indicate the serialization method corresponding to the player data.
[0071] The data serialization module 42 is used to serialize the player data according to the serialization method indicated by the data type of the player data, and obtain the serialization result of the player data.
[0072] The aforementioned player data serialization device first retrieves player data classes containing preset keywords from a preset code file; then, based on the declaration of the preset keywords, it determines the data type of the player data corresponding to the player data class; and finally, it serializes the player data according to the serialization method indicated by the data type, obtaining the serialized result of the player data. This method marks player data classes in the code file using preset keywords, allowing direct determination of player data classes based on these keywords during the player data serialization stage, and serialization only of player data classes. This method eliminates the need to serialize all classes in the code file, reducing the complexity of serialization operations and improving the efficiency of data serialization. Furthermore, this method eliminates the need for manual selection of player data from the serialized data, saving labor costs.
[0073] Specifically, the device further includes a tagging module for: tagging the player data class in the code file with the preset keywords before obtaining the player data class containing the preset keywords from the preset code file.
[0074] In specific implementation, the aforementioned marker module is also used to: declare player data classes in code files using preset keywords; wherein, the declaration of preset keywords includes: the variable name, variable type, and access permissions corresponding to the player data class; the variable type is used to indicate the data type of the player data corresponding to the player data class.
[0075] Furthermore, the aforementioned data type determination module 41 is used to: obtain the variable type from the declaration of the preset keyword, and determine the variable type as the data type of the player data corresponding to the player data class.
[0076] In specific implementation, there are multiple player data classes containing preset keywords; the data serialization module 42 is also used to: determine whether there is an inheritance relationship between the multiple player data classes; if there is no inheritance relationship, for each player data class, according to the serialization method indicated by the data type corresponding to the player data class, the player data corresponding to the player data class is serialized to obtain the serialization result of the player data corresponding to the player data class.
[0077] Specifically, the data serialization module 42 described above is also used to: if there is an inheritance relationship, determine the base class and derived class among multiple player data classes; wherein the derived class inherits from the base class; serialize the player data corresponding to the base class according to the serialization method indicated by the data type corresponding to the base class, and obtain the serialization result of the player data corresponding to the base class; and determine the serialization result of the player data corresponding to the derived class based on the serialization result of the player data corresponding to the base class.
[0078] Furthermore, the data serialization module 42 described above is also used to: for each derived class, perform the following operations: determine the base class corresponding to the current derived class; if the current derived class has target player data that is the same as the base class corresponding to the current derived class, determine the serialization result of the target player data corresponding to the base class of the current derived class as the serialization result of the target player data corresponding to the current derived class.
[0079] The player data serialization device provided in this embodiment of the invention has the same implementation principle and technical effect as the player data serialization method embodiment. For the sake of brevity, any parts not mentioned in the device embodiment can be referred to the corresponding content in the foregoing method embodiment.
[0080] This invention also provides an electronic device, such as... Figure 5 As shown, the electronic device includes a processor and a memory, the memory storing machine-executable instructions that can be executed by the processor, which executes the machine-executable instructions to implement the aforementioned player data serialization method.
[0081] Specifically, the above-mentioned player data serialization method includes: obtaining a player data class containing a preset keyword from a preset code file; determining the data type of the player data corresponding to the player data class based on the declaration of the preset keyword; wherein the data type is used to indicate the serialization method corresponding to the player data; and serializing the player data according to the serialization method indicated by the data type of the player data to obtain the serialization result of the player data.
[0082] The aforementioned player data serialization method marks player data classes with preset keywords in the code file, so that the player data class can be directly determined according to the preset keywords during the player data serialization stage, and only the player data class is serialized. This method does not require serializing all classes in the code file, which reduces the complexity of serialization operations and improves the efficiency of data serialization. At the same time, this method does not require manual screening of player data from the serialized data, saving labor costs.
[0083] In an optional embodiment, before the step of obtaining the player data class containing the preset keyword from the preset code file, the method further includes: marking the player data class with the preset keyword in the code file.
[0084] In an optional embodiment, the step of marking the player data class in the code file using a preset keyword includes: declaring the player data class in the code file using a preset keyword; wherein, the declaration of the preset keyword includes: the variable name, variable type, and access permissions corresponding to the player data class; the variable type is used to indicate the data type of the player data corresponding to the player data class.
[0085] In an optional embodiment, the step of determining the data type of player data corresponding to the player data class based on the declaration of preset keywords includes: obtaining the variable type from the declaration of preset keywords and determining the variable type as the data type of player data corresponding to the player data class.
[0086] In an optional embodiment, there are multiple player data classes containing preset keywords; the step of serializing the player data according to the serialization method indicated by the data type of the player data to obtain the serialization result of the player data includes: determining whether there is an inheritance relationship between the multiple player data classes; if there is no inheritance relationship, for each player data class, serializing the player data corresponding to the player data class according to the serialization method indicated by the data type of the player data class to obtain the serialization result of the player data corresponding to the player data class.
[0087] In an optional embodiment, the method further includes: if an inheritance relationship exists, determining the base class and derived class among multiple player data classes; wherein the derived class inherits from the base class; serializing the player data corresponding to the base class according to the serialization method indicated by the data type corresponding to the base class to obtain the serialization result of the player data corresponding to the base class; and determining the serialization result of the player data corresponding to the derived class based on the serialization result of the player data corresponding to the base class.
[0088] In an optional embodiment, the step of determining the serialization result of the player data corresponding to the derived class based on the serialization result of the player data corresponding to the base class includes: for each derived class, performing the following operations: determining the base class corresponding to the current derived class; if the current derived class corresponds to target player data that is the same as the base class corresponding to the current derived class, determining the serialization result of the target player data corresponding to the base class of the current derived class as the serialization result of the target player data corresponding to the current derived class.
[0089] Furthermore, Figure 5 The electronic device shown also includes a bus 102 and a communication interface 103, with the processor 101, the communication interface 103 and the memory 100 connected via the bus 102.
[0090] The memory 100 may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 103 (which can be wired or wireless), such as the Internet, wide area network, local area network, or metropolitan area network. The bus 102 may be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 5 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0091] Processor 101 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 101 or by instructions in software form. The processor 101 can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this invention can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor. The software module can reside in a readily available storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory 100, and processor 101 reads information from memory 100 and, in conjunction with its hardware, completes the steps of the method described in the foregoing embodiments.
[0092] This invention also provides a computer-readable storage medium storing computer-executable instructions. When these computer-executable instructions are called and executed by a processor, they cause the processor to implement the aforementioned player data serialization method. For specific implementation details, please refer to the method embodiments, which will not be repeated here.
[0093] Specifically, the above-mentioned player data serialization method includes: obtaining a player data class containing a preset keyword from a preset code file; determining the data type of the player data corresponding to the player data class based on the declaration of the preset keyword; wherein the data type is used to indicate the serialization method corresponding to the player data; and performing serialization processing on the player data according to the serialization method indicated by the data type of the player data to obtain the serialization result of the player data.
[0094] The aforementioned player data serialization method marks player data classes with preset keywords in the code file, so that the player data class can be directly determined according to the preset keywords during the player data serialization stage, and only the player data class is serialized. This method does not require serializing all classes in the code file, which reduces the complexity of serialization operations and improves the efficiency of data serialization. At the same time, this method does not require manual screening of player data from the serialized data, saving labor costs.
[0095] In an optional embodiment, before the step of obtaining the player data class containing the preset keyword from the preset code file, the method further includes: marking the player data class with the preset keyword in the code file.
[0096] In an optional embodiment, the step of marking the player data class in the code file using a preset keyword includes: declaring the player data class in the code file using a preset keyword; wherein, the declaration of the preset keyword includes: the variable name, variable type, and access permissions corresponding to the player data class; the variable type is used to indicate the data type of the player data corresponding to the player data class.
[0097] In an optional embodiment, the step of determining the data type of player data corresponding to the player data class based on the declaration of preset keywords includes: obtaining the variable type from the declaration of preset keywords and determining the variable type as the data type of player data corresponding to the player data class.
[0098] In an optional embodiment, there are multiple player data classes containing preset keywords; the step of serializing the player data according to the serialization method indicated by the data type of the player data to obtain the serialization result of the player data includes: determining whether there is an inheritance relationship between the multiple player data classes; if there is no inheritance relationship, for each player data class, serializing the player data corresponding to the player data class according to the serialization method indicated by the data type of the player data class to obtain the serialization result of the player data corresponding to the player data class.
[0099] In an optional embodiment, the method further includes: if an inheritance relationship exists, determining the base class and derived class among multiple player data classes; wherein the derived class inherits from the base class; serializing the player data corresponding to the base class according to the serialization method corresponding to the data type of the base class to obtain the serialization result of the player data corresponding to the base class; and determining the serialization result of the player data corresponding to the derived class based on the serialization result of the player data corresponding to the base class.
[0100] In an optional embodiment, the step of determining the serialization result of the player data class corresponding to the derived class based on the serialization result of the player data corresponding to the base class includes: for each derived class, performing the following operations: determining the base class corresponding to the current derived class; if the current derived class corresponds to target player data that is the same as the base class corresponding to the current derived class, determining the serialization result of the target player data corresponding to the base class of the current derived class as the serialization result of the target player data corresponding to the current derived class.
[0101] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a terminal device, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0102] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0103] Finally, it should be noted that the above-described embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for serializing player data, characterized in that, The method includes: From a pre-defined code file, obtain player data classes containing pre-defined keywords; wherein, only player data classes in the code file contain the pre-defined keywords, and the pre-defined keywords are used to declare the player data classes; the declaration of the pre-defined keywords includes: the variable name, variable type, and access permissions corresponding to the player data class; the variable type is used to indicate the data type of the player data corresponding to the player data class; Based on the declaration of the preset keywords, the data type of the player data corresponding to the player data class is determined; wherein, the data type is used to indicate the serialization method corresponding to the player data; The player data is serialized according to the serialization method indicated by the data type of the player data to obtain the serialization result of the player data.
2. The method according to claim 1, characterized in that, Before the step of retrieving the player data class containing the preset keywords from the preset code file, the method further includes: In the code file, the player data class is marked with the preset keyword.
3. The method according to claim 2, characterized in that, The step of marking the player data class using the preset keyword in the code file includes: In the code file, the player data class is declared using preset keywords.
4. The method according to claim 1, characterized in that, The step of determining the data type of player data corresponding to the player data class based on the declaration of the preset keyword includes: Obtain the variable type from the declaration of the preset keyword, and determine the variable type as the data type of the player data corresponding to the player data class.
5. The method according to claim 1, characterized in that, The player data class containing preset keywords is multiple; The step of serializing the player data according to the serialization method indicated by the data type of the player data to obtain the serialization result of the player data includes: Determine whether there is an inheritance relationship among the multiple player data classes; If there is no inheritance relationship, for each player data class, the player data corresponding to the player data class is serialized according to the serialization method indicated by the data type corresponding to the player data class, so as to obtain the serialization result of the player data corresponding to the player data class.
6. The method according to claim 5, characterized in that, The method further includes: If an inheritance relationship exists, determine the base class and derived class among the multiple player data classes; wherein the derived class inherits from the base class; Based on the serialization method indicated by the data type corresponding to the base class, the player data corresponding to the base class is serialized to obtain the serialization result of the player data corresponding to the base class; Based on the serialization result of the player data corresponding to the base class, the serialization result of the player data corresponding to the derived class is determined.
7. The method according to claim 6, characterized in that, The step of determining the serialization result of the player data corresponding to the derived class based on the serialization result of the player data corresponding to the base class includes: For each of the derived classes, perform the following operations: Determine the base class corresponding to the current derived class; If the current derived class corresponds to target player data that is the same as the base class corresponding to the current derived class, the serialization result of the target player data corresponding to the base class of the current derived class is determined as the serialization result of the target player data corresponding to the current derived class.
8. A player data serialization device, characterized in that, The device includes: A data class acquisition module is used to acquire player data classes containing preset keywords from a preset code file; wherein, only player data classes in the code file contain the preset keywords, and the preset keywords are used to declare the player data classes; the declaration of the preset keywords includes: the variable name, variable type, and access permissions corresponding to the player data class; the variable type is used to indicate the data type of the player data corresponding to the player data class; The data type determination module is used to determine the data type of the player data corresponding to the player data class based on the declaration of the preset keyword; wherein, the data type is used to indicate the serialization method corresponding to the player data; The data serialization module is used to serialize the player data according to the serialization method indicated by the data type of the player data, and obtain the serialization result of the player data.
9. An electronic device, characterized in that, It includes a processor and a memory, the memory storing machine-executable instructions that can be executed by the processor, the processor executing the machine-executable instructions to implement the player data serialization method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the player data serialization method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Target serialization achieving method and device
CN106648569A
Data serialization method and device
CN106777292A
Serialization and deserialization method, device and equipment
CN107451237A