Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CARLA simulator Carla CompositeSerializer

From Leeroopedia
Knowledge Sources
Domains Sensor, Serialization
Last Updated 2026-02-15 05:00 GMT

Overview

CompositeSerializer is a compile-time type map that dispatches serialization and deserialization of sensor data to the appropriate serializer registered for each sensor type.

Description

The CompositeSerializer template class extends CompileTimeTypeMap and provides a centralized mechanism for mapping CARLA sensor objects to their respective serializers at compile time. When sensor data needs to be serialized, the class looks up the correct serializer based on the sensor type and delegates the operation. For deserialization, it reads the sensor type ID from the raw data header and dispatches to the corresponding serializer using an optimized index-based lookup that the compiler can convert into a jump table.

The class defines an interpreted_type alias (SharedPtr<SensorData>) which represents the result of deserializing any sensor buffer. The Serialize static method uses template argument deduction to find the serializer at compile time, while Deserialize performs a runtime dispatch using std::index_sequence expansion and std::initializer_list to simulate a switch statement over all registered serializer indices.

This class is not intended for direct use; instead, the SensorRegistry type alias should be used, which provides the concrete instantiation with all registered sensor-serializer pairs.

Usage

This class is used internally by the CARLA sensor framework. Developers should use SensorRegistry (which is a typedef of CompositeSerializer with all sensor pairs) to serialize and deserialize sensor data rather than using CompositeSerializer directly.

Code Reference

Source Location

  • Repository: CARLA
  • File: LibCarla/source/carla/sensor/CompositeSerializer.h

Signature

template <typename... Items>
class CompositeSerializer : public CompileTimeTypeMap<Items...> {
public:
    using interpreted_type = SharedPtr<SensorData>;

    template <typename Sensor, typename... Args>
    static Buffer Serialize(Sensor &sensor, Args &&... args);

    static interpreted_type Deserialize(Buffer &&data);
};

Import

#include "carla/sensor/CompositeSerializer.h"

I/O Contract

Inputs

Name Type Required Description
sensor Sensor& Yes Reference to the sensor object to serialize data for
args Args&&... Yes Variadic arguments forwarded to the appropriate serializer
data Buffer&& Yes (Deserialize) Raw buffer containing serialized sensor data with a type ID header

Outputs

Name Type Description
(Serialize result) Buffer Serialized binary buffer containing sensor data with header
(Deserialize result) SharedPtr<SensorData> Shared pointer to a deserialized SensorData-derived object

Usage Examples

// Serialization: typically called internally by sensor framework
// Using SensorRegistry (the concrete CompositeSerializer instantiation)
Buffer serialized = SensorRegistry::Serialize(mySensor, sensorArgs...);

// Deserialization: reconstruct sensor data from a raw buffer
SharedPtr<SensorData> result = SensorRegistry::Deserialize(std::move(buffer));

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment