Interface code generation and maintenance method and device, equipment and medium

By automatically generating C++ interface code using JSON configuration files, the inefficiency and consistency issues of property management in C++ software development are resolved, and automated interface code generation and persistent storage are achieved.

CN122064338APending Publication Date: 2026-05-19HANGZHOU MAITANG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HANGZHOU MAITANG TECH CO LTD
Filing Date
2026-02-27
Publication Date
2026-05-19

AI Technical Summary

Technical Problem

In C++ software development, property management requires manually writing Get/Set interfaces. In particular, the lack of automation for composite types and notification mechanisms leads to low development efficiency, error-proneness, and inconsistent code.

Method used

Attribute information is defined through JSON configuration files, and the interface code is automatically generated using a template engine, including attribute read/write interfaces and notification callback mechanisms. Automated persistence is achieved by combining MMKV storage.

Benefits of technology

It achieves automated generation of interface code, reduces manual coding work, improves development efficiency, eliminates type errors and omissions, and ensures code consistency and standardization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122064338A_ABST
    Figure CN122064338A_ABST
Patent Text Reader

Abstract

The invention discloses an interface code generation and maintenance method and device, equipment and a medium, and relates to the field of software codes, and the interface code generation and maintenance method comprises the steps that after environment verification and resource loading are completed, legality verification is conducted on all attribute configuration JSON files, and after verification succeeds, text content of the attribute configuration JSON files is read; extracting a target field of a root node of the attribute configuration JSON file according to the text information, obtaining attribute information based on the target field, and generating a target interface code based on the attribute information and the template file; creating a callback management container for the target attribute needing to be notified, and generating a public interface corresponding to the target attribute, so as to add or remove a callback function in the callback management container of the target attribute through the public interface; and when the target attribute is changed, traversing and executing the callback function in the callback management container at the public interface according to the target sequence so as to complete the attribute change notification. Therefore, the code can be automatically generated, and the maintenance cost is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of software code, and in particular to a method, apparatus, device, and medium for generating and maintaining interface code. Background Technology

[0002] In C++ software development, the management of properties (such as configuration parameters, state variables, etc.) is a core aspect. It is usually necessary to implement property reading (Get) and setting (Set) interfaces to support access by external components. In some scenarios, it is also necessary to notify related modules when properties change (such as UI (User Interface) refresh, business logic triggering).

[0003] Property interface generation: In the traditional way, developers need to manually write Get / Set functions for each property, which involves logic such as data type validation and storage interaction (such as memory variables or persistent storage); for composite types such as arrays and dictionaries, serialization / deserialization also needs to be handled additionally.

[0004] Persistent storage technology: MMKV, as an open-source, high-efficiency key-value pair repository, is based on the memory mapping (mmap) mechanism. It features fast read and write speeds and supports multiple data types (primitive types, strings, binary, etc.), and is widely used in scenarios that require efficient persistent storage.

[0005] Automatic code generation technology: Repetitive code can be automatically generated through template engines (such as Jinja2) and scripts (such as Python), reducing the amount of manual coding. It is commonly used in ORM (Object Relational Mapping) frameworks and Interface Definition Language (IDL) generation scenarios.

[0006] Existing technologies have achieved the core requirement of "configuring and generating basic interfaces + manually integrating MMKV storage," but they have not solved core issues such as handling complex types, automating notification mechanisms, and standardizing code generation. Therefore, how to automatically generate interface code, reduce manual coding work, and improve development efficiency and accuracy is an urgent problem to be solved. Summary of the Invention

[0007] In view of this, the purpose of this invention is to provide a method, apparatus, device, and medium for generating and maintaining interface code, which can automatically generate interface code without manual writing, thereby improving development efficiency and eliminating problems such as type errors and interface omissions during manual coding, ensuring code consistency and standardization. The specific solution is as follows: Firstly, this application discloses a method for generating and maintaining interface code, including: After environment verification and resource loading are completed, the validity of each attribute configuration JSON file in the file list to be processed is verified. If the verification is successful, the text content of the attribute configuration JSON file is read to obtain the corresponding text information; the resources include template files and utility functions. Extract the target field of the root node of the attribute configuration JSON file based on the text information, obtain the corresponding attribute information based on the target field, and generate the corresponding target interface code based on the attribute information and the template file. Create a corresponding callback management container for the target attribute that needs to be notified, and generate a public interface corresponding to the target attribute so that callback functions can be added or removed to the callback management container of the target attribute through the public interface; When the target attribute changes, the public interface executes the callback functions in the callback management container according to the target order to complete the attribute change notification; the target order is the order in which attribute value verification, attribute value update, attribute value persistence and callback notification are executed.

