Skip to content
Roboto
Esc
↑↓navigate↵open⌘Jpreview
On this page

roboto.formats.mcap.json_decoder_factory

Module Contents

JsonDecoderFactory

class roboto.formats.mcap.json_decoder_factory.JsonDecoderFactory#View Source

Bases: mcap.decoder.DecoderFactory

Factory for creating JSON message decoders for MCAP readers.

Provides functionality to decode JSON-encoded messages within MCAP files. This decoder factory is used by the MCAP reader to handle messages that were originally encoded in JSON format.

JsonDecoderFactory.decoder_for()

decoder_for(message_encoding, schema)#View Source

Create a decoder function for JSON-encoded messages.

Returns a decoder function if the message encoding is JSON, otherwise returns None to indicate this factory cannot handle the encoding.

Parameters

message_encoding str

The encoding format of the message.

schema Optional[mcap.records.Schema]

Optional schema information for the message.

Returns

Optional[Callable[[bytes], Any]]

A decoder function for JSON messages, or None if the encoding is not JSON.

Usage

factory = JsonDecoderFactory()
decoder = factory.decoder_for(MessageEncoding.JSON, None)
if decoder:
    decoded = decoder(b'{"x": 1.5, "y": 2.0}')
    print(decoded)
# {'x': 1.5, 'y': 2.0}

Was this page helpful?