Bug 1853814 [wpt PR 42017] - LoAF: Expose script URL for promise resolvers, a=testonly
[gecko.git] / dom / localstorage / SerializationHelpers.h
blobf9b499671cf8201aa102ad1e5cb49d1082920aff
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_localstorage_SerializationHelpers_h
8 #define mozilla_dom_localstorage_SerializationHelpers_h
10 #include <string>
11 #include "chrome/common/ipc_message_utils.h"
12 #include "ipc/EnumSerializer.h"
13 #include "mozilla/dom/LSSnapshot.h"
14 #include "mozilla/dom/LSValue.h"
16 namespace IPC {
18 template <>
19 struct ParamTraits<mozilla::dom::LSSnapshot::LoadState>
20 : public ContiguousEnumSerializer<
21 mozilla::dom::LSSnapshot::LoadState,
22 mozilla::dom::LSSnapshot::LoadState::Initial,
23 mozilla::dom::LSSnapshot::LoadState::EndGuard> {};
25 template <>
26 struct ParamTraits<mozilla::dom::LSValue::CompressionType>
27 : public ContiguousEnumSerializer<
28 mozilla::dom::LSValue::CompressionType,
29 mozilla::dom::LSValue::CompressionType::UNCOMPRESSED,
30 mozilla::dom::LSValue::CompressionType::NUM_TYPES> {};
32 static_assert(
33 0u == static_cast<uint8_t>(mozilla::dom::LSValue::ConversionType::NONE));
34 template <>
35 struct ParamTraits<mozilla::dom::LSValue::ConversionType>
36 : public ContiguousEnumSerializer<
37 mozilla::dom::LSValue::ConversionType,
38 mozilla::dom::LSValue::ConversionType::NONE,
39 mozilla::dom::LSValue::ConversionType::NUM_TYPES> {};
41 template <>
42 struct ParamTraits<mozilla::dom::LSValue> {
43 typedef mozilla::dom::LSValue paramType;
45 static void Write(MessageWriter* aWriter, const paramType& aParam) {
46 WriteParam(aWriter, aParam.mBuffer);
47 WriteParam(aWriter, aParam.mUTF16Length);
48 WriteParam(aWriter, aParam.mConversionType);
49 WriteParam(aWriter, aParam.mCompressionType);
52 static bool Read(MessageReader* aReader, paramType* aResult) {
53 return ReadParam(aReader, &aResult->mBuffer) &&
54 ReadParam(aReader, &aResult->mUTF16Length) &&
55 ReadParam(aReader, &aResult->mConversionType) &&
56 ReadParam(aReader, &aResult->mCompressionType);
60 } // namespace IPC
62 #endif // mozilla_dom_localstorage_SerializationHelpers_h