mirror of
https://github.com/ZGCA-Forge/MsgCenterPy.git
synced 2025-12-14 13:04:34 +00:00
d5704e78c37e81582bc8568f221369c8f2016db5
Bumps [actions/upload-pages-artifact](https://github.com/actions/upload-pages-artifact) from 3 to 4. - [Release notes](https://github.com/actions/upload-pages-artifact/releases) - [Commits](https://github.com/actions/upload-pages-artifact/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/upload-pages-artifact dependency-version: '4' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com>
MsgCenterPy
🚀 概述
MsgCenterPy 是一个基于统一实例管理器架构的多格式消息转换系统,支持 ROS2、Pydantic、Dataclass、JSON、Dict、YAML 和 JSON Schema 之间的无缝互转。
支持的格式
| 格式 | 读取 | 写入 | JSON Schema | 类型约束 |
|---|---|---|---|---|
| ROS2 | ✅ | ✅ | ✅ | ✅ |
| JSON Schema | ✅ | ✅ | ✅ | ✅ |
| Pydantic | 开发中 | 开发中 | 开发中 | 开发中 |
| Dataclass | 开发中 | 开发中 | 开发中 | 开发中 |
| JSON | 开发中 | 开发中 | 开发中 | 开发中 |
| Dict | 开发中 | 开发中 | 开发中 | 开发中 |
| YAML | 开发中 | 开发中 | 开发中 | 开发中 |
📦 安装
基础安装
pip install msgcenterpy
包含可选依赖
# 安装 ROS2 支持
conda install
# 安装开发工具
pip install msgcenterpy[dev]
# 安装文档工具
pip install msgcenterpy[docs]
# 安装所有依赖
pip install msgcenterpy[all]
从源码安装
git clone https://github.com/ZGCA-Forge/MsgCenterPy.git
cd MsgCenterPy
pip install -e .[dev]
🔧 快速开始
基础使用
from msgcenterpy import MessageInstance, MessageType
# 从字典创建消息实例
data = {
"name": "sensor_001",
"readings": [1.0, 2.0, 3.0],
"active": True
}
dict_instance = MessageInstance.create(MessageType.DICT, data)
# 生成 JSON Schema
schema = dict_instance.get_json_schema()
print(schema)
ROS2 消息转换
from std_msgs.msg import String
from msgcenterpy.instances.ros2_instance import ROS2MessageInstance
# 创建 ROS2 消息实例
string_msg = String()
string_msg.data = "Hello ROS2"
ros2_instance = ROS2MessageInstance(string_msg)
# 转换为 JSON Schema
json_schema_instance = ros2_instance.to_json_schema()
# 获取生成的 Schema
schema = json_schema_instance.json_schema
print(schema)
字段访问和约束
# 动态字段访问
ros2_instance.data_field = "new_value"
print(ros2_instance.fields.get_field_info("data"))
# 类型约束验证
type_info = ros2_instance.fields.get_sub_type_info("data")
print(f"约束条件: {[c.type.value for c in type_info.constraints]}")
📖 文档
核心概念
- MessageInstance: 统一消息实例基类
- TypeInfo: 详细的字段类型信息和约束
- FieldAccessor: 统一字段访问接口
- MessageCenter: 消息类型管理和转换中心
API 参考
详细的 API 文档请访问:https://zgca-forge.github.io/MsgCenterPy/
示例代码
更多示例请查看 examples/ 目录:
🧪 测试
运行测试
# 运行所有测试
python -m pytest
# 运行特定测试套件
python run_all_tests.py --type json_schema
# 生成覆盖率报告
pytest --cov=msgcenterpy --cov-report=html
🛠️ 开发
开发环境设置
git clone https://github.com/ZGCA-Forge/MsgCenterPy.git
cd MsgCenterPy
pip install -e .[dev]
pre-commit install
代码质量
# 代码格式化
black msgcenterpy tests
isort msgcenterpy tests
# 类型检查
mypy msgcenterpy
# 运行测试
pytest
贡献指南
- Fork 项目
- 创建特性分支 (
git checkout -b feature/AmazingFeature) - 提交变更 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 创建 Pull Request
详细贡献指南请查看 CONTRIBUTING.md
📊 开发路线图
- ✅ ROS2 消息支持
- ✅ JSON Schema 生成和验证
- ✅ 统一字段访问器
- ✅ 类型约束系统
- 🔄 Pydantic 集成
- 🔄 Dataclass 支持
- 🔄 YAML 格式支持
- 🔄 性能优化
- 🔄 插件系统
🤝 社区
支持渠道
- 💬 讨论: GitHub Discussions
- 🐛 问题: GitHub Issues
- 📖 文档: GitHub Pages
贡献者
感谢所有为 MsgCenterPy 做出贡献的开发者!
📄 许可证
本项目基于 Apache-2.0 许可证开源 - 查看 LICENSE 文件了解详情。
🙏 致谢
- ROS2 - 机器人操作系统
- Pydantic - 数据验证库
- pytest - 测试框架
- jsonschema - JSON Schema 验证
Description
Unified message conversion system supporting ROS2, Pydantic, Dataclass, JSON, YAML, Dict, and MCP schema inter-conversion
Languages
Python
96.8%
PowerShell
2%
Shell
1.2%