Patch Detail
Show a patch.
GET /api/1.1/patches/2002/?format=api
{ "id": 2002, "url": "https://patchwork.libcamera.org/api/1.1/patches/2002/?format=api", "web_url": "https://patchwork.libcamera.org/patch/2002/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20190924172503.30864-4-jacopo@jmondi.org>", "date": "2019-09-24T17:24:45", "name": "[libcamera-devel,03/21] libcamera: Implement serialization helper class", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "bdd773531c86f099ecf887962a4fa45b0de3d240", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/2002/mbox/", "series": [ { "id": 506, "url": "https://patchwork.libcamera.org/api/1.1/series/506/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=506", "date": "2019-09-24T17:24:42", "name": "Implement control serialization", "version": 1, "mbox": "https://patchwork.libcamera.org/series/506/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/2002/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/2002/checks/", "tags": {}, "headers": { "Return-Path": "<jacopo@jmondi.org>", "Received": [ "from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net\n\t[217.70.183.195])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9EF7A6237C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 24 Sep 2019 19:23:30 +0200 (CEST)", "from uno.homenet.telecomitalia.it\n\t(host89-248-dynamic.45-213-r.retail.telecomitalia.it [213.45.248.89])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay3-d.mail.gandi.net (Postfix) with ESMTPSA id ACB8E60009\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 24 Sep 2019 17:23:29 +0000 (UTC)" ], "X-Originating-IP": "213.45.248.89", "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 24 Sep 2019 19:24:45 +0200", "Message-Id": "<20190924172503.30864-4-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.23.0", "In-Reply-To": "<20190924172503.30864-1-jacopo@jmondi.org>", "References": "<20190924172503.30864-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 03/21] libcamera: Implement serialization\n\thelper class", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "X-List-Received-Date": "Tue, 24 Sep 2019 17:23:30 -0000" }, "content": "Define and implement a Serializer class which provides static operations\nused to serialize and de-serialize DataValue and DataInfo instances to\nand from a memory buffers.\n\nThe helpers implementation define the binary serialization format to which\ndata are dumped to and restored from.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/include/meson.build | 1 +\n src/libcamera/include/serializer.h | 93 +++++++\n src/libcamera/meson.build | 1 +\n src/libcamera/serializer.cpp | 420 +++++++++++++++++++++++++++++\n 4 files changed, 515 insertions(+)\n create mode 100644 src/libcamera/include/serializer.h\n create mode 100644 src/libcamera/serializer.cpp", "diff": "diff --git a/src/libcamera/include/meson.build b/src/libcamera/include/meson.build\nindex 933be8543a8d..3bec594c3b3d 100644\n--- a/src/libcamera/include/meson.build\n+++ b/src/libcamera/include/meson.build\n@@ -15,6 +15,7 @@ libcamera_headers = files([\n 'message.h',\n 'pipeline_handler.h',\n 'process.h',\n+ 'serializer.h',\n 'thread.h',\n 'utils.h',\n 'v4l2_controls.h',\ndiff --git a/src/libcamera/include/serializer.h b/src/libcamera/include/serializer.h\nnew file mode 100644\nindex 000000000000..19978bc0375f\n--- /dev/null\n+++ b/src/libcamera/include/serializer.h\n@@ -0,0 +1,93 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * serializer.h - Data serializer helpers\n+ */\n+#ifndef __LIBCAMERA_SERIALIZER_H__\n+#define __LIBCAMERA_SERIALIZER_H__\n+\n+#include <cstdint>\n+#include <memory>\n+#include <utility>\n+\n+#include <libcamera/data_value.h>\n+\n+#include \"utils.h\"\n+\n+namespace libcamera {\n+\n+class Serializer\n+{\n+public:\n+\tstatic constexpr unsigned int BLOB_ALIGN_BYTES\t= 8;\n+\tstatic constexpr unsigned int BLOB_ALIGN(size_t s)\n+\t{\n+\t\treturn ALIGN(s, BLOB_ALIGN_BYTES);\n+\t}\n+\n+\t/*\n+\t * These offset define the serialization format.\n+\t * Keep the total headers size 8 bytes aligned.\n+\t */\n+\tstatic constexpr unsigned int VALUE_BLOB_TYPE_OFFS = 4;\n+\tstatic constexpr uint8_t *VALUE_BLOB_TYPE(uint8_t *b)\n+\t{\n+\n+\t\treturn b + VALUE_BLOB_TYPE_OFFS;\n+\t}\n+\n+\tstatic constexpr unsigned int VALUE_BLOB_SIZE_OFFS = 8;\n+\tstatic constexpr uint8_t *VALUE_BLOB_SIZE(uint8_t *b)\n+\t{\n+\t\treturn b + VALUE_BLOB_SIZE_OFFS;\n+\t}\n+\n+\tstatic constexpr unsigned int VALUE_BLOB_DATA_OFFS = 16;\n+\tstatic constexpr uint8_t *VALUE_BLOB_DATA(uint8_t *b)\n+\t{\n+\t\treturn b + VALUE_BLOB_DATA_OFFS;\n+\t}\n+\n+\tstatic constexpr unsigned int INFO_BLOB_TYPE_OFFS = 4;\n+\tstatic constexpr uint8_t *INFO_BLOB_TYPE(uint8_t *b)\n+\t{\n+\t\treturn b + INFO_BLOB_TYPE_OFFS;\n+\t}\n+\n+\tstatic constexpr unsigned int INFO_BLOB_SIZE_OFFS = 8;\n+\tstatic constexpr uint8_t *INFO_BLOB_SIZE(uint8_t *b)\n+\t{\n+\t\treturn b + INFO_BLOB_SIZE_OFFS;\n+\t}\n+\n+\tstatic constexpr unsigned int INFO_BLOB_DATA_OFFS = 16;\n+\tstatic constexpr uint8_t *INFO_BLOB_DATA(uint8_t *b)\n+\t{\n+\t\treturn b + INFO_BLOB_DATA_OFFS;\n+\t}\n+\n+\tusing DataValueTuple = std::tuple<unsigned int, DataValue, size_t>;\n+\tusing DataInfoTuple = std::tuple<unsigned int, DataInfo, size_t>;\n+\n+\tstatic int serialize(unsigned int id, const DataValue &value,\n+\t\t\t uint8_t *buffer);\n+\tstatic DataValueTuple deserializeValue(uint8_t *buffer);\n+\n+\tstatic int serialize(unsigned int id, const DataInfo &info,\n+\t\t\t uint8_t *buffer);\n+\tstatic DataInfoTuple deserializeInfo(uint8_t *buffer);\n+\n+\tstatic unsigned int size(const DataValue &value);\n+\tstatic unsigned int size(const DataInfo &value);\n+\n+private:\n+\tstatic unsigned int dumpValue(const DataValue &value, DataType type,\n+\t\t\t\t uint8_t *b);\n+\tstatic DataValue loadValue(DataType type, uint8_t *b);\n+\tstatic DataInfo loadInfo(DataType type, uint8_t *b);\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_SERIALIZER_H__ */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 973b20269943..0f6f97305e4f 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -28,6 +28,7 @@ libcamera_sources = files([\n 'request.cpp',\n 'signal.cpp',\n 'serializable.cpp',\n+ 'serializer.cpp',\n 'stream.cpp',\n 'thread.cpp',\n 'timer.cpp',\ndiff --git a/src/libcamera/serializer.cpp b/src/libcamera/serializer.cpp\nnew file mode 100644\nindex 000000000000..d624d277434b\n--- /dev/null\n+++ b/src/libcamera/serializer.cpp\n@@ -0,0 +1,420 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * serializer.h - Data serializer helpers\n+ */\n+\n+#include \"serializer.h\"\n+\n+#include <utility>\n+\n+#include <libcamera/data_value.h>\n+\n+/**\n+ * \\file serializer.h\n+ * \\brief Helper class for serialization of values and information\n+ */\n+\n+namespace libcamera {\n+\n+/**\n+ * \\class Serializer\n+ * \\brief Helper class that provides operations to serialize values and\n+ * information to memory buffers\n+ *\n+ * The Serializer class provides helper methods to serialize to binary format\n+ * DataValue and DataInfo associated with a numerical identifier.\n+ *\n+ * A data is serialized to a memory buffer using the serialize() operation. It\n+ * is responsability of the caller to provide a pointer to an opportunely\n+ * allocated memory area, with enough space reserved to contain the whole data\n+ * blob representation. The memory size required to contain all serialized data\n+ * could be esitameted by using the size() operation when iterating on them.\n+ */\n+\n+/**\n+ * \\var Serializer::BLOB_ALIGN_BYTES\n+ * \\brief The blob alignement, in bytes\n+ */\n+\n+/**\n+ * \\fn Serializer::BLOB_ALIGN()\n+ * \\brief Align a size \\a s to BLOB_ALIGN_BYTES\n+ * \\param[in] s The size to align\n+ * \\return Size \\a s aligned to BLOB_ALIGN_BYTES\n+ */\n+\n+/**\n+ * \\var Serializer::VALUE_BLOB_TYPE_OFFS\n+ * \\brief The offset from the blob start where the value type is encoded\n+ */\n+\n+/**\n+ * \\fn Serializer::VALUE_BLOB_TYPE()\n+ * \\brief Return the memory location where the value type is encoded in buffer\n+ * \\a b\n+ * \\param[in] b The memory buffer containing a serialized value\n+ * \\return The memory location in buffer \\b where the type information is\n+ * encoded\n+ */\n+\n+/**\n+ * \\var Serializer::VALUE_BLOB_SIZE_OFFS\n+ * \\brief The offset from the blob start where the value size is encoded\n+ */\n+\n+/**\n+ * \\fn Serializer::VALUE_BLOB_SIZE()\n+ * \\brief Return the memory location where the value size is encoded in buffer\n+ * \\a b\n+ * \\param[in] b The memory buffer containing a serialized value\n+ * \\return The memory location in buffer \\b where the size information is\n+ * encoded\n+ */\n+\n+/**\n+ * \\var Serializer::VALUE_BLOB_DATA_OFFS\n+ * \\brief The offset from the blob start where the value data is encoded\n+ */\n+\n+/**\n+ * \\fn Serializer::VALUE_BLOB_DATA()\n+ * \\brief Return the memory location where the value data is encoded in buffer\n+ * \\a b\n+ * \\param[in] b The memory buffer containing a serialized value\n+ * \\return The memory location in buffer \\b where the data information is\n+ * encoded\n+ */\n+\n+/**\n+ * \\var Serializer::INFO_BLOB_TYPE_OFFS\n+ * \\brief The offset from the blob start where the value type is encoded\n+ */\n+\n+/**\n+ * \\fn Serializer::INFO_BLOB_TYPE()\n+ * \\brief Return the memory location where the value type is encoded in buffer\n+ * \\a b\n+ * \\param[in] b The memory buffer containing a serialized value\n+ * \\return The memory location in buffer \\b where the type information is\n+ * encoded\n+ */\n+\n+/**\n+ * \\var Serializer::INFO_BLOB_SIZE_OFFS\n+ * \\brief The offset from the blob start where the value size is encoded\n+ */\n+\n+/**\n+ * \\fn Serializer::INFO_BLOB_SIZE()\n+ * \\brief Return the memory location where the value size is encoded in buffer\n+ * \\a b\n+ * \\param[in] b The memory buffer containing a serialized value\n+ * \\return The memory location in buffer \\b where the size information is\n+ * encoded\n+ */\n+\n+/**\n+ * \\var Serializer::INFO_BLOB_DATA_OFFS\n+ * \\brief The offset from the blob start where the value data is encoded\n+ */\n+\n+/**\n+ * \\fn Serializer::INFO_BLOB_DATA()\n+ * \\brief Return the memory location where the value data is encoded in buffer\n+ * \\a b\n+ * \\param[in] b The memory buffer containing a serialized value\n+ * \\return The memory location in buffer \\b where the data information is\n+ * encoded\n+ */\n+\n+/**\n+ * \\typedef Serializer::DataValueTuple\n+ * \\brief A tuple that contains a numeric id, a DataValue and a size\n+ *\n+ * DataTupleValue is used to return the content of a DataValue de-serialization\n+ * operation.\n+ */\n+\n+/**\n+ * \\typedef Serializer::DataInfoTuple\n+ * \\brief A tuple that contains a numeric id, a DataInfo and a size\n+ *\n+ * DataTupleInfo is used to return the content of a DataInfo de-serialization\n+ * operation.\n+ */\n+\n+/**\n+ * \\var Serializer::BLOB_ALIGN_BYTES\n+ * \\brief Memory alignement of the serialized data in bytes\n+ */\n+\n+/**\n+ * \\brief Serialize a data value into a memory buffer\n+ * \\param[in] id The identifier associated with the DataValue\n+ * \\param[in] value The DataValue to serialize\n+ * \\param[in] buffer The memory area where to serialize the data blob\n+ *\n+ * A data value is serialized to the following binary sections:\n+ * - id: the identifier provided to the operation\n+ * - type: the DataType of the DataValue provided to the operation\n+ * - size: the size in bytes of the data contained in the DataValue provided\n+ *\t the operation\n+ * - data: the data contained in the DataValue provided to the operation\n+ * - padding (optional): padding bytes to guarantee alignment to 64-bits\n+ *\t boundary\n+ *\n+ * The data value is serialized to the following binary format:\n+ *\n+ * Bytes\n+ * Offset: 0 4 8 16\t [16 + size]\n+ *\t +----+----+--------+----- ... -----+--- ... ----+\n+ * Entry: | id |type| size | data | padding |\n+ *\t +----+----+--------+----- ... ------+--- ... ---+\n+ *\n+ *\t \\----- HEADER ----\\---- DATA ----\\--- PADDING ---\\\n+ *\n+ * The operation returns the total number of data written into \\a buffer,\n+ * which is guaranteed to be aligned to Serializer::BLOB_ALIGN_BYTES boundary.\n+ *\n+ * The memory buffer pointer \\a b is not advanced during serialization, and is\n+ * responsibility of the caller to advance it using the returned size to the\n+ * next memory location where to serialize data.\n+ *\n+ * \\return The number of bytes written in \\a buffer, or a negative error code\n+ * in case of errors\n+ */\n+int Serializer::serialize(unsigned int id, const DataValue &value,\n+\t\t\t uint8_t *buffer)\n+{\n+\tif (!buffer)\n+\t\treturn -ENOMEM;\n+\n+\tDataType type = value.type();\n+\tuint8_t *b = buffer;\n+\n+\t*reinterpret_cast<int32_t *>(b) = id;\n+\t*reinterpret_cast<int32_t *>(VALUE_BLOB_TYPE(b)) = type;\n+\t*reinterpret_cast<int64_t *>(VALUE_BLOB_SIZE(b)) = BLOB_ALIGN(value.size());\n+\n+\tdumpValue(value, type, VALUE_BLOB_DATA(b));\n+\n+\treturn Serializer::size(value);\n+}\n+\n+/**\n+ * \\brief De-serialize a memory buffer to a tuple containing a DataValue\n+ * \\param[in] buffer The buffer containing data to de-serialize\n+ *\n+ * De-serialize a data value and its associated id from the memory buffer\n+ * \\a b. The de-serialized data are expected to be have been serialized using\n+ * the serialize(unsigned int id, const DataValue &value, uint8_t *buffer)\n+ * operation, which dumps data to the memory in the format known to this\n+ * operation.\n+ *\n+ * The de-serialized data are returned in a tuple which contains:\n+ * - id: the id associated with the de-serialized DataValue\n+ * - value: the de-serialized DataValue\n+ * - size: the size (in bytes) occupied by the serialized data in the memory\n+ *\t buffer\n+ *\n+ * The memory buffer pointer \\a b is not advanced during de-serialization, and\n+ * it is responsibility of the caller to advance it using the returned size to\n+ * the next memory location containing data to de-serialize.\n+ *\n+ * \\return A tuple containing the id associated with the de-serialized data, the\n+ * data value itself and the size of the size of the de-serialized memory area\n+ */\n+Serializer::DataValueTuple Serializer::deserializeValue(uint8_t *buffer)\n+{\n+\tif (!buffer)\n+\t\treturn {};\n+\n+\tuint8_t *b = buffer;\n+\tunsigned int id = *reinterpret_cast<unsigned int *>(b);\n+\tDataType type = *reinterpret_cast<DataType *>(VALUE_BLOB_TYPE(b));\n+\tsize_t size = *reinterpret_cast<size_t *>(VALUE_BLOB_SIZE(b));\n+\n+\tb = VALUE_BLOB_DATA(b);\n+\treturn std::make_tuple<unsigned int, DataValue, size_t>(\n+\t\tstd::forward<unsigned int>(id), loadValue(type, b),\n+\t\tstd::forward<size_t>(size + VALUE_BLOB_DATA_OFFS));\n+}\n+\n+/**\n+ * \\brief Serialize a data info into a memory buffer\n+ * \\param[in] id The identifier associated with the DataValue\n+ * \\param[in] info The DataInfo to serialize\n+ * \\param[in] buffer The memory area where to serialize the data blob\n+ *\n+ * A data info is serialized to the following binary sections:\n+ * - id: the identifier provided to the operation\n+ * - type: the DataType of the data this info refers to\n+ * - size: the size in bytes of the data contained in the DataInfo provided\n+ * to the operation\n+ * - data: the data contained in the DataInfo provided to the operation:\n+ *\t - min (DataValue of type 'type')\n+ *\t - max (DataValue of type 'type')\n+ *\n+ * The data value is serialized to the following binary format:\n+ *\n+ * Bytes\n+ * Offset: 0 4 8 16\t [16 + size]\n+ * +----+----+--------+- ... -+- ... -+\n+ * Entry: | id |type| size | min | max |\n+ * +----+----+--------+- ... -+- ... -+\n+ *\n+ * \\----- HEADER -----\\---- DATA ----\\\n+ *\n+ * The operation returns the total number of data written into \\a buffer,\n+ * which is guaranteed to be aligned to Serializer::BLOB_ALIGN_BYTES boundary.\n+ *\n+ * \\return The number of bytes written in \\a buffer, or a negative error code\n+ * in case of errors\n+ */\n+int Serializer::serialize(unsigned int id, const DataInfo &info,\n+\t\t\t uint8_t *buffer)\n+{\n+\tif (!buffer)\n+\t\treturn -ENOMEM;\n+\n+\tDataType type = info.min().type();\n+\tuint8_t *b = buffer;\n+\n+\t*reinterpret_cast<int32_t *>(b) = id;\n+\t*reinterpret_cast<int32_t *>(INFO_BLOB_TYPE(b)) = type;\n+\t*reinterpret_cast<int64_t *>(INFO_BLOB_SIZE(b)) = BLOB_ALIGN(DataSize[type]) +\n+\t\t\t\t\t\t\t BLOB_ALIGN(DataSize[type]);\n+\n+\tb = INFO_BLOB_DATA(b);\n+\tb += dumpValue(info.min(), type, b);\n+\tb += dumpValue(info.max(), type, b);\n+\n+\treturn Serializer::size(info);\n+}\n+\n+/**\n+ * \\brief De-serialize a memory buffer to a tuple containing a DataInfo\n+ * \\param[in] buffer The buffer containing data to de-serialize\n+ *\n+ * De-serialize a data value and its associated id from the memory buffer\n+ * \\a b. The de-serialized data are expected to be have been serialized using\n+ * the serialize(unsigned int id, const DataInfo &info, uint8_t *buffer)\n+ * operation, which dumps data to the memory in the format known to this\n+ * operation.\n+ *\n+ * The de-serialized data are returned in a tuple which contains:\n+ * - id: the id associated with the de-serialized DataValue\n+ * - info: the de-serialized DataInfo\n+ * - size: the size (in bytes) occupied by the serialized data in the memory\n+ *\t buffer\n+ *\n+ * The memory buffer pointer \\a b is not advanced during de-serialization, and\n+ * it is responsibility of the caller to advance it using the returned size to\n+ * the next memory location containing data to de-serialize.\n+ *\n+ * \\return A tuple containing the id associated with the de-serialized data, the\n+ * data value itself and the size of the size of the de-serialized memory area\n+ */\n+Serializer::DataInfoTuple Serializer::deserializeInfo(uint8_t *buffer)\n+{\n+\tif (!buffer)\n+\t\treturn {};\n+\n+\tuint8_t *b = buffer;\n+\tunsigned int id = *reinterpret_cast<unsigned int *>(b);\n+\tDataType type = *reinterpret_cast<DataType *>((INFO_BLOB_TYPE(b)));\n+\tsize_t size = *reinterpret_cast<size_t *>(INFO_BLOB_SIZE(b));\n+\n+\tb = INFO_BLOB_DATA(b);\n+\treturn std::make_tuple<unsigned int, DataInfo, size_t>(\n+\t\tstd::forward<unsigned int>(id), loadInfo(type, b),\n+\t\tstd::forward<size_t>(size + INFO_BLOB_DATA_OFFS));\n+}\n+\n+/**\n+ * \\brief Calculate the size of the data value once serialized to binary form\n+ *\n+ * Calculate the data value size in bytes comprising header, data and padding\n+ * bytes to guarantee alignement to 64 bits boundary.\n+ *\n+ * The returned size is the actual byte size occupied by the data blob once\n+ * serialized to a memory buffer.\n+ *\n+ * \\return The blob size in bytes, aligned to Serializer::BLOB_ALIGN_BYTES\n+ * boundary\n+ */\n+unsigned int Serializer::size(const DataValue &value)\n+{\n+\treturn VALUE_BLOB_DATA_OFFS + BLOB_ALIGN(value.size());\n+}\n+\n+/**\n+ * \\brief Calculate the size of the data info once serialized to binary form\n+ *\n+ * Calculate the data info size in bytes comprising header, data and padding\n+ * bytes to guarantee alignement to 64 bits boundary.\n+ *\n+ * The returned size is the actual byte size occupied by the data blob once\n+ * serialized to a memory buffer.\n+ *\n+ * \\return The blob size in bytes, aligned to Serializer::BLOB_ALIGN_BYTES\n+ * boundary\n+ */\n+unsigned int Serializer::size(const DataInfo &info)\n+{\n+\t/*\n+\t * Header is aligned as well as the transported data\n+\t *\n+\t * \\todo If any non-DataValue field is added to DataInfo, the\n+\t * total size of the serialized package should be aligned with the\n+\t * ALIGN() macro.\n+\t */\n+\tDataType type = info.min().type();\n+\treturn INFO_BLOB_DATA_OFFS + BLOB_ALIGN(DataSize[type]) +\n+\t BLOB_ALIGN(DataSize[type]);\n+}\n+\n+unsigned int Serializer::dumpValue(const DataValue &value, DataType type,\n+\t\t\t\t uint8_t *b)\n+{\n+\tswitch (type) {\n+\tcase DataTypeBool:\n+\t\t*reinterpret_cast<bool *>(b) = value.getBool();\n+\t\tbreak;\n+\tcase DataTypeInteger:\n+\t\t*reinterpret_cast<int32_t *>(b) = value.getInt();\n+\t\tbreak;\n+\tcase DataTypeInteger64:\n+\t\t*reinterpret_cast<int64_t *>(b) = value.getInt64();\n+\t\tbreak;\n+\tdefault:\n+\t\t*b = 0;\n+\t\tbreak;\n+\t}\n+\n+\treturn DataSize[type];\n+}\n+\n+DataValue Serializer::loadValue(DataType type, uint8_t *b)\n+{\n+\tswitch (type) {\n+\tcase DataTypeBool:\n+\t\treturn DataValue(*reinterpret_cast<bool *>(b));\n+\tcase DataTypeInteger:\n+\t\treturn DataValue(*reinterpret_cast<int *>(b));\n+\tcase DataTypeInteger64:\n+\t\treturn DataValue(*reinterpret_cast<int64_t *>(b));\n+\tdefault:\n+\t\treturn DataValue();\n+\t}\n+}\n+\n+DataInfo Serializer::loadInfo(DataType type, uint8_t *b)\n+{\n+\treturn DataInfo(loadValue(type, b),\n+\t\t\tloadValue(type, b + BLOB_ALIGN(DataSize[type])));\n+}\n+\n+} /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "03/21" ] }