//
// Automatically generated by ipdlc.
// Edit at your own risk
//


#include "mozilla/ipc/RandomAccessStreamParams.h"

#include "ipc/IPCMessageUtils.h"
#include "ipc/IPCMessageUtilsSpecializations.h"
#include "nsIFile.h"
#include "mozilla/ipc/Endpoint.h"
#include "mozilla/ipc/ProtocolMessageUtils.h"
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/ipc/ShmemMessageUtils.h"
#include "mozilla/ipc/TaintingIPCUtils.h"


//-----------------------------------------------------------------------------
// Method definitions for the IPDL type |struct FileRandomAccessStreamParams|
//
namespace mozilla {
namespace ipc {
} // namespace ipc
} // namespace mozilla

namespace IPC {
auto ParamTraits<::mozilla::ipc::FileRandomAccessStreamParams>::Write(
        IPC::MessageWriter* aWriter,
        const paramType& aVar) -> void
{
    IPC::WriteParam(aWriter, (aVar).fileDescriptor());
    // Sentinel = 'fileDescriptor'
    (aWriter)->WriteSentinel(704972224);
    (aWriter)->WriteBytes((&((aVar).behaviorFlags())), 4);
    // Sentinel = 'behaviorFlags'
    (aWriter)->WriteSentinel(614073662);
}

auto ParamTraits<::mozilla::ipc::FileRandomAccessStreamParams>::Read(IPC::MessageReader* aReader) -> IPC::ReadResult<paramType>
{
    auto maybe___fileDescriptor = IPC::ReadParam<::mozilla::ipc::FileDescriptor>(aReader);
    if (!maybe___fileDescriptor) {
        aReader->FatalError("Error deserializing 'fileDescriptor' (FileDescriptor) member of 'FileRandomAccessStreamParams'");
        return {};

    }
    auto& _fileDescriptor = *maybe___fileDescriptor;
    // Sentinel = 'fileDescriptor'
    if ((!((aReader)->ReadSentinel(704972224)))) {
        mozilla::ipc::SentinelReadError("Error deserializing 'fileDescriptor' (FileDescriptor) member of 'FileRandomAccessStreamParams'");
        return {};
    }
    IPC::ReadResult<paramType> result__{
            std::in_place,
            std::move(_fileDescriptor),
            ::int32_t{0}};
    if ((!((aReader)->ReadBytesInto((&((result__)->behaviorFlags())), 4)))) {
        aReader->FatalError("Error bulk reading fields from int32_t");
        return {};
    }
    // Sentinel = 'behaviorFlags'
    if ((!((aReader)->ReadSentinel(614073662)))) {
        mozilla::ipc::SentinelReadError("Error bulk reading fields from int32_t");
        return {};
    }
    return result__;
}

} // namespace IPC

//-----------------------------------------------------------------------------
// Method definitions for the IPDL type |struct LimitingFileRandomAccessStreamParams|
//
namespace mozilla {
namespace ipc {
} // namespace ipc
} // namespace mozilla

namespace IPC {
auto ParamTraits<::mozilla::ipc::LimitingFileRandomAccessStreamParams>::Write(
        IPC::MessageWriter* aWriter,
        paramType&& aVar) -> void
{
    IPC::WriteParam(aWriter, (aVar).fileRandomAccessStreamParams());
    // Sentinel = 'fileRandomAccessStreamParams'
    (aWriter)->WriteSentinel(2688551716);
    IPC::WriteParam(aWriter, std::move((aVar).quotaObject()));
    // Sentinel = 'quotaObject'
    (aWriter)->WriteSentinel(461046914);
}

auto ParamTraits<::mozilla::ipc::LimitingFileRandomAccessStreamParams>::Read(IPC::MessageReader* aReader) -> IPC::ReadResult<paramType>
{
    auto maybe___fileRandomAccessStreamParams = IPC::ReadParam<::mozilla::ipc::FileRandomAccessStreamParams>(aReader);
    if (!maybe___fileRandomAccessStreamParams) {
        aReader->FatalError("Error deserializing 'fileRandomAccessStreamParams' (FileRandomAccessStreamParams) member of 'LimitingFileRandomAccessStreamParams'");
        return {};

    }
    auto& _fileRandomAccessStreamParams = *maybe___fileRandomAccessStreamParams;
    // Sentinel = 'fileRandomAccessStreamParams'
    if ((!((aReader)->ReadSentinel(2688551716)))) {
        mozilla::ipc::SentinelReadError("Error deserializing 'fileRandomAccessStreamParams' (FileRandomAccessStreamParams) member of 'LimitingFileRandomAccessStreamParams'");
        return {};
    }
    auto maybe___quotaObject = IPC::ReadParam<::mozilla::dom::quota::IPCQuotaObject>(aReader);
    if (!maybe___quotaObject) {
        aReader->FatalError("Error deserializing 'quotaObject' (IPCQuotaObject) member of 'LimitingFileRandomAccessStreamParams'");
        return {};

    }
    auto& _quotaObject = *maybe___quotaObject;
    // Sentinel = 'quotaObject'
    if ((!((aReader)->ReadSentinel(461046914)))) {
        mozilla::ipc::SentinelReadError("Error deserializing 'quotaObject' (IPCQuotaObject) member of 'LimitingFileRandomAccessStreamParams'");
        return {};
    }
    IPC::ReadResult<paramType> result__{
            std::in_place,
            std::move(_fileRandomAccessStreamParams),
            std::move(_quotaObject)};
    return result__;
}

} // namespace IPC

