Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: getter for message classes #1325

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions python/mcap-protobuf-support/mcap_protobuf/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from google.protobuf.descriptor_pb2 import FileDescriptorProto, FileDescriptorSet
from google.protobuf.descriptor_pool import DescriptorPool
from google.protobuf.message_factory import GetMessageClassesForFiles, GetMessageClass
from google.protobuf.reflection import GeneratedProtocolMessageType

from mcap.decoder import DecoderFactory as McapDecoderFactory
from mcap.exceptions import McapError
Expand All @@ -26,6 +27,13 @@ class DecoderFactory(McapDecoderFactory):
def __init__(self) -> None:
self._types: Dict[int, Type[Any]] = {}

def pb_message_from_schema(
self, schema: Schema
) -> Optional[GeneratedProtocolMessageType]:
if schema.encoding != SchemaEncoding.Protobuf:
return None
return self._types.get(schema.id)

def decoder_for(
self, message_encoding: str, schema: Optional[Schema]
) -> Optional[Callable[[bytes], Any]]:
Expand Down
Loading