[0008] Optionally, before performing validity checks on the JSON files configuring each attribute in the list of files to be processed, the method further includes: Check if the property configuration JSON file and the template file used to generate the interface code exist; If it exists, the template file is read and utility functions are loaded to complete environment verification and resource loading; the template file includes an interface declaration specification definition file and an interface implementation logic definition file; the utility functions include a JSON format verification function, a data type conversion function, a cyclic redundancy check value calculation function, and a log output function.

[0009] Optionally, the validation of the JSON files configuring each attribute in the list of files to be processed includes: Filter files in the target directory based on their file extensions, and determine the list of files to be processed based on the filtering results. Determine whether each attribute configuration JSON file in the list of files to be processed has permission errors and whether it is an empty file; If none of them exist, the validity check is successful. Otherwise, output an error log.

[0010] Optionally, the step of extracting the target field of the root node of the attribute configuration JSON file based on the text information, and obtaining the corresponding attribute information based on the target field, includes: The grammatical validity of the text information is verified using a pre-defined JSON parsing library; If the text information contains a formatting error, the corresponding error location information will be output. If the text information is free of formatting errors, then extract the target field from the root node of the attribute configuration JSON file; the target field includes the file storage identifier and the attribute list; The attribute list is traversed, and each attribute in the attribute list is parsed to obtain the attribute information; the attribute information includes the attribute name, attribute data type, access mode, attribute default value, attribute change notification switch, and storage key name.

[0011] Optionally, after generating the corresponding target interface code based on the attribute information and the template file, the method further includes: Generate the MMKV persistent storage file corresponding to the attribute configuration JSON file; A summary log is generated and output based on the target interface code and the MMKV persistent storage file.

[0012] Optionally, the method further includes: If an exception occurs during the execution of a callback function in the callback management container, a log is logged and the next callback function is executed directly.

[0013] Optionally, the method further includes: If the callback management container is empty, the attribute change notification process is prohibited from being triggered.

[0014] Secondly, this application discloses an interface code generation and maintenance apparatus, comprising: The text information acquisition module is used to perform validity checks on each attribute configuration JSON file in the file list to be processed after environment verification and resource loading are completed. If the verification is successful, the text content of the attribute configuration JSON file is read to obtain the corresponding text information; the resources include template files and utility functions. The interface code generation module is used to extract the target field of the root node of the attribute configuration JSON file based on the text information, obtain the corresponding attribute information based on the target field, and generate the corresponding target interface code based on the attribute information and the template file. The public interface generation module is used to create a corresponding callback management container for the target attribute that needs to be notified, and generate a public interface corresponding to the target attribute, so as to add or remove callback functions to the callback management container of the target attribute through the public interface. The attribute change notification module is used to execute the callback functions in the callback management container in the public interface according to the target order when the target attribute changes, so as to complete the attribute change notification; the target order is the order of executing attribute value verification, attribute value update, attribute value persistence and callback notification in sequence.

[0015] Thirdly, this application discloses an electronic device, including: Memory, used to store computer programs; A processor is used to execute computer programs to implement the steps of the interface code generation and maintenance methods described above.

[0016] Fourthly, this application discloses a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the aforementioned interface code generation and maintenance method.

[0017] In this application, after environment verification and resource loading are completed, the validity of each attribute configuration JSON file in the file list to be processed is verified. If the verification is successful, the text content of the attribute configuration JSON file is read to obtain the corresponding text information. The resources include template files and utility functions. The target field of the root node of the attribute configuration JSON file is extracted according to the text information. The corresponding attribute information is obtained based on the target field. The corresponding target interface code is generated based on the attribute information and the template file. A corresponding callback management container is created for the target attribute that needs to be notified, and a public interface corresponding to the target attribute is generated so that callback functions can be added or removed from the callback management container of the target attribute through the public interface. When the target attribute changes, the callback functions in the callback management container are executed in the public interface according to the target order to complete the attribute change notification. The target order is the order of executing attribute value verification, attribute value update, attribute value persistence, and callback notification in sequence. As can be seen, this application defines the type, access mode, default value and notification switch of the attribute through the configuration file, and automatically generates the corresponding read and write interface, reducing manual coding work and improving development efficiency and accuracy; by configuring the automatic generation of callback registration and triggering logic, all registered callback functions can be automatically called when the attribute changes, avoiding the risk of omissions in manually maintaining notification logic. Attached Figure Description

[0018] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0019] Figure 1 This is a flowchart of an interface code generation and maintenance method disclosed in this application; Figure 2 This is a schematic diagram of the execution flow of an automated script disclosed in this application; Figure 3 This is a schematic diagram illustrating the overall process of an attribute change notification disclosed in this application. Figure 4 This is a schematic diagram illustrating the code generation of a callback management container disclosed in this application; Figure 5 This is a schematic diagram of an interface registration and deregistration code disclosed in this application; Figure 6 This is a schematic diagram of an execution sequence code disclosed in this application; Figure 7 This is a schematic diagram of auxiliary logic code for one of the interfaces disclosed in this application; Figure 8 This is a schematic diagram of an overall block diagram disclosed in this application; Figure 9 This is a schematic diagram of the structure of an interface code generation and maintenance device disclosed in this application; Figure 10 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation

[0020] 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. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0021] Traditional manual API development or simple configuration generation tools require repetitive implementation of homogeneous logic such as type validation and storage interaction for each attribute. When the number of attributes reaches dozens or even hundreds, the workload of manual coding increases linearly, and inconsistencies in API logic are easily caused by oversights (such as omitting default value handling for a certain attribute). Furthermore, complex nested types (such as arrays)... dict The serialization / deserialization of strings requires separate code, further increasing the risk of errors. In existing solutions, adding new attributes requires manually writing interface code, notification logic (if needed), and MMKV interaction logic; modifying the attribute type requires simultaneous modification of the Get / Set interfaces, serialization logic, and external calls dependent on that attribute, resulting in a cascading effect and maintenance costs increasing dramatically with the number of attributes. In manually implemented notification mechanisms, the observer list for each attribute needs to be defined separately, and the notification triggering logic needs to be embedded in the Set interface, resulting in code scattered across multiple files. When enabling / disabling notification mode for an attribute, the triggering logic in the Set interface needs to be manually modified, which is prone to omissions (such as forgetting to add notification triggering code in the Set), causing the notification mechanism to fail. Existing configuration generation tools only support basic types; handling arrays, dictionaries, and nested types requires manual code addition, which cannot be uniformly managed through configuration, limiting the tool's versatility and still requiring significant manual development. To address the aforementioned technical problems, this invention discloses an interface code generation and maintenance method, apparatus, device, and medium that can automatically generate interface code without manual writing, thereby improving development efficiency. It also eliminates issues such as type errors and interface omissions during manual coding, ensuring code consistency and standardization.

[0022] See Figure 1 As shown in the figure, an embodiment of the present invention discloses an interface code generation and maintenance method, including: Step S11: After the environment verification and resource loading are completed, perform a validity check on each attribute configuration JSON file in the file list to be processed. If the verification is successful, read the text content of the attribute configuration JSON file to obtain the corresponding text information; the resources include template files and utility functions.

[0023] In this embodiment, `build.py` serves as the automated generation engine. Its core execution logic is "batch loading → single file parsing → template rendering → dual-product output → batch cleanup." Using a single JSON attribute configuration file in the `. / tools / app` directory as the smallest processing unit, it completes the entire automated transformation from "structured attribute configuration" to "callable C++ interfaces + persistent MMKV storage." No manual coding is required throughout; all implementation work is accomplished simply by defining attribute characteristics through JSON configuration. The execution flow of the automated script is as follows: Figure 2 As shown.

[0024] First, after `build.py` starts, it performs basic environment verification and resource loading, paving the way for subsequent parsing and generation processes. Before validating the JSON (JavaScript Object Notation) files for each attribute configuration in the file list to be processed, it checks whether the attribute configuration JSON files and the template files used to generate interface code exist. If they exist, it reads the template files and loads utility functions to complete environment verification and resource loading. The template files include interface declaration specification definition files and interface implementation logic definition files. The utility functions include JSON format validation functions, data type conversion functions, cyclic redundancy check value calculation functions, and log output functions. Specifically, the process involves: directory validation and creation: checking if the core directories (the input attribute configuration JSON file and the template file used to generate the interface code) exist; template engine loading: initializing the Python template engine (such as Jinja2), reading the template files under the . / tools / template directory—including .h templates (defining interface declaration specifications) and .cpp templates (defining interface implementation logic), and caching the template content to avoid repeated reading; and utility function initialization: loading auxiliary functions (such as JSON format validation functions, data type conversion functions, CRC (Cyclic redundancy check) check value calculation functions, and log output functions) to provide basic capabilities for subsequent steps.

[0025] After environment verification and resource loading are completed, files in the target directory are filtered based on their file extensions, and a list of files to be processed is determined based on the filtering results. The script then checks whether each attribute configuration JSON file in the list of files to be processed has permission errors or is empty. If neither exists, the validity check is successful; otherwise, an error log is output. After successful verification, the text content of the attribute configuration JSON file is read to obtain the corresponding text information. Specifically, after completing environment preparation, the script enters the configuration loading stage to achieve batch management of all attribute configurations: Traversing the target directory: Scanning the . / tools / app directory, filtering out all files with the .json extension, and generating a list of files to be processed (e.g., app1_cfg.json, app2_cfg.json); Initial file validity check: Checking each JSON file for permission errors, empty files, etc. If any exist, an error log is output and the file is skipped without interrupting the overall process; Loading files in sequence: Sort by filename (or custom rules), read the text content of each JSON file one by one, and enter the "single file parsing stage".