//-----------------------------------------------------------------------------
// Method definitions for the IPDL type |union RandomAccessStreamParams|
//
namespace mozilla {
namespace ipc {
auto RandomAccessStreamParams::MaybeDestroy() -> void
{
    if ((mType) == (T__None)) {
        return;
    }
    switch (mType) {
    case TFileRandomAccessStreamParams:
        {
            (ptr_FileRandomAccessStreamParams())->~FileRandomAccessStreamParams__tdef();
            break;
        }
    case TLimitingFileRandomAccessStreamParams:
        {
            (ptr_LimitingFileRandomAccessStreamParams())->~LimitingFileRandomAccessStreamParams__tdef();
            break;
        }
    default:
        {
            mozilla::ipc::LogicError("not reached");
            break;
        }
    }
}

MOZ_IMPLICIT RandomAccessStreamParams::RandomAccessStreamParams(const FileRandomAccessStreamParams& aOther)
{
    new (mozilla::KnownNotNull, ptr_FileRandomAccessStreamParams()) FileRandomAccessStreamParams(aOther);
    mType = TFileRandomAccessStreamParams;
}

MOZ_IMPLICIT RandomAccessStreamParams::RandomAccessStreamParams(FileRandomAccessStreamParams&& aOther)
{
    new (mozilla::KnownNotNull, ptr_FileRandomAccessStreamParams()) FileRandomAccessStreamParams(std::move(aOther));
    mType = TFileRandomAccessStreamParams;
}

MOZ_IMPLICIT RandomAccessStreamParams::RandomAccessStreamParams(LimitingFileRandomAccessStreamParams&& aOther)
{
    new (mozilla::KnownNotNull, ptr_LimitingFileRandomAccessStreamParams()) LimitingFileRandomAccessStreamParams(std::move(aOther));
    mType = TLimitingFileRandomAccessStreamParams;
}

MOZ_IMPLICIT RandomAccessStreamParams::RandomAccessStreamParams(RandomAccessStreamParams&& aOther)
{
    (aOther).AssertSanity();
    Type t = (aOther).type();
    switch (t) {
    case TFileRandomAccessStreamParams:
        {
            new (mozilla::KnownNotNull, ptr_FileRandomAccessStreamParams()) FileRandomAccessStreamParams(std::move((aOther).get_FileRandomAccessStreamParams()));
            (aOther).MaybeDestroy();
            break;
        }
    case TLimitingFileRandomAccessStreamParams:
        {
            new (mozilla::KnownNotNull, ptr_LimitingFileRandomAccessStreamParams()) LimitingFileRandomAccessStreamParams(std::move((aOther).get_LimitingFileRandomAccessStreamParams()));
            (aOther).MaybeDestroy();
            break;
        }
    case T__None:
        {
            break;
        }
    default:
        {
            mozilla::ipc::LogicError("unreached");
            return;
        }
    }
    (aOther).mType = T__None;
    mType = t;
}

RandomAccessStreamParams::~RandomAccessStreamParams()
{
    MaybeDestroy();
}

auto RandomAccessStreamParams::operator=(const FileRandomAccessStreamParams& aRhs) -> RandomAccessStreamParams&
{
    MaybeDestroy();
    new (mozilla::KnownNotNull, ptr_FileRandomAccessStreamParams()) FileRandomAccessStreamParams(aRhs);
    mType = TFileRandomAccessStreamParams;
    return (*(this));
}

auto RandomAccessStreamParams::operator=(FileRandomAccessStreamParams&& aRhs) -> RandomAccessStreamParams&
{
    MaybeDestroy();
    new (mozilla::KnownNotNull, ptr_FileRandomAccessStreamParams()) FileRandomAccessStreamParams(std::move(aRhs));
    mType = TFileRandomAccessStreamParams;
    return (*(this));
}

auto RandomAccessStreamParams::operator=(LimitingFileRandomAccessStreamParams&& aRhs) -> RandomAccessStreamParams&
{
    MaybeDestroy();
    new (mozilla::KnownNotNull, ptr_LimitingFileRandomAccessStreamParams()) LimitingFileRandomAccessStreamParams(std::move(aRhs));
    mType = TLimitingFileRandomAccessStreamParams;
    return (*(this));
}

auto RandomAccessStreamParams::operator=(RandomAccessStreamParams&& aRhs) -> RandomAccessStreamParams&
{
    (aRhs).AssertSanity();
    Type t = (aRhs).type();
    switch (t) {
    case TFileRandomAccessStreamParams:
        {
            MaybeDestroy();
            new (mozilla::KnownNotNull, ptr_FileRandomAccessStreamParams()) FileRandomAccessStreamParams(std::move((aRhs).get_FileRandomAccessStreamParams()));
            (aRhs).MaybeDestroy();
            break;
        }
    case TLimitingFileRandomAccessStreamParams:
        {
            MaybeDestroy();
            new (mozilla::KnownNotNull, ptr_LimitingFileRandomAccessStreamParams()) LimitingFileRandomAccessStreamParams(std::move((aRhs).get_LimitingFileRandomAccessStreamParams()));
            (aRhs).MaybeDestroy();
            break;
        }
    case T__None:
        {
            MaybeDestroy();
            break;
        }
    default:
        {
            mozilla::ipc::LogicError("unreached");
            break;
        }
    }
    (aRhs).mType = T__None;
    mType = t;
    return (*(this));
}

} // namespace ipc
} // namespace mozilla

