Message ID | 20221011105859.457567-4-paul.elder@ideasonboard.com |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
Hi Paul On Tue, Oct 11, 2022 at 07:58:53PM +0900, Paul Elder via libcamera-devel wrote: > Implement an IPADataSerializer for Flags. > > Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > --- > No change in v5 > > No change in v4 > > No change in v3 > > Changes in v2: > - use Flags's Type cast to avoid friend class > --- > .../libcamera/internal/ipa_data_serializer.h | 46 +++++++++++++++++++ > 1 file changed, 46 insertions(+) > > diff --git a/include/libcamera/internal/ipa_data_serializer.h b/include/libcamera/internal/ipa_data_serializer.h > index 30bdaebc..981d2f5c 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.end()); nit: deserialize() wants a "std::vector<uint8_t>::const_iterator dataEnd". Should you use cend()? This apart Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Thanks j > + } > + > + 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.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 */ > -- > 2.30.2 >
Hi Jacopo, On Wed, Oct 12, 2022 at 09:23:45AM +0200, Jacopo Mondi wrote: > Hi Paul > > On Tue, Oct 11, 2022 at 07:58:53PM +0900, Paul Elder via libcamera-devel wrote: > > Implement an IPADataSerializer for Flags. > > > > Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> > > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > > > --- > > No change in v5 > > > > No change in v4 > > > > No change in v3 > > > > Changes in v2: > > - use Flags's Type cast to avoid friend class > > --- > > .../libcamera/internal/ipa_data_serializer.h | 46 +++++++++++++++++++ > > 1 file changed, 46 insertions(+) > > > > diff --git a/include/libcamera/internal/ipa_data_serializer.h b/include/libcamera/internal/ipa_data_serializer.h > > index 30bdaebc..981d2f5c 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.end()); > > nit: deserialize() wants a "std::vector<uint8_t>::const_iterator dataEnd". > Should you use cend()? Yeah, I should :S Thanks, Paul > > This apart > Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> > > > + } > > + > > + 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.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 */ > > -- > > 2.30.2 > >
diff --git a/include/libcamera/internal/ipa_data_serializer.h b/include/libcamera/internal/ipa_data_serializer.h index 30bdaebc..981d2f5c 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.end()); + } + + 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.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 */