1.2 KiB
1.2 KiB
代码模板说明
本目录包含用于自动生成C/C++代码的Jinja2模板。
模板结构
cpp/ 目录
包含C++代码生成模板:
- tcp_receiver.template: TCP协议数据接收器模板
- dds_receiver.template: DDS协议数据接收器模板
- deserializer.template: 反序列化器模板(支持JSON/XML/Binary)
- mapper.template: 字段映射器模板
- serializer.template: 序列化器模板(支持JSON/XML/Binary)
- sender.template: 数据发送器模板
模板变量
模板中可用的变量:
source_message: 源消息对象target_message: 目标消息对象mapping_path: 映射路径(边列表)protocol: 传输协议(TCP/UDP/DDS等)serialization: 序列化格式(JSON/XML/Binary)language_standard: 语言标准(C++11/14/17/20)part: 当前生成部分('header' 或 'source')
自定义模板
可以添加自定义模板来支持其他协议或语言:
- 在相应目录下创建
.template文件 - 使用Jinja2语法编写模板
- 在
code_generator_service.py中注册模板
示例
{# 示例模板 #}
{% if part == 'header' %}
#pragma once
// 头文件内容
{% else %}
#include "header.h"
// 源文件内容
{% endif %}