12 #include <type_traits> 33 std::enable_if_t<std::is_arithmetic_v<T>> * =
nullptr>
34 void appendPOD(std::vector<uint8_t> &vec, T val)
36 constexpr
size_t byteWidth =
sizeof(val);
37 vec.resize(vec.size() + byteWidth);
38 memcpy(&*(vec.end() - byteWidth), &val, byteWidth);
42 std::enable_if_t<std::is_arithmetic_v<T>> * =
nullptr>
43 T readPOD(std::vector<uint8_t>::const_iterator it,
size_t pos,
44 std::vector<uint8_t>::const_iterator end)
49 memcpy(&ret, &(*(it + pos)),
sizeof(ret));
55 std::enable_if_t<std::is_arithmetic_v<T>> * =
nullptr>
56 T readPOD(std::vector<uint8_t> &vec,
size_t pos)
58 return readPOD<T>(vec.cbegin(), pos, vec.end());
67 static std::tuple<std::vector<uint8_t>, std::vector<SharedFD>>
70 static T
deserialize(
const std::vector<uint8_t> &data,
72 static T
deserialize(std::vector<uint8_t>::const_iterator dataBegin,
73 std::vector<uint8_t>::const_iterator dataEnd,
76 static T
deserialize(
const std::vector<uint8_t> &data,
77 const std::vector<SharedFD> &fds,
79 static T
deserialize(std::vector<uint8_t>::const_iterator dataBegin,
80 std::vector<uint8_t>::const_iterator dataEnd,
81 std::vector<SharedFD>::const_iterator fdsBegin,
82 std::vector<SharedFD>::const_iterator fdsEnd,
105 static std::tuple<std::vector<uint8_t>, std::vector<SharedFD>>
108 std::vector<uint8_t> dataVec;
109 std::vector<SharedFD> fdsVec;
112 uint32_t vecLen = data.size();
113 appendPOD<uint32_t>(dataVec, vecLen);
116 for (
auto const &it : data) {
117 std::vector<uint8_t> dvec;
118 std::vector<SharedFD> fvec;
120 std::tie(dvec, fvec) =
123 appendPOD<uint32_t>(dataVec, dvec.size());
124 appendPOD<uint32_t>(dataVec, fvec.size());
126 dataVec.insert(dataVec.end(), dvec.begin(), dvec.end());
127 fdsVec.insert(fdsVec.end(), fvec.begin(), fvec.end());
130 return { dataVec, fdsVec };
135 return deserialize(data.cbegin(), data.cend(), cs);
138 static std::vector<V>
deserialize(std::vector<uint8_t>::const_iterator dataBegin,
139 std::vector<uint8_t>::const_iterator dataEnd,
142 std::vector<SharedFD> fds;
143 return deserialize(dataBegin, dataEnd, fds.cbegin(), fds.cend(), cs);
146 static std::vector<V>
deserialize(std::vector<uint8_t> &data, std::vector<SharedFD> &fds,
149 return deserialize(data.cbegin(), data.cend(), fds.cbegin(), fds.cend(), cs);
152 static std::vector<V>
deserialize(std::vector<uint8_t>::const_iterator dataBegin,
153 std::vector<uint8_t>::const_iterator dataEnd,
154 std::vector<SharedFD>::const_iterator fdsBegin,
155 [[maybe_unused]] std::vector<SharedFD>::const_iterator fdsEnd,
158 uint32_t vecLen = readPOD<uint32_t>(dataBegin, 0, dataEnd);
159 std::vector<V> ret(vecLen);
161 std::vector<uint8_t>::const_iterator dataIter = dataBegin + 4;
162 std::vector<SharedFD>::const_iterator fdIter = fdsBegin;
163 for (uint32_t i = 0; i < vecLen; i++) {
164 uint32_t sizeofData = readPOD<uint32_t>(dataIter, 0, dataEnd);
165 uint32_t sizeofFds = readPOD<uint32_t>(dataIter, 4, dataEnd);
169 dataIter + sizeofData,
174 dataIter += sizeofData;
198 template<
typename K,
typename V>
202 static std::tuple<std::vector<uint8_t>, std::vector<SharedFD>>
205 std::vector<uint8_t> dataVec;
206 std::vector<SharedFD> fdsVec;
209 uint32_t mapLen = data.size();
210 appendPOD<uint32_t>(dataVec, mapLen);
213 for (
auto const &it : data) {
214 std::vector<uint8_t> dvec;
215 std::vector<SharedFD> fvec;
217 std::tie(dvec, fvec) =
220 appendPOD<uint32_t>(dataVec, dvec.size());
221 appendPOD<uint32_t>(dataVec, fvec.size());
223 dataVec.insert(dataVec.end(), dvec.begin(), dvec.end());
224 fdsVec.insert(fdsVec.end(), fvec.begin(), fvec.end());
226 std::tie(dvec, fvec) =
229 appendPOD<uint32_t>(dataVec, dvec.size());
230 appendPOD<uint32_t>(dataVec, fvec.size());
232 dataVec.insert(dataVec.end(), dvec.begin(), dvec.end());
233 fdsVec.insert(fdsVec.end(), fvec.begin(), fvec.end());
236 return { dataVec, fdsVec };
241 return deserialize(data.cbegin(), data.cend(), cs);
244 static std::map<K, V>
deserialize(std::vector<uint8_t>::const_iterator dataBegin,
245 std::vector<uint8_t>::const_iterator dataEnd,
248 std::vector<SharedFD> fds;
249 return deserialize(dataBegin, dataEnd, fds.cbegin(), fds.cend(), cs);
252 static std::map<K, V>
deserialize(std::vector<uint8_t> &data, std::vector<SharedFD> &fds,
255 return deserialize(data.cbegin(), data.cend(), fds.cbegin(), fds.cend(), cs);
258 static std::map<K, V>
deserialize(std::vector<uint8_t>::const_iterator dataBegin,
259 std::vector<uint8_t>::const_iterator dataEnd,
260 std::vector<SharedFD>::const_iterator fdsBegin,
261 [[maybe_unused]] std::vector<SharedFD>::const_iterator fdsEnd,
266 uint32_t mapLen = readPOD<uint32_t>(dataBegin, 0, dataEnd);
268 std::vector<uint8_t>::const_iterator dataIter = dataBegin + 4;
269 std::vector<SharedFD>::const_iterator fdIter = fdsBegin;
270 for (uint32_t i = 0; i < mapLen; i++) {
271 uint32_t sizeofData = readPOD<uint32_t>(dataIter, 0, dataEnd);
272 uint32_t sizeofFds = readPOD<uint32_t>(dataIter, 4, dataEnd);
276 dataIter + sizeofData,
281 dataIter += sizeofData;
283 sizeofData = readPOD<uint32_t>(dataIter, 0, dataEnd);
284 sizeofFds = readPOD<uint32_t>(dataIter, 4, dataEnd);
288 dataIter + sizeofData,
292 ret.insert({ key, value });
294 dataIter += sizeofData;
307 static std::tuple<std::vector<uint8_t>, std::vector<SharedFD>>
310 std::vector<uint8_t> dataVec;
312 appendPOD<uint32_t>(dataVec,
static_cast<typename
Flags<E>::Type>(data));
314 return { dataVec, {} };
324 std::vector<uint8_t>::const_iterator dataEnd,
327 return Flags<E>{
static_cast<E
>(readPOD<uint32_t>(dataBegin, 0, dataEnd)) };
331 [[maybe_unused]] std::vector<SharedFD> &fds,
338 std::vector<uint8_t>::const_iterator dataEnd,
339 [[maybe_unused]] std::vector<SharedFD>::const_iterator fdsBegin,
340 [[maybe_unused]] std::vector<SharedFD>::const_iterator fdsEnd,
Camera controls identifiers.
Image Processing Algorithm interface.
Top-level libcamera namespace.
Definition: backtrace.h:17
#define ASSERT(condition)
Abort program execution if assertion fails.
#define LOG_DECLARE_CATEGORY(name)
Declare a category of log messages.
Serializer and deserializer for control-related classes.
Definition: control_serializer.h:20
std::underlying_type_t< E > Type
The underlying data type of the enum.
Definition: flags.h:21
static T deserialize(const std::vector< uint8_t > &data, ControlSerializer *cs=nullptr)
Deserialize byte vector into an object.
IPA Data Serializer.
Definition: ipa_data_serializer.h:64
static std::tuple< std::vector< uint8_t >, std::vector< SharedFD > > serialize(const T &data, ControlSerializer *cs=nullptr)
Serialize an object into byte vector and fd vector.
Type-safe container for enum-based bitfields.
Definition: flags.h:15
Data structures related to geometric objects.
Serialization and deserialization helpers for controls.