Protocol dynamic adaptation method, device, electronic device and storage medium

By dynamically building and verifying the memory layout of the protocol structure and performing variable conversion under consistent conditions, the problem of low data analysis efficiency in complex protocol scenarios is solved, and efficient data analysis and conversion is achieved.

CN117278648BActive Publication Date: 2025-02-21GUANGZHOU BAOLUN ELECTRONICS CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202311232096.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-21
Publication Date
2025-02-21
Estimated Expiration
2043-09-21

AI Technical Summary

Technical Problem

In complex protocol scenarios, data parsing efficiency is low, especially the memory layout inconsistent due to inconsistent protocol length and data type per frame, which affects variable conversion and data parsing.

Method used

By obtaining the structure type information of the variable to be converted, dynamically build a dynamic protocol structure and determine whether its memory layout is consistent. In the case of consistency, run the target conversion function to convert the variable to the target conversion variable.

Benefits of technology

It realizes efficient data parsing under dynamic changes in the protocol, improves data parsing efficiency, and avoids data conversion errors and memory losses caused by inconsistent memory layout.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117278648B_ABST
    Figure CN117278648B_ABST
Patent Text Reader

Abstract

The present invention discloses a protocol dynamic adaptation method, device, electronic device and storage medium. The method includes: obtaining the structure type information of the variable to be converted; dynamically constructing a dynamic protocol structure based on the structure type information of the variable to be converted; determining whether the memory layout of the variable to be converted and the target conversion variable under the dynamic protocol structure are consistent; and running the target conversion function when the memory layout of the variable to be converted and the target conversion variable under the dynamic protocol structure are consistent, wherein the target conversion function is used to convert the variable to be converted into the target conversion variable. The above technical solution realizes efficient data parsing under the condition of dynamic changes in the protocol and improves the data parsing efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a protocol dynamic adaptation method, device, electronic equipment and storage medium. Background Art

[0002] C# language, also known as CSharp, is a general-purpose, object-oriented programming language developed by Microsoft Corporation and has a key component of Common Language Runtime (CLR), which can implement automatic memory management.

[0003] Currently, in complex protocol scenarios, such as inconsistent protocol length and data type for each frame, there is a problem of low data parsing efficiency. Summary of the invention

[0004] The present invention provides a protocol dynamic adaptation method, device, electronic equipment and storage medium to improve data parsing efficiency.

[0005] According to one aspect of the present invention, a protocol dynamic adaptation method is provided, comprising:

[0006] Get the structure type information of the variable to be converted;

[0007] Dynamically construct a dynamic protocol structure based on the structure type information of the variable to be converted;

[0008] Determine whether the memory layout of the variable to be converted and the target conversion variable under the dynamic protocol structure are consistent;

[0009] When the memory layout of the variable to be converted is consistent with the target conversion variable under the dynamic protocol structure, a target conversion function is run, wherein the target conversion function is used to convert the variable to be converted into a target conversion variable.

[0010] According to another aspect of the present invention, there is provided a protocol dynamic adaptation device, comprising:

[0011] The structure type acquisition module is used to obtain the structure type information of the variable to be converted;

[0012] A dynamic protocol structure building module, used to dynamically build a dynamic protocol structure based on the structure type information of the variable to be converted;

[0013] A memory layout consistency determination module, used to determine whether the memory layout of the variable to be converted and the target conversion variable under the dynamic protocol structure are consistent;

[0014] The variable conversion module is used to run the target conversion function when the memory layout of the variable to be converted is consistent with the target conversion variable under the dynamic protocol structure, wherein the target conversion function is used to convert the variable to be converted into the target conversion variable.

[0015] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:

[0016] at least one processor;

[0017] and a memory communicatively coupled to the at least one processor;

[0018] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the protocol dynamic adaptation method described in any embodiment of the present invention.

[0019] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the protocol dynamic adaptation method described in any embodiment of the present invention when executed.

[0020] The technical solution of the embodiment of the present invention realizes the real-time construction of the dynamic protocol structure by constructing a dynamic protocol structure according to the structure type information of the variable to be converted, and then allocates the dynamic protocol structure to the memory space, and determines whether the memory layout of the variable to be converted and the target conversion variable under the dynamic protocol structure are consistent; when the memory layout of the variable to be converted and the target conversion variable under the dynamic protocol structure are consistent, the variable to be converted is converted into the target conversion variable through the target conversion function, thereby realizing efficient data parsing under the dynamic change of the protocol and improving the data parsing efficiency.

