Program Listing for File ProtoSerializable.hpp

Return to documentation for file (include/depthai/utility/ProtoSerializable.hpp)

#pragma once

#include <cstdint>
#include <string>
#include <vector>

namespace dai {

class ProtoSerializable {
   public:
    struct SchemaPair {
        std::string schemaName;
        std::string schema;
    };

    virtual ~ProtoSerializable();

#ifdef DEPTHAI_ENABLE_PROTOBUF
    virtual std::vector<std::uint8_t> serializeProto(bool metadataOnly = false) const = 0;

    virtual SchemaPair serializeSchema() const = 0;

#else
    // Helper struct for compile-time check
    template <typename... T>
    struct dependent_false {
        static constexpr bool value = false;
    };

    template <typename... T>
    std::vector<std::uint8_t> serializeProto(T...) const {
        static_assert(dependent_false<T...>::value, "Protobuf support is not enabled in this build");
        return {};
    }

    template <typename... T>
    SchemaPair serializeSchema(T...) const {
        static_assert(dependent_false<T...>::value, "Protobuf support is not enabled in this build");
        return {};
    }
#endif
};

}  // namespace dai