tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SerializationHelpers.h (2280B)


      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/. */
      6 
      7 #ifndef mozilla_dom_localstorage_SerializationHelpers_h
      8 #define mozilla_dom_localstorage_SerializationHelpers_h
      9 
     10 #include "chrome/common/ipc_message_utils.h"
     11 #include "ipc/EnumSerializer.h"
     12 #include "mozilla/dom/LSSnapshot.h"
     13 #include "mozilla/dom/LSValue.h"
     14 
     15 namespace IPC {
     16 
     17 template <>
     18 struct ParamTraits<mozilla::dom::LSSnapshot::LoadState>
     19    : public ContiguousEnumSerializer<
     20          mozilla::dom::LSSnapshot::LoadState,
     21          mozilla::dom::LSSnapshot::LoadState::Initial,
     22          mozilla::dom::LSSnapshot::LoadState::EndGuard> {};
     23 
     24 template <>
     25 struct ParamTraits<mozilla::dom::LSValue::CompressionType>
     26    : public ContiguousEnumSerializer<
     27          mozilla::dom::LSValue::CompressionType,
     28          mozilla::dom::LSValue::CompressionType::UNCOMPRESSED,
     29          mozilla::dom::LSValue::CompressionType::NUM_TYPES> {};
     30 
     31 static_assert(
     32    0u == static_cast<uint8_t>(mozilla::dom::LSValue::ConversionType::NONE));
     33 template <>
     34 struct ParamTraits<mozilla::dom::LSValue::ConversionType>
     35    : public ContiguousEnumSerializer<
     36          mozilla::dom::LSValue::ConversionType,
     37          mozilla::dom::LSValue::ConversionType::NONE,
     38          mozilla::dom::LSValue::ConversionType::NUM_TYPES> {};
     39 
     40 template <>
     41 struct ParamTraits<mozilla::dom::LSValue> {
     42  typedef mozilla::dom::LSValue paramType;
     43 
     44  static void Write(MessageWriter* aWriter, const paramType& aParam) {
     45    WriteParam(aWriter, aParam.mBuffer);
     46    WriteParam(aWriter, aParam.mUTF16Length);
     47    WriteParam(aWriter, aParam.mConversionType);
     48    WriteParam(aWriter, aParam.mCompressionType);
     49  }
     50 
     51  static bool Read(MessageReader* aReader, paramType* aResult) {
     52    return ReadParam(aReader, &aResult->mBuffer) &&
     53           ReadParam(aReader, &aResult->mUTF16Length) &&
     54           ReadParam(aReader, &aResult->mConversionType) &&
     55           ReadParam(aReader, &aResult->mCompressionType);
     56  }
     57 };
     58 
     59 }  // namespace IPC
     60 
     61 #endif  // mozilla_dom_localstorage_SerializationHelpers_h