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.
Metadata
Release files for mcap-protobuf-support 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mcap-protobuf-support-0.0.4.tar.gz | 8.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mcap_protobuf_support-0.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.5 kB
Release files / mcap-protobuf-support-0.0.4.tar.gz
| Download URL | mcap-protobuf-support-0.0.4.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
880b051844e291253e21ff57ba15b7d5cdb7821173be006cbd6816193ecc5316
|
|
BLAKE2b-256 checksum How to use checksums |
71b48edee3d95b03d367e021472c604ce845c71674e472d9ef0fb99847f42723
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / mcap_protobuf_support-0.0.4-py3-none-any.whl
| Download URL | mcap_protobuf_support-0.0.4-py3-none-any.whl |
|---|---|
| Size | 10.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
84ef70e351764dd9bfc197a03b25abef1bcaaa6c6e8e28e2a7f63a5e6f9a7375
|
|
BLAKE2b-256 checksum How to use checksums |
42ac43db3090353b73170d5db3e8ef583884df006f042e20a2474361a414bcb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|