ParamTraits_TiedFields.h (1303B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef MOZILLA_PARAMTRAITS_TIEDFIELDS_H 7 #define MOZILLA_PARAMTRAITS_TIEDFIELDS_H 8 9 #include "TiedFields.h" 10 #include "ipc/IPCMessageUtils.h" 11 12 namespace IPC { 13 14 template <class T> 15 struct ParamTraits_TiedFields { 16 static_assert(mozilla::AssertTiedFieldsAreExhaustive<T>()); 17 18 static void Write(MessageWriter* const writer, const T& in) { 19 const auto& fields = mozilla::TiedFields(in); 20 mozilla::MapTuple(fields, [&](const auto& field) { 21 WriteParam(writer, field); 22 return true; // ignored 23 }); 24 } 25 26 static bool Read(MessageReader* const reader, T* const out) { 27 const auto& fields = mozilla::TiedFields(*out); 28 bool ok = true; 29 mozilla::MapTuple(fields, [&](auto& field) { 30 if (ok) { 31 ok &= ReadParam(reader, &field); 32 } 33 return true; // ignored 34 }); 35 return ok; 36 } 37 }; 38 39 // - 40 41 template <class U, size_t N> 42 struct ParamTraits<mozilla::PaddingField<U, N>> final 43 : public ParamTraits_TiedFields<mozilla::PaddingField<U, N>> {}; 44 45 } // namespace IPC 46 47 #endif