[0026] Step S12: Extract the target field of the root node of the attribute configuration JSON file based on the text information, obtain the corresponding attribute information based on the target field, and generate the corresponding target interface code based on the attribute information and the template file.

[0027] In this embodiment, the syntax validity of the text information is verified using a preset JSON parsing library. If the text information has a format error, the corresponding error location information is output. If the text information does not have a format error, the target field of the root node of the attribute configuration JSON file is extracted. The target field includes a file storage identifier and an attribute list. The attribute list is traversed, and each attribute in the attribute list is parsed to obtain the attribute information. The attribute information includes the attribute name, attribute data type, access mode, attribute default value, attribute change notification switch, and storage key name. Finally, the corresponding target interface code is generated based on the attribute information and the template file. Specifically, this stage is crucial for transforming the "unstructured configuration" in JSON into "structured attribute data that scripts can recognize." For a single JSON file, all attribute configurations are parsed field by field: JSON format validation: The file's syntax is validated using a JSON parsing library (such as Python's json module). If format errors are found (such as missing commas or unclosed quotation marks), the detailed error location is output and the file is skipped; Root field parsing: The core fields of the JSON root node are extracted, such as mmap_id (a unique identifier for the MMKV storage file) and properties (a list of attributes, the core field); Attribute-by-attribute parsing (properties array): The properties array is traversed, and the following key information is parsed for each attribute (covering all core configurations). The specific parsing content is shown in Table 1.

[0028] Table 1

[0029] Then, structured data encapsulation: all parsed attribute information is encapsulated into Python dictionaries / objects (such as {"name":"volume","type":"uint8_t",...}) for easy use in subsequent template rendering.

[0030] Finally, based on the parsed attribute structured data and the template file in . / tools / template, compileable C++ interface code is generated: Rendering by template type: .h header file generation (output to . / inc): ① Based on the .h template, generate the property management class declaration (e.g., class App1Cfg), and associate the class name with the JSON file name (e.g., app1_cfg.json → App1Cfg). ② Generate read-only / read-write interface declarations for attributes (such as uint8_t getVolume() const;, void setVolume(uint8_t value);). For read-only attributes, only the get interface is generated. ③ If the property is enabled with notify, generate a callback registration / unregistration interface declaration (e.g., void registerVolumeCallback(std::function<void(uint8_t)> cb);); ④ Generate the basic declaration of MMKV storage association (such as private member MMKV) mmkv_handler_;).

[0031] .cpp source file generation (output to . / src): ① Generate the class constructor, initialize the MMKV handle (associated with mmap_id), default attribute values, and load initial data from MMKV (if the MMKV file already exists); ② Implement the get interface: read the attribute value in memory (read-only attributes are returned directly, and readable and writable attributes are returned synchronously after being refreshed from MMKV); ③ Implement the set interface: validate the type of the input value → update the memory attribute value → serialize the new value and write it to MMKV → if notify is enabled, iterate through the callback list and trigger all registered callback functions; ④ Implement callback registration / deregistration interfaces: Maintain a list of callback functions for each property (e.g., std::vector). <std::function<void(uint8_t)> > volume_cbs_;), supports multiple callback bindings; ⑤ For composite / nested types, automatically generate serialization / deserialization logic (e.g., for dictionaries)<string, int> Convert to a binary stream supported by MMKV, and reverse-parse during reading.

[0032] File write and overwrite rules: The generated .h / .cpp files are prefixed with the JSON filename (e.g., app1_cfg.h / app1_cfg.cpp). If a file with the same name already exists in the target directory, it will be overwritten by default (backup can be retained if configured).

[0033] In addition, after generating the corresponding target interface code based on the attribute information and the template file, this application generates an MMKV persistent storage file corresponding to the attribute configuration JSON file; and generates and outputs a summary log based on the target interface code and the MMKV persistent storage file. For each parsed JSON file, a corresponding MMKV persistent storage file is generated to ensure the persistence and integrity of the attribute data. Initial data initialization: Based on the default values ​​of each attribute in the JSON, an initial MMKV data dictionary is constructed using mmkv_key as the key and the serialized default value as the value; CRC check value calculation: A CRC32 (or custom CRC algorithm) check value is calculated on the binary content of the initial data dictionary for subsequent data integrity verification; MMKV file writing: ① Create an MMKV file in the . / tools / output directory with mmap_id as the filename (e.g., app1_cfg.mmkv); ② Write the "initial data binary stream + CRC check value" to a file, where the CRC value is stored in a fixed position in the file (e.g., the last 8 bytes of the file) for easy verification during subsequent interface reading; Data format compatibility: For composite / nested types, it automatically serializes them into binary formats supported by MMKV (such as Protobuf, custom binary protocols) to ensure that the data can be read and written normally.