[0021] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0023] Figure 1 is a flowchart of a protocol dynamic adaptation method provided according to Embodiment 1 of the present invention;

[0024] Figure 2 is a flowchart of a protocol dynamic adaptation method provided according to Embodiment 2 of the present invention;

[0025] Figure 3 A schematic diagram of a flow chart of another protocol dynamic adaptation method provided by an embodiment of the present invention;

[0026] Figure 4 is a structural diagram of a protocol dynamic adaptation device provided according to Embodiment 4 of the present invention;

[0027] Figure 5 It is a structural schematic diagram of an electronic device for implementing the protocol dynamic adaptation method of an embodiment of the present invention. DETAILED DESCRIPTION

[0028] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0029] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0030] At present, in complex protocol scenarios, the data protocol conversion method based on memory layout may cause variable conversion to be blocked due to the inconsistency of the target conversion variables in the memory layout. In serious cases, the data conversion result may not be consistent with the original data. The data protocol conversion method based on the preset data format to splice data with a specified string length has a memory loss problem, which may greatly increase the data parsing time and reduce the timeliness of data transmission.

[0031] To this end, the embodiment of the present disclosure provides a protocol dynamic adaptation method, which realizes real-time construction of the dynamic protocol structure by constructing a dynamic protocol structure according to the structure type information of the variable to be converted, and then allocates the dynamic protocol structure to the memory space, and determines whether the memory layout of the variable to be converted and the target conversion variable under the dynamic protocol structure are consistent; when the memory layout of the variable to be converted and the target conversion variable under the dynamic protocol structure are consistent, the variable to be converted is converted into the target conversion variable through the target conversion function, thereby realizing efficient data parsing under the dynamic change of the protocol and improving the data parsing efficiency.

[0032] Embodiment 1

[0033] Figure 1 This is a flowchart of a protocol dynamic adaptation method provided in the first embodiment of the present invention. This embodiment is applicable to the case of dynamic protocol parsing based on memory layout. The method can be executed by a protocol dynamic adaptation device. The protocol dynamic adaptation device can be implemented in the form of hardware and / or software. The protocol dynamic adaptation device can be configured in electronic devices such as computer terminals. Figure 1 As shown, the method includes:

[0034] S110. Obtain structure type information of the variable to be converted.

[0035] Among them, the structure type is a type of data structure, and the structure type may include several data items of the same or different types. The variables to be converted and the target conversion variables in the embodiments of the present disclosure are both structure types. The variable to be converted refers to a structure variable that needs to be converted, for example, a structure variable that contains other structures or its own structure variables. The target conversion variable is the structure variable after the variable to be converted is converted.

[0036] In the disclosed embodiment, the structure type information of one or more variables to be converted can be obtained from a remote device, wherein the remote device can be a device that is connected to the current electronic device for communication, and the data transmission between the two complies with a preset communication protocol, for example, the remote device can be an audio acquisition device, etc. Exemplarily, the variable to be converted can be Student, and its corresponding structure type information can include fields such as Id, Name, Gender, and Score, and the field types corresponding to each field, namely Int32, String, Char, and Float. The variable to be converted can also be Teacher, and its corresponding structure type information can include fields such as Id, Name, Age, and Salary, and the field types corresponding to each field, namely Int32, String, Int32, and Double. The number of bytes occupied by different field types in memory can be different, such as String type occupies 4 bytes, Int32 type occupies 4 bytes, Char type occupies 2 bytes, Float type occupies 4 bytes, and Double type occupies 8 bytes.

[0037] S120: Dynamically construct a dynamic protocol structure based on the structure type information of the variable to be converted.

[0038] In the disclosed embodiment, the memory layout, protocol structure data type, fields, etc. of the protocol structure can be defined according to the structure type information of the variable to be converted, thereby completing the real-time construction of the dynamic protocol structure.

[0039] S130: Determine whether the memory layout of the variable to be converted and the target conversion variable under the dynamic protocol structure are consistent.

