Message ID | 20220803112150.3040287-5-paul.elder@ideasonboard.com |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Paul, Thank you for the patch. On Wed, Aug 03, 2022 at 08:21:45PM +0900, Paul Elder via libcamera-devel wrote: > Implement an IPADataSerializer for Flags. > > Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> > --- > .../libcamera/internal/ipa_data_serializer.h | 48 +++++++++++++++++++ > 1 file changed, 48 insertions(+) > > diff --git a/include/libcamera/internal/ipa_data_serializer.h b/include/libcamera/internal/ipa_data_serializer.h > index 30bdaebc..3645da4c 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,53 @@ 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, data.value_); 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.end()); > + } > + > + static Flags<E> deserialize(std::vector<uint8_t>::const_iterator dataBegin, > + std::vector<uint8_t>::const_iterator dataEnd, > + [[maybe_unused]] ControlSerializer *cs = nullptr) > + { > + Flags<E> ret; > + ret.value_ = readPOD<uint32_t>(dataBegin, 0, dataEnd); > + return ret; And here, return Flags<E>{ static_cast<E>(readPOD<uint32_t>(dataBegin, 0, dataEnd)) }; That should take care of the friends statement hopefully. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > + } > + > + 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.end()); > + } > + > + 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 */
diff --git a/include/libcamera/internal/ipa_data_serializer.h b/include/libcamera/internal/ipa_data_serializer.h index 30bdaebc..3645da4c 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,53 @@ 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, data.value_); + + return { dataVec, {} }; + } + + static Flags<E> deserialize(std::vector<uint8_t> &data, + [[maybe_unused]] ControlSerializer *cs = nullptr) + { + return deserialize(data.cbegin(), data.end()); + } + + static Flags<E> deserialize(std::vector<uint8_t>::const_iterator dataBegin, + std::vector<uint8_t>::const_iterator dataEnd, + [[maybe_unused]] ControlSerializer *cs = nullptr) + { + Flags<E> ret; + ret.value_ = readPOD<uint32_t>(dataBegin, 0, dataEnd); + return ret; + } + + 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.end()); + } + + 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 */
Implement an IPADataSerializer for Flags. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> --- .../libcamera/internal/ipa_data_serializer.h | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+)