[0034] Furthermore, single-file processing is completed: after completing the "parsing → interface generation → MMKV generation" of a single JSON file, a green success log is output (e.g., [SUCCESS] The interface and MMKV file generation of app1_cfg.json has been completed); batch processing is performed: returning to the "JSON configuration file batch loading stage", the next JSON file in the file list is processed until all files are processed; the overall process is completed: a summary log is output (e.g., a total of 5 JSON files were processed, 5 sets of interface files + 5 MMKV files were successfully generated), resources such as the template engine and MMKV handles are released, and the script exits normally. An automatic binding mechanism between attribute objects and the MMKV storage engine was created, realizing integrated "memory-storage" management to ensure real-time data persistence and cross-process consistency. A tree-structured general JSON object to C++ structured object conversion algorithm was designed, which can automatically map the attributes defined in JSON to the member variables of C++ classes, supporting complete mapping of basic types (int / float / string), composite types (arrays / dictionaries), and custom types.

[0035] Step S13: Create a corresponding callback management container for the target attribute that needs to be notified, and generate a public interface corresponding to the target attribute so that callback functions can be added or removed to the callback management container of the target attribute through the public interface.

[0036] In this embodiment, the generated C++ interface code in the . / src directory (such as app_cfg.cpp) implements the notify (property change notification) mechanism based on the observer pattern. All notification-related logic is automatically generated by build.py based on the notify:true flag in the JSON configuration, requiring no manual writing. It is deeply coupled with the property read / write and persistence logic, yet with clear boundaries. The overall process of property change notification is as follows: Figure 3 As shown.

[0037] This application first generates a dedicated callback management container for each property with `notify` enabled, ensuring the independence of the notification logic and thread safety, such as... Figure 4 As shown. Among these, callback type adaptation: the parameter type of std::function must be exactly the same as the attribute type (e.g., dict).<string,int> The attribute corresponds to std::function <void(std::map<std::string,int> )>); Independent containers: Each attribute with notify has its own dedicated callback container (such as user_info_callbacks_), and the notification logic between attributes does not interfere with each other; Thread-safe: A mutex lock is generated by default, covering the entire process of "registering callback", "triggering callback" and "updating attribute value".

[0038] Afterwards, a standardized registration / deregistration interface is generated for external modules to bind / unbind attribute change notifications, such as... Figure 5 As shown. Regarding access control: read-only properties (mode:ro) will not generate a Set (public interface) interface, and therefore will not generate any callback-related interfaces. In this way, a public interface corresponding to the target property is generated, allowing callback functions to be added or removed from the callback management container of the target property through this public interface.

[0039] Step S14: When the target attribute changes, the public interface executes the callback functions in the callback management container according to the target order to complete the attribute change notification; the target order is the order in which attribute value verification, attribute value update, attribute value persistence and callback notification are executed in sequence.

[0040] In this embodiment, the notification triggering logic in the Set interface is as follows: the core trigger point of the notification mechanism is in the Set interface of the property, strictly following the execution order of "validation → update → persistence → notification", such as... Figure 6As shown. Execution order: Ensure that the notification is a "persistent and valid value," avoiding external reception of temporary values ​​that are "only updated in memory and not persisted"; Exception isolation: When a single callback execution throws an exception, only a log is recorded and the next callback continues to execute, without interrupting the core process; No callback handling: If the callback container is empty, the triggering logic is skipped directly, with no performance loss. In other words, if an exception occurs during the execution of a callback function in the callback management container, a log is recorded, and the next callback function is executed directly. If the callback management container is empty, the attribute change notification process is prohibited from being triggered.

[0041] Additionally, it should be noted that the Get interface is only responsible for reading attribute values ​​and does not involve any notification logic. For example... Figure 7 As shown, it innovatively integrates the observer pattern with property accessors, automatically generating a complete notification management mechanism for each property with notify enabled, without requiring a single line of manual notification code.

[0042] In this way, the present invention defines attribute metadata uniformly through JSON configuration, and automatically generates C++ interface code by script, eliminating the need to manually write Get / Set and serialization logic for each attribute. This directly solves the problems of "low efficiency and error-proneness from repetitive coding" in traditional development—dozens of attribute interfaces that previously required hours to write can now be completed simply by modifying the configuration and executing the script, improving development efficiency by over 80%. It also eliminates issues such as type errors and missing interfaces during manual coding, ensuring code consistency and standardization. Furthermore, because the present invention automatically generates thread-safe callback management logic for attributes with notify enabled, it eliminates the need to manually implement the observer pattern, thus avoiding the defects of "missed callback triggers and multi-threaded race conditions" in traditional notification mechanisms. The automatic integration of MMKV storage allows for attribute data persistence and memory synchronization without manual intervention, ensuring real-time data consistency and improving attribute access performance through the efficient read / write characteristics of MMKV. This perfectly solves the pain points of "cumbersome complex type adaptation and error-prone storage synchronization" in traditional solutions.