[0040] The memory layout refers to the arrangement of a variable in the memory. Specifically, the memory layout of the variable to be converted and the target conversion variable is a byte string with a certain length.

[0041] In the disclosed embodiment, whether the memory layout is consistent can be determined based on the field type and field order of the variable to be converted and the target conversion variable under the dynamic protocol structure. Specifically, if the field type and field order of the variable to be converted and the target conversion variable are completely consistent, it means that the memory layout of the variable to be converted and the target conversion variable are consistent. If the field type and field order of the variable to be converted and the target conversion variable are inconsistent, it means that the memory layout of the variable to be converted and the target conversion variable are inconsistent.

[0042] Specifically, first determine the first field in the data structure of Student, such as the Id field, where the first field can be any field in the data structure of Student, and then determine the second field in the data structure of the target conversion variable that is in a corresponding position with the first field in the data structure of Student, such as the Id field, and determine whether the field types of the first field and the second field are the same. After traversing all the fields in the data structure of Student in the above manner, determine whether the field types of the corresponding fields of the two are the same. If it is determined that the field types of each field in the data structure of Student and the target conversion variable and the order of each field type are the same, then determine that the memory layout of the Student type variable is consistent with that of the target conversion variable.

[0043] S140. When the memory layout of the variable to be converted is consistent with the target conversion variable under the dynamic protocol structure, run the target conversion function, wherein the target conversion function is used to convert the variable to be converted into the target conversion variable.

[0044] In the disclosed embodiment, the target conversion function can automatically convert the variable to be converted into the target conversion variable to complete the layout of the instance under the current dynamic protocol structure.

[0045] Optionally, the method further includes: receiving a protocol change instruction sent by a remote device, and updating the dynamic protocol structure based on the protocol change instruction.

[0046] It should be noted that after the remote device modifies the communication protocol, it can send a protocol change instruction to the current electronic device. After receiving the protocol change instruction sent by the remote device, the current electronic device triggers the dynamic protocol structure update program to generate a new dynamic protocol structure to realize dynamic parsing of the protocol.

[0047] Optionally, the method further includes: when the dynamic protocol structure is inconsistent with the memory layout of the variable to be converted, returning to S110 to obtain the structure type information of the next variable to be converted.

[0048] The technical solution of the embodiment of the present invention realizes the real-time construction of the dynamic protocol structure by constructing a dynamic protocol structure according to the structure type information of the variable to be converted, and then allocates the dynamic protocol structure to the memory space, and determines whether the memory layout of the variable to be converted and the target conversion variable under the dynamic protocol structure are consistent; when the memory layout of the variable to be converted and the target conversion variable under the dynamic protocol structure are consistent, the variable to be converted is converted into the target conversion variable through the target conversion function, thereby realizing efficient data parsing under the dynamic change of the protocol and improving the data parsing efficiency.

[0049] Embodiment 2

[0050] Figure 2 A flowchart of a protocol dynamic adaptation method provided for Embodiment 2 of the present invention, the method of this embodiment can be combined with the various optional schemes in the protocol dynamic adaptation method provided in the above embodiments. The protocol dynamic adaptation method provided in this embodiment is further optimized. Optionally, a dynamic protocol structure is dynamically constructed based on the structure type information of the variable to be converted, including: creating a dynamic type of the variable to be converted based on a first preset function; defining a memory layout and structure fields of the dynamic type based on the structure type information of the variable to be converted; inputting the memory layout and structure fields of the dynamic type into a second preset function to obtain a dynamic protocol structure.

[0051] like Figure 2 As shown, the method includes:

[0052] S210. Obtain structure type information of the variable to be converted.

[0053] S220: Create a dynamic type of the variable to be converted based on a first preset function.

[0054] The first preset function refers to a function that creates a dynamic type of variable to be converted.

[0055] Exemplarily, the first preset function may be a ModuleBuilder.DefineType() function. Specifically, a dynamic assembly or module may be created according to the ModuleBuilder.DefineType() function, thereby automatically creating the dynamic type of the variable to be converted through the dynamic assembly or module.

[0056] S230: Define the memory layout and structure fields of the dynamic type based on the structure type information of the variable to be converted.

[0057] Exemplarily, the memory layout of the dynamic type of the variable to be converted may be defined according to the structure type information of the variable to be converted; and the structure field may be dynamically constructed according to the dynamic type of the variable to be converted.

