from __future__ import annotations
from dataclasses import dataclass
from typing import Any, Generic, TypeVar
from betterproto import Message
from betterproto.lib.google.protobuf import Any as GoogleAny
_M = TypeVar("_M", bound=Message)
[docs]
@dataclass
class MessageGenerated(Generic[_M]):
"""Structure of message generated by our library."""
message: _M
"""Actual message instance."""
path: str
"""Path where this was generated inside the library."""
[docs]
def create_any_message(msg: MessageGenerated[Any]) -> GoogleAny:
"""Wrap message (coerced to binary) with convenience wrapper.
Returns:
:class:`~betterproto.lib.google.protobuf.Any`
"""
return GoogleAny(
type_url=f"/{msg.path}",
value=bytes(msg.message),
)