[0043] In summary, after environment verification and resource loading are completed, the validity of each attribute configuration JSON file in the file list to be processed is verified. Upon successful verification, the text content of the attribute configuration JSON file is read to obtain the corresponding text information. The resources include template files and utility functions. The target fields of the root node of the attribute configuration JSON file are extracted based on the text information. Based on the target fields, the corresponding attribute information is obtained. Based on the attribute information and the template file, corresponding target interface code is generated. A corresponding callback management container is created for the target attributes that need to be notified, and a public interface corresponding to the target attribute is generated so that callback functions can be added or removed from the callback management container of the target attribute through the public interface. When the target attribute changes, the callback functions in the callback management container are executed in the public interface according to the target order to complete the attribute change notification. The target order is the sequential execution of attribute value verification, attribute value update, attribute value persistence, and callback notification. As can be seen, this application defines the type, access mode, default value and notification switch of the attribute through the configuration file, and automatically generates the corresponding read and write interface, reducing manual coding work and improving development efficiency and accuracy; by configuring the automatic generation of callback registration and triggering logic, all registered callback functions can be automatically called when the attribute changes, avoiding the risk of omissions in manually maintaining notification logic.

[0044] This invention constructs a complete technical framework around "configuration-driven + template rendering + automated generation + persistent storage." Its core objective is to achieve automated generation of C++ property read / write interfaces and reliable storage of property data through a standardized process. The overall framework can be divided into four core modules, each achieving decoupling and collaboration based on the project directory structure, forming a complete closed loop of "input-processing-output." The overall block diagram of this invention is shown below. Figure 8 As shown.

[0045] I. Configure the input module: This module is the "property definition source" of the entire framework, corresponding to the . / tools / app directory of the project, and its core carrier is a JSON format configuration file. Its core function is to uniformly describe property metadata through structured configuration, completing property definitions without writing any C++ code. Specifically, it includes: Basic attribute information: attribute name, data type (supports basic types, arrays / dictionaries / sequences and nested types), access mode (read-write / read-only), default value; Extended feature configuration: attribute change notification switch (notify field), MMKV storage association identifier (mmap_id), etc.; Batch management capability: Supports parallel processing of multiple JSON files, with each JSON file corresponding to an independent set of attributes, realizing modular division of attributes.

[0046] II. Template Support Module: This module serves as the "structural baseline" for the interface code, corresponding to the `. / tools / template` directory of the project. It provides standardized C++ interface code templates (including `.h` header file templates and `.cpp` source file templates). The templates pre-define the basic structure of property read / write interfaces (Get / Set), notification callback registration / triggering logic, and general MMKV interaction code. Its core function is: Standardize coding style: Ensure that all generated interface files follow a consistent coding style to improve code readability and maintainability; Reduce development costs: Avoid repeatedly writing homogenized interface framework code, and adapt personalized information with different attributes through template placeholders; Supports flexible expansion: The template can be modified to quickly adapt to the interface specifications of different projects without changing the core generation logic.

[0047] III. Core Generation Module: This module is the "central engine" of the entire framework, corresponding to the `. / tools / py / build.py` script in the project. It bears the core responsibility of "parsing-binding-generating" and is crucial for achieving automation. Its core logic is to connect the preceding input module with the subsequent output module. Specifically, its implementation is as follows: Configuration parsing: Iterate through and read all JSON files in the . / tools / app directory, verify the validity of the configuration format, extract the meta-information of each attribute, and convert it into structured data; Template binding: The parsed attribute structured data is precisely filled into the placeholders in the template file according to the rule of "one set of interfaces for one JSON file", so as to complete the dynamic rendering of the interface code; Logic integration: Automatically embed differentiated logic, such as automatically associating callback trigger code with attributes containing notify=true, and automatically integrating serialization / deserialization logic with complex type attributes; Workflow scheduling: Coordinates the entire automated process, including directory checks, exception handling, and batch file loop processing, to ensure the stability of the generation process.

[0048] IV. Product Output Module: This module is the framework's "output endpoint," corresponding to the project's . / inc, . / src, and . / tools / output directories. It is responsible for outputting two types of core artifacts, supporting attribute access and data persistence for external components: Interface file output (. / inc+. / src): Generates .h header files (interface declarations) and .cpp source files (interface implementations) that correspond one-to-one with the JSON configuration. External components can directly read, set, and register properties and notifications through the generated interfaces without having to worry about the underlying implementation details. Output storage files (. / tools / output): Generates persistent storage files for attributes based on MMKV. Each file contains the initial data (default values) of all attributes in the corresponding JSON configuration and CRC check values, which not only ensures the persistent storage of attribute data, but also ensures data integrity through CRC check to prevent tampering or damage.