[0058] S240: Input the memory layout and structure fields of the dynamic type into a second preset function to obtain a dynamic protocol structure.

[0059] The second preset function refers to a function for completing the construction of a dynamic protocol structure, and cooperates with the first preset function to jointly complete the construction of a dynamic protocol structure.

[0060] Exemplarily, the second preset function may be a TypeBuilder.CreateType() function. Specifically, the memory layout and structure fields of the dynamic type may be input into the TypeBuilder.CreateType() function, thereby completing the construction of the dynamic protocol structure.

[0061] S250: Determine whether the memory layout of the variable to be converted and the target conversion variable under the dynamic protocol structure are consistent.

[0062] S260. When the memory layout of the variable to be converted is consistent with the target conversion variable under the dynamic protocol structure, run the target conversion function, wherein the target conversion function is used to convert the variable to be converted into the target conversion variable.

[0063] Optionally, determining whether the memory layout of the variable to be converted and the target conversion variable under the dynamic protocol structure are consistent includes: allocating the dynamic protocol structure to the memory space according to the number of fields, field type and field order; if the number of fields, field type and field order of the variable to be converted and the target conversion variable are exactly the same, then determining that the memory layout of the variable to be converted and the target conversion variable are consistent.

[0064] In order to improve the efficiency of memory layout consistency judgment of the variable to be converted and the target conversion variable under the dynamic protocol structure, the disclosed embodiment can first determine whether the number of fields respectively included in the data structure of the variable to be converted and the target conversion variable is the same. If the number of fields included in the two is not the same, it means that the memory layout of the two is inconsistent. At this time, the process can exit and report an error. If it is determined that the number of fields respectively included in the data structure of the variable to be converted and the target conversion variable is the same, then determine whether the field type of each field in the data structure of the variable to be converted and the target conversion variable and the order between the field types are the same. If they are the same, the memory layout is consistent, otherwise the memory layout is inconsistent.

[0065] Exemplarily, the data structure of the variable A to be converted may include 10 fields, and the data structure of the target conversion variable B may include 20 fields. Since the number of fields included in the data structure of A is inconsistent with the number of fields included in the data structure of B, it can be determined that the memory layout of A and B is inconsistent.

[0066] Based on the contents of the above embodiments, the present disclosure also provides a protocol dynamic adaptation method. Figure 3A flowchart of another protocol dynamic adaptation method provided by an embodiment of the present disclosure. Specifically, the structure type information of multiple variables to be converted is obtained from a remote device, such as two variables to be converted, Student and Teacher; further, the dynamic types of Student and Teacher can be created according to the ModuleBuilder.DefineType() function, and then the memory layout of the dynamic types of Student and Teacher can be defined according to the structure type information of the variables to be converted; and according to the dynamic types of Student and Teacher, the structure fields are dynamically constructed, and the construction of the dynamic protocol structure is completed using the TypeBuilder.CreateType() function. Furthermore, based on the Marshal feature, the constructed dynamic protocol structure is allocated to the memory space according to the number of fields, field types and order definitions of the fields. If the number of fields, field types and field order of the variables to be converted and the target conversion variables under the dynamic protocol structure are exactly the same, then the memory layout of the variables to be converted and the target conversion variables is determined to be consistent, and Student and Teacher are input into the target conversion function to obtain the target conversion variables corresponding to Student and the target conversion variables corresponding to Teacher, thereby realizing efficient data parsing in complex protocol scenarios; if the number of fields, field types and field order of the variables to be converted and the target conversion variables are inconsistent, then the memory layout of the variables to be converted and the target conversion variables is determined to be inconsistent, and the protocol structure type of the next variable to be converted is re-obtained to construct the dynamic protocol structure, and then the data parsing continues.

[0067] The technical solution of the embodiment of the present invention creates the dynamic type of the variable to be converted through a first preset function, and then defines the memory layout and structure fields of the dynamic type according to the structure type information of the variable to be converted, and then inputs the memory layout and structure fields of the dynamic type into a second preset function to obtain a dynamic protocol structure, thereby realizing real-time construction of the dynamic protocol structure.

[0068] Embodiment 3

