SerializationHelpers.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* -*- Mode: C++; tab-width: 8; 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 file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_indexeddb_serializationhelpers_h__
  6. #define mozilla_dom_indexeddb_serializationhelpers_h__
  7. #include "ipc/IPCMessageUtils.h"
  8. #include "mozilla/dom/indexedDB/Key.h"
  9. #include "mozilla/dom/indexedDB/KeyPath.h"
  10. #include "mozilla/dom/IDBCursor.h"
  11. #include "mozilla/dom/IDBTransaction.h"
  12. namespace IPC {
  13. template <>
  14. struct ParamTraits<mozilla::dom::indexedDB::StructuredCloneFile::FileType> :
  15. public ContiguousEnumSerializer<
  16. mozilla::dom::indexedDB::StructuredCloneFile::FileType,
  17. mozilla::dom::indexedDB::StructuredCloneFile::eBlob,
  18. mozilla::dom::indexedDB::StructuredCloneFile::eEndGuard>
  19. { };
  20. template <>
  21. struct ParamTraits<mozilla::dom::indexedDB::Key>
  22. {
  23. typedef mozilla::dom::indexedDB::Key paramType;
  24. static void Write(Message* aMsg, const paramType& aParam)
  25. {
  26. WriteParam(aMsg, aParam.mBuffer);
  27. }
  28. static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
  29. {
  30. return ReadParam(aMsg, aIter, &aResult->mBuffer);
  31. }
  32. static void Log(const paramType& aParam, std::wstring* aLog)
  33. {
  34. LogParam(aParam.mBuffer, aLog);
  35. }
  36. };
  37. template <>
  38. struct ParamTraits<mozilla::dom::indexedDB::KeyPath::KeyPathType> :
  39. public ContiguousEnumSerializer<mozilla::dom::indexedDB::KeyPath::KeyPathType,
  40. mozilla::dom::indexedDB::KeyPath::NONEXISTENT,
  41. mozilla::dom::indexedDB::KeyPath::ENDGUARD>
  42. { };
  43. template <>
  44. struct ParamTraits<mozilla::dom::indexedDB::KeyPath>
  45. {
  46. typedef mozilla::dom::indexedDB::KeyPath paramType;
  47. static void Write(Message* aMsg, const paramType& aParam)
  48. {
  49. WriteParam(aMsg, aParam.mType);
  50. WriteParam(aMsg, aParam.mStrings);
  51. }
  52. static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
  53. {
  54. return ReadParam(aMsg, aIter, &aResult->mType) &&
  55. ReadParam(aMsg, aIter, &aResult->mStrings);
  56. }
  57. static void Log(const paramType& aParam, std::wstring* aLog)
  58. {
  59. LogParam(aParam.mStrings, aLog);
  60. }
  61. };
  62. template <>
  63. struct ParamTraits<mozilla::dom::IDBCursor::Direction> :
  64. public ContiguousEnumSerializer<
  65. mozilla::dom::IDBCursor::Direction,
  66. mozilla::dom::IDBCursor::NEXT,
  67. mozilla::dom::IDBCursor::DIRECTION_INVALID>
  68. { };
  69. template <>
  70. struct ParamTraits<mozilla::dom::IDBTransaction::Mode> :
  71. public ContiguousEnumSerializer<
  72. mozilla::dom::IDBTransaction::Mode,
  73. mozilla::dom::IDBTransaction::READ_ONLY,
  74. mozilla::dom::IDBTransaction::MODE_INVALID>
  75. { };
  76. } // namespace IPC
  77. #endif // mozilla_dom_indexeddb_serializationhelpers_h__