Commit 9ea37e48 authored by Jan Varga's avatar Jan Varga
Browse files

Bug 1350637 - Part 3: Move mozilla::dom::Optional serialization helper to...

Bug 1350637 - Part 3: Move mozilla::dom::Optional serialization helper to ipc/glue/IPCMessageUtils.h to make it available to other consumers; r=billm
parent c186d54b
Loading
Loading
Loading
Loading
+0 −36
Original line number Diff line number Diff line
@@ -16,42 +16,6 @@ typedef mozilla::dom::Sequence<nsString> WebrtcGlobalLog;

namespace IPC {

template<typename T>
struct ParamTraits<mozilla::dom::Optional<T>>
{
  typedef mozilla::dom::Optional<T> paramType;

  static void Write(Message* aMsg, const paramType& aParam)
  {
    if (aParam.WasPassed()) {
      WriteParam(aMsg, true);
      WriteParam(aMsg, aParam.Value());
      return;
    }

    WriteParam(aMsg, false);
  }

  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
  {
    bool was_passed = false;

    if (!ReadParam(aMsg, aIter, &was_passed)) {
      return false;
    }

    aResult->Reset(); //XXX Optional_base seems to reach this point with isSome true.

    if (was_passed) {
      if (!ReadParam(aMsg, aIter, &(aResult->Construct()))) {
        return false;
      }
    }

    return true;
  }
};

template<typename T>
struct ParamTraits<mozilla::dom::Sequence<T>>
{
+36 −0
Original line number Diff line number Diff line
@@ -979,6 +979,42 @@ struct ParamTraits<mozilla::Variant<Ts...>>
  }
};

template<typename T>
struct ParamTraits<mozilla::dom::Optional<T>>
{
  typedef mozilla::dom::Optional<T> paramType;

  static void Write(Message* aMsg, const paramType& aParam)
  {
    if (aParam.WasPassed()) {
      WriteParam(aMsg, true);
      WriteParam(aMsg, aParam.Value());
      return;
    }

    WriteParam(aMsg, false);
  }

  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
  {
    bool wasPassed = false;

    if (!ReadParam(aMsg, aIter, &wasPassed)) {
      return false;
    }

    aResult->Reset();

    if (wasPassed) {
      if (!ReadParam(aMsg, aIter, &aResult->Construct())) {
        return false;
      }
    }

    return true;
  }
};

} /* namespace IPC */

#endif /* __IPC_GLUE_IPCMESSAGEUTILS_H__ */