[0069] Figure 4 This is a schematic diagram of the structure of a protocol dynamic adaptation device provided in Embodiment 3 of the present invention. Figure 4 As shown, the device comprises:

[0070] The structure type acquisition module 310 is used to obtain the structure type information of the variable to be converted;

[0071] A dynamic protocol structure building module 320, used to dynamically build a dynamic protocol structure based on the structure type information of the variable to be converted;

[0072] A memory layout consistency determination module 330 is used to determine whether the memory layout of the variable to be converted and the target conversion variable under the dynamic protocol structure are consistent;

[0073] The variable conversion module 340 is used to run the target conversion function when the memory layout of the variable to be converted is consistent with the target conversion variable under the dynamic protocol structure, wherein the target conversion function is used to convert the variable to be converted into the target conversion variable.

[0074] The technical solution of the embodiment of the present invention realizes the real-time construction of the dynamic protocol structure by constructing a dynamic protocol structure according to the structure type information of the variable to be converted, and then allocates the dynamic protocol structure to the memory space, and determines whether the memory layout of the variable to be converted and the target conversion variable under the dynamic protocol structure are consistent; when the memory layout of the variable to be converted and the target conversion variable under the dynamic protocol structure are consistent, the variable to be converted is converted into the target conversion variable through the target conversion function, thereby realizing efficient data parsing under the dynamic change of the protocol and improving the data parsing efficiency.

[0075] In some optional implementations, the structure type acquisition module 310 is specifically used to:

[0076] Get the structure type information of the variable to be converted from the remote device.

[0077] In some optional implementations, the dynamic protocol structure building module 320 is specifically used to:

[0078] Creating a dynamic type of the variable to be converted based on a first preset function;

[0079] Defining the memory layout and structure fields of the dynamic type based on the structure type information of the variable to be converted;

[0080] The memory layout and structure fields of the dynamic type are input into a second preset function to obtain a dynamic protocol structure.

[0081] In some optional implementations, the first preset function is the ModuleBuilder.DefineType() function; the second preset function is the TypeBuilder.CreateType() function.

[0082] In some optional implementations, the memory layout consistency determination module 330 is specifically used to:

[0083] Allocating the dynamic protocol structure into memory space according to the number of fields, field types and field order;

[0084] If the number of fields, field types and field orders of the variable to be converted and the target conversion variable are completely the same, it is determined that the memory layout of the variable to be converted is consistent with that of the target conversion variable.

[0085] In some optional implementations, the protocol dynamic adaptation device further includes:

[0086] The dynamic protocol structure updating module is used to receive a protocol change instruction sent by a remote device and update the dynamic protocol structure based on the protocol change instruction.

[0087] In some optional implementations, the protocol dynamic adaptation device further includes:

[0088] The variable to be converted re-acquisition module is used for the dynamic protocol structure update module, and is used to obtain the structure type information of the next variable to be converted when the memory layout of the dynamic protocol structure is inconsistent with that of the variable to be converted.

[0089] The protocol dynamic adaptation device provided in the embodiment of the present invention can execute the protocol dynamic adaptation method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0090] Embodiment 4

[0091] Figure 5 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0092] like Figure 5As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. The I / O interface 15 is also connected to the bus 14.

[0093] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0094] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The processor 11 performs the various methods and processes described above, such as a protocol dynamic adaptation method, which includes:

[0095] Get the structure type information of the variable to be converted;

[0096] Dynamically construct a dynamic protocol structure based on the structure type information of the variable to be converted;

[0097] Determine whether the memory layout of the variable to be converted and the target conversion variable under the dynamic protocol structure are consistent;

[0098] When the memory layout of the variable to be converted is consistent with the target conversion variable under the dynamic protocol structure, a target conversion function is run, wherein the target conversion function is used to convert the variable to be converted into a target conversion variable.

[0099] In some embodiments, the protocol dynamic adaptation method can be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the protocol dynamic adaptation method described above can be performed. Alternatively, in other embodiments, the processor 11 can be configured to perform the protocol dynamic adaptation method in any other appropriate manner (for example, by means of firmware).

[0100] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0101] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0102] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0103] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0104] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0105] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

[0106] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

