mirror of
https://github.com/ZGCA-Forge/MsgCenterPy.git
synced 2025-12-17 04:50:55 +00:00
init version
This commit is contained in:
54
msgcenterpy/core/envelope.py
Normal file
54
msgcenterpy/core/envelope.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, TypedDict
|
||||
|
||||
ENVELOPE_VERSION: str = "1"
|
||||
|
||||
|
||||
class Properties(TypedDict, total=False):
|
||||
ros_msg_cls_path: str
|
||||
ros_msg_cls_namespace: str
|
||||
json_schema: Dict[str, Any]
|
||||
|
||||
|
||||
class FormatMetadata(TypedDict, total=False):
|
||||
"""Additional metadata for source format, optional.
|
||||
|
||||
Examples: field statistics, original type descriptions, field type mappings, etc.
|
||||
"""
|
||||
|
||||
current_format: str
|
||||
source_cls_name: str
|
||||
source_cls_module: str
|
||||
properties: Properties
|
||||
|
||||
|
||||
class MessageEnvelope(TypedDict, total=True):
|
||||
"""Unified message envelope format.
|
||||
|
||||
- version: Protocol version
|
||||
- format: Source format (MessageType.value)
|
||||
- type_info: Type information (applicable for ROS2, Pydantic, etc.)
|
||||
- content: Normalized message content (dictionary)
|
||||
- metadata: Additional metadata
|
||||
"""
|
||||
|
||||
version: str
|
||||
format: str
|
||||
content: Dict[str, Any]
|
||||
metadata: FormatMetadata
|
||||
|
||||
|
||||
def create_envelope(
|
||||
*,
|
||||
format_name: str,
|
||||
content: Dict[str, Any],
|
||||
metadata: FormatMetadata,
|
||||
) -> MessageEnvelope:
|
||||
env: MessageEnvelope = {
|
||||
"version": ENVELOPE_VERSION,
|
||||
"format": format_name,
|
||||
"content": content,
|
||||
"metadata": metadata,
|
||||
}
|
||||
return env
|
||||
Reference in New Issue
Block a user