[0049] In this way, the core of this application is to transform the "attribute configuration" in JSON into "structured attribute data" that scripts can recognize, covering all dimensions such as type, permissions, notifications, and storage, providing a unified data input for subsequent generation; relying on a template engine to achieve dynamic rendering of "configuration → code", the interface file automatically integrates attribute reading and writing, notification triggering, and MMKV interaction logic, and the MMKV file automatically completes initial data filling and integrity verification; using "a single JSON file" as the smallest processing unit, it ensures a one-to-one correspondence of "one configuration - one set of interfaces - one MMKV file", facilitating modular management and maintenance. This process fully realizes "configuration-driven development", and users only need to maintain the JSON configuration file to automatically complete the generation of all interface code and storage files, greatly reducing the workload of repetitive coding, while ensuring the standardization of code style and storage format.

[0050] See Figure 9 As shown, an embodiment of the present invention discloses an interface code generation and maintenance device, comprising: The text information acquisition module 11 is used to perform legality verification on each attribute configuration JSON file in the file list to be processed after the environment verification and resource loading are completed. After successful verification, the text content of the attribute configuration JSON file is read to obtain the corresponding text information; the resources include template files and utility functions. The interface code generation module 12 is used to extract the target field of the root node of the attribute configuration JSON file according to the text information, obtain the corresponding attribute information based on the target field, and generate the corresponding target interface code based on the attribute information and the template file. The public interface generation module 13 is used to create a corresponding callback management container for the target attribute that needs to be notified, and generate a public interface corresponding to the target attribute, so as to add or remove callback functions to the callback management container of the target attribute through the public interface. The attribute change notification module 14 is used to execute the callback functions in the callback management container in the public interface according to the target order when the target attribute changes, so as to complete the attribute change notification; the target order is the order of executing attribute value verification, attribute value update, attribute value persistence and callback notification in sequence.

[0051] In summary, after environment verification and resource loading are completed, the validity of each attribute configuration JSON file in the file list to be processed is verified. Upon successful verification, the text content of the attribute configuration JSON file is read to obtain the corresponding text information. The resources include template files and utility functions. The target fields of the root node of the attribute configuration JSON file are extracted based on the text information. Based on the target fields, the corresponding attribute information is obtained. Based on the attribute information and the template file, corresponding target interface code is generated. A corresponding callback management container is created for the target attributes that need to be notified, and a public interface corresponding to the target attribute is generated so that callback functions can be added or removed from the callback management container of the target attribute through the public interface. When the target attribute changes, the callback functions in the callback management container are executed in the public interface according to the target order to complete the attribute change notification. The target order is the sequential execution of attribute value verification, attribute value update, attribute value persistence, and callback notification. As can be seen, this application defines the type, access mode, default value and notification switch of the attribute through the configuration file, and automatically generates the corresponding read and write interface, reducing manual coding work and improving development efficiency and accuracy; by configuring the automatic generation of callback registration and triggering logic, all registered callback functions can be automatically called when the attribute changes, avoiding the risk of omissions in manually maintaining notification logic.

[0052] In some specific embodiments, the device can also be used to check whether the attribute configuration JSON file and the template file for generating interface code exist; if they exist, the template file is read and utility functions are loaded to complete environment verification and resource loading; the template file includes an interface declaration specification definition file and an interface implementation logic definition file; the utility functions include a JSON format verification function, a data type conversion function, a cyclic redundancy check value calculation function, and a log output function.

[0053] In some specific embodiments, the text information acquisition module 11 can be used to filter files in the target directory according to the file extension, determine the list of files to be processed according to the corresponding filtering results, determine whether there are permission abnormalities or empty files in the JSON files of each attribute configuration in the list of files to be processed, and if neither exists, determine that the legality verification is successful; otherwise, output an error log.

[0054] In some specific embodiments, the interface code generation module 12 can be used to verify the syntactic validity of the text information using a preset JSON parsing library; if the text information has a format error, the corresponding error location information is output; if the text information does not have a format error, the target field of the root node of the attribute configuration JSON file is extracted; the target field includes a file storage identifier and an attribute list; the attribute list is traversed, and each attribute in the attribute list is parsed to obtain the attribute information; the attribute information includes the attribute name, attribute data type, access mode, attribute default value, attribute change notification switch, and storage key name.

[0055] In some specific embodiments, the device can also be used to generate an MMKV persistent storage file corresponding to the attribute configuration JSON file; and to generate and output a summary log based on the target interface code and the MMKV persistent storage file.

[0056] In some specific embodiments, the device can also be used to log an exception if an exception occurs during the execution of a callback function in the callback management container, and then directly execute the next callback function.

[0057] In some specific embodiments, the device can also be used to prevent the attribute change notification process from being triggered if the callback management container is empty.

[0058] Furthermore, embodiments of this application also disclose an electronic device, Figure 10 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.