namespace IPC {
auto ParamTraits<::mozilla::ipc::RandomAccessStreamParams>::Write(
        IPC::MessageWriter* aWriter,
        paramType&& aVar) -> void
{
    typedef ::mozilla::ipc::RandomAccessStreamParams union__;
    int type = (aVar).type();
    IPC::WriteParam(aWriter, type);
    // Sentinel = 'RandomAccessStreamParams'
    (aWriter)->WriteSentinel(1965820292);

    switch (type) {
    case union__::TFileRandomAccessStreamParams:
        {
            IPC::WriteParam(aWriter, (aVar).get_FileRandomAccessStreamParams());
            // Sentinel = 'TFileRandomAccessStreamParams'
            (aWriter)->WriteSentinel(2789542744);
            return;
        }
    case union__::TLimitingFileRandomAccessStreamParams:
        {
            IPC::WriteParam(aWriter, std::move((aVar).get_LimitingFileRandomAccessStreamParams()));
            // Sentinel = 'TLimitingFileRandomAccessStreamParams'
            (aWriter)->WriteSentinel(298847893);
            return;
        }
    default:
        {
            aWriter->FatalError("unknown variant of union RandomAccessStreamParams");
            return;
        }
    }
}

auto ParamTraits<::mozilla::ipc::RandomAccessStreamParams>::Read(IPC::MessageReader* aReader) -> IPC::ReadResult<paramType>
{
    typedef ::mozilla::ipc::RandomAccessStreamParams union__;
    auto maybe__type = IPC::ReadParam<int>(aReader);
    if (!maybe__type) {
        aReader->FatalError("Error deserializing type of union RandomAccessStreamParams");
        return {};

    }
    auto& type = *maybe__type;
    // Sentinel = 'RandomAccessStreamParams'
    if ((!((aReader)->ReadSentinel(1965820292)))) {
        mozilla::ipc::SentinelReadError("Error deserializing type of union RandomAccessStreamParams");
        return {};
    }

    switch (type) {
    case union__::TFileRandomAccessStreamParams:
        {
            auto maybe__tmp = IPC::ReadParam<::mozilla::ipc::FileRandomAccessStreamParams>(aReader);
            if (!maybe__tmp) {
                aReader->FatalError("Error deserializing variant TFileRandomAccessStreamParams of union RandomAccessStreamParams");
                return {};

            }
            auto& tmp = *maybe__tmp;
            // Sentinel = 'TFileRandomAccessStreamParams'
            if ((!((aReader)->ReadSentinel(2789542744)))) {
                mozilla::ipc::SentinelReadError("Error deserializing variant TFileRandomAccessStreamParams of union RandomAccessStreamParams");
                return {};
            }
            return std::move(tmp);
        }
    case union__::TLimitingFileRandomAccessStreamParams:
        {
            auto maybe__tmp = IPC::ReadParam<::mozilla::ipc::LimitingFileRandomAccessStreamParams>(aReader);
            if (!maybe__tmp) {
                aReader->FatalError("Error deserializing variant TLimitingFileRandomAccessStreamParams of union RandomAccessStreamParams");
                return {};

            }
            auto& tmp = *maybe__tmp;
            // Sentinel = 'TLimitingFileRandomAccessStreamParams'
            if ((!((aReader)->ReadSentinel(298847893)))) {
                mozilla::ipc::SentinelReadError("Error deserializing variant TLimitingFileRandomAccessStreamParams of union RandomAccessStreamParams");
                return {};
            }
            return std::move(tmp);
        }
    default:
        {
            aReader->FatalError("unknown variant of union RandomAccessStreamParams");
            return {};
        }
    }
}

} // namespace IPC
