Skip to main content

Protobuf support for the Python MCAP library

Project description

Python MCAP protobuf support

This package provides protobuf support for the Python MCAP file format reader.

Installation

Install via Pipenv by adding mcap-protobuf-support to your Pipfile or via the command line:

pipenv install mcap-protobuf-support

MCAP protobuf writing example

First, compile all of your message definitions:

protoc *.proto --python_out .

Next, use the classes generated from those message definitions to register schema in the mcap file.

from mcap.mcap0.writer import Writer as McapWriter
from mcap_protobuf.schema import register_schema

from .complex_message_pb2 import ComplexMessage
from .simple_message_pb2 import SimpleMessage

output = open("example.mcap", "wb")
mcap_writer = McapWriter(output)
mcap_writer.start(profile="protobuf", library="test")

simple_schema_id = register_schema(writer=mcap_writer, message_class=SimpleMessage)

complex_schema_id = register_schema(writer=mcap_writer, message_class=ComplexMessage)

simple_channel_id = mcap_writer.register_channel(
    topic="/simple_message",
    message_encoding="protobuf",
    schema_id=simple_schema_id,
)

complex_channel_id = mcap_writer.register_channel(
    topic="/complex_message",
    message_encoding="protobuf",
    schema_id=complex_schema_id,
)

for i in range(1, 11):
    simple_message = SimpleMessage(data=f"Hello MCAP protobuf world #{i}!")
    mcap_writer.add_message(
        channel_id=simple_channel_id,
        log_time=i * 1000,
        data=simple_message.SerializeToString(),
        publish_time=i * 1000,
    )
    complex_message = ComplexMessage(fieldA=f"Field A {i}", fieldB="Field B {i}")
    mcap_writer.add_message(
        channel_id=complex_channel_id,
        log_time=i * 1000,
        data=complex_message.SerializeToString(),
        publish_time=i * 1000,
    )

mcap_writer.finish()
output.close()

MCAP protobuf decoding example

from mcap.mcap0.stream_reader import StreamReader
from mcap_protobuf.decoder import Decoder

reader = StreamReader("my_data.mcap")
decoder = Decoder(reader)
for m in decoder.messages:
    print(m)

Stay in touch

Join our Slack channel to ask questions, share feedback, and stay up to date on what our team is working on.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcap-protobuf-support-0.0.4.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcap_protobuf_support-0.0.4-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file mcap-protobuf-support-0.0.4.tar.gz.

File metadata

  • Download URL: mcap-protobuf-support-0.0.4.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.11

File hashes

Hashes for mcap-protobuf-support-0.0.4.tar.gz
Algorithm Hash digest
SHA256 880b051844e291253e21ff57ba15b7d5cdb7821173be006cbd6816193ecc5316
MD5 b446c9f74e90d21e9276027230f6d310
BLAKE2b-256 71b48edee3d95b03d367e021472c604ce845c71674e472d9ef0fb99847f42723

See more details on using hashes here.

File details

Details for the file mcap_protobuf_support-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: mcap_protobuf_support-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.11

File hashes

Hashes for mcap_protobuf_support-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 84ef70e351764dd9bfc197a03b25abef1bcaaa6c6e8e28e2a7f63a5e6f9a7375
MD5 ee7461acc7dddf9672e1ac6c5313c7c6
BLAKE2b-256 42ac43db3090353b73170d5db3e8ef583884df006f042e20a2474361a414bcb6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page