[0059] Figure 10 This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. Specifically, the electronic device 20 may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the interface code generation and maintenance method disclosed in any of the foregoing embodiments. Furthermore, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0060] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0061] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include operating system 221, computer program 222, etc., and the storage method can be temporary storage or permanent storage.

[0062] The operating system 221 is used to manage and control the various hardware devices on the electronic device 20 and the computer program 222, which may be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program capable of performing the interface code generation and maintenance method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include a computer program capable of performing other specific tasks.

[0063] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned disclosed method for generating and maintaining interface code. Specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.

[0064] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.

[0065] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0066] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0067] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0068] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A method for generating and maintaining interface code, characterized in that, include: After environment verification and resource loading are completed, the validity of each attribute configuration JSON file in the file list to be processed is verified. If the verification is successful, the text content of the attribute configuration JSON file is read to obtain the corresponding text information; the resources include template files and utility functions. Extract the target field of the root node of the attribute configuration JSON file based on the text information, obtain the corresponding attribute information based on the target field, and generate the corresponding target interface code based on the attribute information and the template file. Create a corresponding callback management container for the target attribute that needs to be notified, and generate a public interface corresponding to the target attribute so that callback functions can be added or removed to the callback management container of the target attribute through the public interface; When the target attribute changes, the public interface executes the callback functions in the callback management container according to the target order to complete the attribute change notification; the target order is the order in which attribute value verification, attribute value update, attribute value persistence and callback notification are executed.

2. The interface code generation and maintenance method according to claim 1, characterized in that, Before performing validity checks on the JSON files configuring each attribute in the list of files to be processed, the process also includes: Check if the property configuration JSON file and the template file used to generate the interface code exist; If it exists, the template file is read and utility functions are loaded to complete environment verification and resource loading; the template file includes an interface declaration specification definition file and an interface implementation logic definition file; the utility functions include a JSON format verification function, a data type conversion function, a cyclic redundancy check value calculation function, and a log output function.

3. The interface code generation and maintenance method according to claim 1, characterized in that, The validation of the JSON files configuring each attribute in the list of files to be processed includes: Filter files in the target directory based on their file extensions, and determine the list of files to be processed based on the filtering results. Determine whether each attribute configuration JSON file in the list of files to be processed has permission errors and whether it is an empty file; If none of them exist, the validity check is successful. Otherwise, output an error log.

4. The interface code generation and maintenance method according to claim 1, characterized in that, The step of extracting the target field of the root node of the attribute configuration JSON file based on the text information, and obtaining the corresponding attribute information based on the target field, includes: The grammatical validity of the text information is verified using a pre-defined JSON parsing library; If the text information contains a formatting error, the corresponding error location information will be output. If the text information is free of formatting errors, then extract the target field from the root node of the attribute configuration JSON file; the target field includes the file storage identifier and the attribute list; The attribute list is traversed, and each attribute in the attribute list is parsed to obtain the attribute information; the attribute information includes the attribute name, attribute data type, access mode, attribute default value, attribute change notification switch, and storage key name.

5. The interface code generation and maintenance method according to claim 1, characterized in that, After generating the corresponding target interface code based on the attribute information and the template file, the process further includes: Generate the MMKV persistent storage file corresponding to the attribute configuration JSON file; A summary log is generated and output based on the target interface code and the MMKV persistent storage file.

6. The interface code generation and maintenance method according to claim 1, characterized in that, Also includes: If an exception occurs during the execution of a callback function in the callback management container, a log is logged and the next callback function is executed directly.

7. The interface code generation and maintenance method according to any one of claims 1 to 6, characterized in that, Also includes: If the callback management container is empty, the attribute change notification process is prohibited from being triggered.

8. An interface code generation and maintenance device, characterized in that, include: The text information acquisition module is used to perform validity checks on each attribute configuration JSON file in the file list to be processed after environment verification and resource loading are completed. If the verification is successful, the text content of the attribute configuration JSON file is read to obtain the corresponding text information; the resources include template files and utility functions. The interface code generation module is used to extract the target field of the root node of the attribute configuration JSON file based on the text information, obtain the corresponding attribute information based on the target field, and generate the corresponding target interface code based on the attribute information and the template file. The public interface generation module is used to create a corresponding callback management container for the target attribute that needs to be notified, and generate a public interface corresponding to the target attribute, so as to add or remove callback functions to the callback management container of the target attribute through the public interface. The attribute change notification module is used to execute the callback functions in the callback management container in the public interface according to the target order when the target attribute changes, so as to complete the attribute change notification; the target order is the order of executing attribute value verification, attribute value update, attribute value persistence and callback notification in sequence.

9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing a computer program to implement the steps of the interface code generation and maintenance method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, A computer program is stored on a computer-readable storage medium, and when executed by a processor, the computer program implements the steps of the interface code generation and maintenance method as described in any one of claims 1 to 7.