diff options
author | Paul Elder <paul.elder@ideasonboard.com> | 2022-08-03 19:46:24 +0900 |
---|---|---|
committer | Paul Elder <paul.elder@ideasonboard.com> | 2022-10-18 18:51:25 +0900 |
commit | fc6b5f49e176b7b8750175e2eb37825f5919b6d9 (patch) | |
tree | 70e56019532c79d47ac055ed47d5f2681d666e50 | |
parent | 3f9da2a71ef5ed6fe495576221c5f6394f21e55b (diff) |
libcamera: ipa_data_serializer: Add serializer for Flags
Implement an IPADataSerializer for Flags.
Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
-rw-r--r-- | include/libcamera/internal/ipa_data_serializer.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/include/libcamera/internal/ipa_data_serializer.h b/include/libcamera/internal/ipa_data_serializer.h index 30bdaebc..b4c0f438 100644 --- a/include/libcamera/internal/ipa_data_serializer.h +++ b/include/libcamera/internal/ipa_data_serializer.h @@ -14,6 +14,7 @@ #include <type_traits> #include <vector> +#include <libcamera/base/flags.h> #include <libcamera/base/log.h> #include <libcamera/control_ids.h> @@ -301,6 +302,51 @@ public: } }; +/* Serialization format for Flags is same as for PODs */ +template<typename E> +class IPADataSerializer<Flags<E>> +{ +public: + static std::tuple<std::vector<uint8_t>, std::vector<SharedFD>> + serialize(const Flags<E> &data, [[maybe_unused]] ControlSerializer *cs = nullptr) + { + std::vector<uint8_t> dataVec; + dataVec.reserve(sizeof(Flags<E>)); + appendPOD<uint32_t>(dataVec, static_cast<typename Flags<E>::Type>(data)); + + return { dataVec, {} }; + } + + static Flags<E> deserialize(std::vector<uint8_t> &data, + [[maybe_unused]] ControlSerializer *cs = nullptr) + { + return deserialize(data.cbegin(), data.cend()); + } + + static Flags<E> deserialize(std::vector<uint8_t>::const_iterator dataBegin, + std::vector<uint8_t>::const_iterator dataEnd, + [[maybe_unused]] ControlSerializer *cs = nullptr) + { + return Flags<E>{ static_cast<E>(readPOD<uint32_t>(dataBegin, 0, dataEnd)) }; + } + + static Flags<E> deserialize(std::vector<uint8_t> &data, + [[maybe_unused]] std::vector<SharedFD> &fds, + [[maybe_unused]] ControlSerializer *cs = nullptr) + { + return deserialize(data.cbegin(), data.cend()); + } + + static Flags<E> deserialize(std::vector<uint8_t>::const_iterator dataBegin, + std::vector<uint8_t>::const_iterator dataEnd, + [[maybe_unused]] std::vector<SharedFD>::const_iterator fdsBegin, + [[maybe_unused]] std::vector<SharedFD>::const_iterator fdsEnd, + [[maybe_unused]] ControlSerializer *cs = nullptr) + { + return deserialize(dataBegin, dataEnd); + } +}; + #endif /* __DOXYGEN__ */ } /* namespace libcamera */ |