Method for generating code describing remote procedure call, electronic device, medium and program product
Patent Information
- Application Number
- CN202280098061.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-29
- Publication Date
- 2025-03-14
AI Technical Summary
In the existing technology, users need to additionally define interface implementations when implementing remote procedure calls, resulting in cumbersome operations and limited flexibility.
By adding singleton code and decorator code to the business code written by the user, and using lexical and syntax analysis tools to analyze it, the code describing the remote procedure call is generated, thereby automatically defining the interface implementation and completely decoupling the remote procedure call framework and the business. code.
It enables users to quickly and automatically define interface implementations, provides greater flexibility and freedom in writing business code, allows users to define public rules from the bottom up, and supports efficient execution of low-level languages and hardware controllability.
Smart Images

Figure CN119631059A_ABST
Abstract
Description
Method, electronic device, medium and program product for generating code describing remote procedure call Technical Field
[0001] The embodiments of the present application mainly relate to the field of remote procedure calls, and in particular to a method, electronic device, medium, and program product for generating code describing a remote procedure call. Background Art
[0002] A remote procedure call (RPC) is the process by which one node requests a service from another remote node—in other words, the process of invoking a remote machine. This corresponds to a local procedure call, which aims to make calling remote methods as convenient as calling local methods. Although RPC defines a set of interface methods, currently, if users want to enable remote calls for a business function, they must not only define the business function itself but also the specific interface implementation. Clearly, this is cumbersome and restrictive in its current state.
[0003] Summary of the Invention
[0004] Embodiments of the present application provide a method, electronic device, medium, and program product for generating code describing a remote procedure call (RPC). These methods can help users quickly and automatically define corresponding interface implementations, thereby establishing a remote procedure call. By completely decoupling the RPC framework from the service code, users are given greater flexibility when writing service code.
[0005] In a first aspect, a method for generating code describing a remote procedure call is provided, comprising: marking the code for a specified function in a business code written by a user through a singleton code to obtain a first code; marking the code for the specified function in the business code written by the user through a decorator code to obtain a second code; parsing the first code and the second code through a specified lexical and syntax analysis tool; and generating code describing a remote procedure call.
[0006] In a second aspect, an electronic device is provided, comprising: at least one memory configured to store computer-readable code; and at least one processor configured to call the computer-readable code and execute each step of the method provided in the first aspect.
[0007] According to a third aspect, a computer-readable medium is provided, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor, the processor executes the steps of the method provided in the first aspect.
[0008] In a fourth aspect, a computer program product is provided, which is tangibly stored on a computer-readable medium and includes computer-readable instructions, which, when executed, cause at least one processor to perform the steps of the method provided in the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] The following figures are intended only to illustrate and explain the embodiments of the present application and are not intended to limit the scope of the embodiments of the present application.
[0010] FIG1 is a flowchart of a method for generating code describing a remote procedure call according to an embodiment of the present application;
[0011] FIG2 is a schematic diagram of an electronic device according to an embodiment of the present application.
[0012] Description of Reference Numerals
[0013] 100: Method for generating code describing remote procedure calls 101-105: Method steps
[0014] 200: Electronic device 201: Memory 202: Processor DETAILED DESCRIPTION
[0015] The subject matter described herein will now be discussed with reference to example embodiments. It should be understood that discussing these embodiments is merely to enable those skilled in the art to better understand and implement the subject matter described herein, and is not intended to limit the scope of protection, applicability, or examples set forth in the claims. The functions and arrangements of the elements discussed may be changed without departing from the scope of protection of the embodiments of the present application. Various examples may omit, replace, or add various processes or components as needed. For example, the described method may be performed in an order different from the described order, and various steps may be added, omitted, or combined. In addition, the features described relative to some examples may also be combined in other examples.
[0016] As used herein, the term "including" and its variations are open terms meaning "including but not limited to". The term "based on" means "based at least in part on". The terms "one embodiment" and "an embodiment" mean "at least one embodiment". The term "another embodiment" means "at least one other embodiment". The terms "first", "second", etc. may refer to different or the same objects. Other definitions may be included below, whether explicit or implicit. Unless the context clearly indicates otherwise, the definition of a term is consistent throughout the specification.
[0017] The embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0018] FIG1 is a flow chart of a method for generating code describing a remote procedure call according to an embodiment of the present application. As shown in FIG1 , the method 100 for generating code describing a remote procedure call includes:
[0019] Step 101: Mark the code of the specified function in the business code written by the user through the singleton code to obtain the first code.
[0020] Singleton code not only allows users to identify business functions that they plan to expose via RPC, but also allows them to instantiate the code for the corresponding business function. Singleton code ensures that a class in the business function code has only one instance and provides a global access point to it.
[0021] Step 102: Mark the code of the specified function in the business code written by the user through the decorator code to obtain the second code.
[0022] Decorator code is a new modern programming method, aspect-oriented programming, which belongs to high-level languages. Optionally, the code can be marked by adding a tag such as "@public" before the code of the specified function.
[0023] Step 103: parse the first code and the second code using a designated lexical and grammatical analysis tool.
[0024] The designated lexical and grammatical analysis tool may be, for example, Flex&Bison or Antlr4, which includes customized grammatical rules for singleton code and lexical and grammatical rules for decorator code.
[0025] Optionally, before parsing the first code and the second code, an inference engine is used to check the lexical structure and grammar of the first code and the second code, respectively. If there are errors in the lexical structure and grammar of the first code or the second code, the corresponding errors are corrected according to preset lexical structure and grammar error correction rules.
[0026] Step 104: Generate code describing the remote procedure call.
[0027] Generate code describing the remote procedure call using semantic communication rules. Optionally, the semantic communication rules include: fieldbus communication rules, databus communication rules, or point-to-point communication rules. Optionally, the semantic communication rules include: DDS, MQTT, HTTP, or ModBus.
[0028] Optionally, after generating the code describing the remote procedure call, the business code, the first code and the code describing the remote procedure call are compiled and linked in the metaprogramming framework through the specified lexical and grammatical analysis tools, and the target code that can be run on the general platform is output. Optionally, the business code, the first code, the second code and the code describing the remote procedure call can also be compiled and linked in the metaprogramming framework, and the target code that can be run on the general platform is output. Among them, compilation refers to translating the source code into target code in a binary format that can be recognized by the computer. Linking refers to combining all related target files and system components into an executable file, that is, a "packaging" process. Optionally, the general platform refers to, for example, an ARM architecture or an X86 architecture.
[0029] The embodiment of the present application is directed to the code of the specified function in the business code written by the user, and singleton code and decorator code are added respectively, parsed by the specified lexical and grammatical analysis tools, and the code describing the remote procedure call is regenerated. Finally, after compiling and linking the relevant code, the target code that can be run on the general platform is obtained. If the target code is run, the interface can be exposed. The embodiment of the present application provides a friendly application development framework for an open ecosystem, which can realize the complete decoupling of the remote procedure call framework and the business code, provides the user with more flexibility when writing business code, and allows the user to define public rules from the bottom up. The user can use low-level languages such as C / C++ to write business code in the code editor in the application (APP) integrated development environment (integrated development environment, IDE), that is, the language type that the user can choose to write business code is freer. The execution efficiency of low-level languages is high and the controllability to hardware is stronger, and some business codes must be written in low-level languages due to the limitations of the corresponding interfaces.
[0030] The present application also provides an electronic device 200. FIG2 is a schematic diagram of an electronic device 200 according to an embodiment of the present application. As shown in FIG2 , the electronic device 200 includes a processor 202 and a memory 201. The memory 201 stores instructions, wherein the instructions, when executed by the processor 202, implement the method 100 described above.
[0031] Among them, at least one processor 202 may include a microprocessor, an application-specific integrated circuit (ASIC), a digital signal processor (DSP), a central processing unit (CPU), a graphics processing unit (GPU), a state machine, etc. Embodiments of computer-readable media include, but are not limited to, floppy disks, CD-ROMs, magnetic disks, memory chips, ROMs, RAMs, ASICs, configured processors, all-optical media, all tapes or other magnetic media, or any other medium from which a computer processor can read instructions. In addition, various other forms of computer-readable media can send or carry instructions to a computer, including routers, private or public networks, or other wired and wireless transmission devices or channels. Instructions may include code in any computer programming language, including C, C++, C language, Visual Basic, Java, and JavaScript.
[0032] In addition, an embodiment of the present application further provides a computer-readable medium having computer-readable instructions stored thereon, and when the computer-readable instructions are executed by a processor, the processor executes the aforementioned method 100 for generating a code describing a remote procedure call. Embodiments of computer-readable media include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), magnetic tapes, non-volatile memory cards, and ROMs. Optionally, the computer-readable instructions can be downloaded from a server computer or a cloud via a communication network. In addition, an embodiment of the present application further provides a computer program product, which is tangibly stored on a computer-readable medium and includes computer-readable instructions, which, when executed, cause at least one processor to execute the steps in the method 100 for generating a code describing a remote procedure call in an embodiment of the present application.
[0033] It should be noted that not all steps and modules in the above processes and system structure diagrams are required, and certain steps or modules can be omitted according to actual needs. The execution order of each step is not fixed and can be adjusted as needed. The system structure described in the above embodiments can be a physical structure or a logical structure, that is, some modules may be implemented by the same physical entity, or some modules may be implemented by multiple physical entities, or may be implemented by certain components in multiple independent devices.
Claims
1. A method for generating code describing a remote procedure call, comprising: -Mark the code of the specified function in the business code written by the user through the singleton code (101) to obtain the first code; - The code of the specified function in the business code written by the user is marked by the decorator code (102) to obtain a second code; - parsing the first code and the second code using a designated lexical and grammatical analysis tool (103); -Generate (104) code describing a remote procedure call.
2. The method according to claim 1, characterized in that After generating (104) the code describing the remote procedure call, the method further comprises: - using the specified lexical and grammatical analysis tools, compiling and linking the business code, the first code, and the code describing the remote procedure call in a metaprogramming framework; - Output target code that can be run on common platforms.
3. The method according to claim 1, characterized in that Before parsing the first code and the second code (103), the method further includes: - using an inference engine to check the lexical structure and grammar of the first code and the second code respectively; -When there are errors in the lexical and grammatical aspects of the first code or the second code, correct the corresponding errors according to preset lexical and grammatical error correction rules.
4. The method according to claim 1, wherein The code for generating (104) a description of a remote procedure call comprises: -Generate code describing remote procedure calls through rules of semantic communication.
5. The method according to claim 4, characterized in that The semantic communication rules include: field bus communication rules, data bus communication rules or point-to-point communication rules.
6. The method according to claim 4, characterized in that The semantic communication rules include: DDS, MQTT, HTTP or ModBus.
7. An electronic device, characterized in that: include: at least one memory (201) configured to store computer-readable code; At least one processor (202) is configured to call the computer-readable code to execute the steps in the method according to any one of claims 1 to 6.
8. [Corrected 16.09.2022 according to Rule 91] A computer-readable medium, characterized in that The computer-readable medium stores computer-readable instructions, which, when executed by a processor, cause the processor to perform the steps of the method according to any one of claims 1 to 6.
9. [Corrected 16.09.2022 in accordance with Rule 91] A computer program product, characterized in that The computer program product is tangibly stored on a computer-readable medium and comprises computer-readable instructions which, when executed, cause at least one processor to perform the steps of the method according to any one of claims 1 to 6.