1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 #ifndef COMMONAPI_DBUS_SERIALIZABLE_ARGUMENTS_H_
5 #define COMMONAPI_DBUS_SERIALIZABLE_ARGUMENTS_H_
7 #include "DBusInputStream.h"
8 #include "DBusOutputStream.h"
13 template <typename... _Arguments>
14 struct DBusSerializableArguments;
17 struct DBusSerializableArguments<> {
18 static inline bool serialize(OutputStream& outputStream) {
22 static inline bool deserialize(DBusInputStream& inputStream) {
27 template <typename _ArgumentType>
28 struct DBusSerializableArguments<_ArgumentType> {
29 static inline bool serialize(OutputStream& outputStream, const _ArgumentType& argument) {
30 outputStream << argument;
31 return !outputStream.hasError();
34 static inline bool deserialize(DBusInputStream& inputStream, _ArgumentType& argument) {
35 inputStream >> argument;
36 return !inputStream.hasError();
40 template <typename _ArgumentType, typename ... _Rest>
41 struct DBusSerializableArguments<_ArgumentType, _Rest...> {
42 static inline bool serialize(OutputStream& outputStream, const _ArgumentType& argument, const _Rest&... rest) {
43 outputStream << argument;
44 const bool success = !outputStream.hasError();
45 return success ? DBusSerializableArguments<_Rest...>::serialize(outputStream, rest...) : false;
48 static inline bool deserialize(DBusInputStream& inputStream, _ArgumentType& argument, _Rest&... rest) {
49 inputStream >> argument;
50 const bool success = !inputStream.hasError();
51 return success ? DBusSerializableArguments<_Rest...>::deserialize(inputStream, rest...) : false;
56 } // namespace CommonAPI
58 #endif // COMMONAPI_DBUS_SERIALIZABLE_ARGUMENTS_H_