[0107] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A protocol dynamic adaptation method, characterized in that: Applicable to dynamic parsing of protocols based on memory layout of C# language, including: Obtain the structure type information of the variables to be converted from the audio acquisition device. The variables to be converted include Student and Teacher. The structure type information corresponding to Student includes the fields Id, Name, Gender, and Score, and the field types corresponding to each field: Int32, String, Char, and Float; The structure type information corresponding to Teacher includes the Id, Name, Age, and Salary fields and the field types corresponding to each field: Int32, String, Int32, and Double; Among them, the String type occupies 4 bytes, the Int32 type occupies 4 bytes, the Char type occupies 2 bytes, the Float type occupies 4 bytes, and the Double type occupies 8 bytes; Create the dynamic types of Student and Teacher according to the ModuleBuilder.DefineType() function, and define the memory layout of the dynamic types of Student and Teacher according to the structure type information of Student and Teacher; dynamically build the structure fields according to the dynamic types of Student and Teacher, and input the memory layout and structure fields of the dynamic type into the TypeBuilder.CreateType() function to complete the construction of the dynamic protocol structure; Based on the Marshal feature, the constructed dynamic protocol structure is allocated to the memory space according to the number of fields, field types and order of the field types of the structure fields. If the number of fields, field types and field order of the variables to be converted and the target conversion variables under the dynamic protocol structure are completely consistent, it is determined that the memory layout of the variables to be converted and the target conversion variables is consistent; Input Student and Teacher into the target conversion function to obtain the target conversion variable corresponding to Student and the target conversion variable corresponding to Teacher; If the number of fields, field type and field order of the variable to be converted are inconsistent with the target conversion variable, it is determined that the memory layout of the variable to be converted is inconsistent with the target conversion variable, and the protocol structure type of the next variable to be converted is re-acquired to construct a dynamic protocol structure, and data parsing continues; The method further comprises: A protocol change instruction sent by an audio acquisition device is received, and the dynamic protocol structure is updated based on the protocol change instruction.

2. A protocol dynamic adaptation device, characterized in that: Applicable to dynamic parsing of protocols based on memory layout of C# language, including: The structure type acquisition module is used to obtain the structure type information of the variables to be converted from the audio acquisition device. The variables to be converted include Student and Teacher. The structure type information corresponding to Student includes the fields Id, Name, Gender, and Score, and the field types corresponding to each field: Int32, String, Char, and Float; The structure type information corresponding to Teacher includes the Id, Name, Age, and Salary fields and the field types corresponding to each field: Int32, String, Int32, and Double; Among them, the String type occupies 4 bytes, the Int32 type occupies 4 bytes, the Char type occupies 2 bytes, the Float type occupies 4 bytes, and the Double type occupies 8 bytes; The dynamic protocol structure building module is used to create the dynamic types of Student and Teacher according to the ModuleBuilder.DefineType() function, and define the memory layout of the dynamic types of Student and Teacher according to the structure type information of Student and Teacher; dynamically build the structure fields according to the dynamic types of Student and Teacher, and input the memory layout and structure fields of the dynamic type into the TypeBuilder.CreateType() function to complete the construction of the dynamic protocol structure; A memory layout consistency determination module is used to allocate the constructed dynamic protocol structure to the memory space according to the number of fields, field types and order definitions of the structure fields based on the Marshal feature. If the number of fields, field types and field order of the variables to be converted and the target conversion variables under the dynamic protocol structure are completely consistent, it is determined that the memory layout of the variables to be converted is consistent with that of the target conversion variables; The variable conversion module is used to input Student and Teacher into the target conversion function to obtain the target conversion variable corresponding to Student and the target conversion variable corresponding to Teacher; The module for re-obtaining variables to be converted is used to determine that the memory layout of the variable to be converted is inconsistent with that of the target conversion variable if the number of fields, field type and field order of the variable to be converted are inconsistent with those of the target conversion variable, and to re-obtain the protocol structure type of the next variable to be converted to construct a dynamic protocol structure and continue data parsing; The dynamic protocol structure updating module is used to receive the protocol change instruction sent by the audio acquisition device and update the dynamic protocol structure based on the protocol change instruction.

3. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively coupled to the at least one processor; The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the protocol dynamic adaptation method described in claim 1.

4. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the protocol dynamic adaptation method described in claim 1 when executed.

Citation Information

Patent Citations

  • Type conversion method and device, equipment and storage medium

    CN114756240A