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


#include "mozilla/net/PAltDataOutputStreamChild.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/net/AltDataOutputStreamChild.h"

#include "mozilla/net/PNeckoChild.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"

namespace mozilla {
namespace net {


MOZ_IMPLICIT PAltDataOutputStreamChild::PAltDataOutputStreamChild() :
    mozilla::ipc::IProtocol(kProtocolId, mozilla::ipc::ChildSide)
{
    MOZ_COUNT_CTOR(PAltDataOutputStreamChild);
}

PAltDataOutputStreamChild::~PAltDataOutputStreamChild()
{
    MOZ_COUNT_DTOR(PAltDataOutputStreamChild);
}

auto PAltDataOutputStreamChild::ActorAlloc() -> void
{
}

auto PAltDataOutputStreamChild::ActorDealloc() -> void
{
    if (Manager()) {
        Manager()->DeallocManagee(kProtocolId, this);
    }
}

auto PAltDataOutputStreamChild::OtherPid() const -> ::base::ProcessId
{
    ::base::ProcessId pid =
        ::mozilla::ipc::IProtocol::ToplevelProtocol()->OtherPidMaybeInvalid();
    MOZ_RELEASE_ASSERT(pid != ::base::kInvalidProcessId);
    return pid;
}

auto PAltDataOutputStreamChild::OtherChildID() const -> ::GeckoChildID
{
    ::GeckoChildID childID =
        ::mozilla::ipc::IProtocol::ToplevelProtocol()->OtherChildIDMaybeInvalid();
    MOZ_RELEASE_ASSERT(childID != -1);
    return childID;
}

auto PAltDataOutputStreamChild::OtherEndpointProcInfo() const -> ::mozilla::ipc::EndpointProcInfo
{
    return ::mozilla::ipc::EndpointProcInfo{OtherPid(), OtherChildID()};
}

auto PAltDataOutputStreamChild::Manager() const -> PNeckoChild*
{
    return static_cast<PNeckoChild*>(IProtocol::Manager());
}

auto PAltDataOutputStreamChild::ManagedProtocolIds() const -> mozilla::Span<mozilla::ipc::ProtocolId const>
{
    return {};
}

auto PAltDataOutputStreamChild::GetManagedActors(mozilla::ipc::ProtocolId aProtocol) -> UntypedManagedContainer*
{
    switch (aProtocol) {
    default:
        return nullptr;
    }
}

auto PAltDataOutputStreamChild::SendWriteData(const nsACString& data) -> bool
{
    UniquePtr<IPC::Message> msg__ = PAltDataOutputStream::Msg_WriteData(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), data);
    // Sentinel = 'data'
    ((&(writer__)))->WriteSentinel(67109275);


    if (mozilla::ipc::LoggingEnabledFor("PAltDataOutputStream", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PAltDataOutputStreamChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PAltDataOutputStream::Msg_WriteData", OTHER);

    bool sendok__ = ChannelSend(std::move(msg__));
    return sendok__;
}

auto PAltDataOutputStreamChild::SendClose(const nsresult& status) -> bool
{
    UniquePtr<IPC::Message> msg__ = PAltDataOutputStream::Msg_Close(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), status);
    // Sentinel = 'status'
    ((&(writer__)))->WriteSentinel(154731173);


    if (mozilla::ipc::LoggingEnabledFor("PAltDataOutputStream", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PAltDataOutputStreamChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PAltDataOutputStream::Msg_Close", OTHER);

    bool sendok__ = ChannelSend(std::move(msg__));
    return sendok__;
}

auto PAltDataOutputStreamChild::Send__delete__(PAltDataOutputStreamChild* actor) -> bool
{
    if (!actor || !actor->CanSend()) {
        NS_WARNING("Attempt to __delete__ missing or closed actor");
        return false;
    }
    UniquePtr<IPC::Message> msg__ = PAltDataOutputStream::Msg___delete__((actor)->Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            actor};


    if (mozilla::ipc::LoggingEnabledFor("PAltDataOutputStream", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PAltDataOutputStreamChild",
            actor->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PAltDataOutputStream::Msg___delete__", OTHER);

    bool sendok__ = (actor)->ChannelSend(std::move(msg__));

    actor->ActorDisconnected(Deletion);
    return sendok__;
}

auto PAltDataOutputStreamChild::SendDeleteSelf() -> bool
{
    UniquePtr<IPC::Message> msg__ = PAltDataOutputStream::Msg_DeleteSelf(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};



    if (mozilla::ipc::LoggingEnabledFor("PAltDataOutputStream", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PAltDataOutputStreamChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PAltDataOutputStream::Msg_DeleteSelf", OTHER);

    bool sendok__ = ChannelSend(std::move(msg__));
    return sendok__;
}

auto PAltDataOutputStreamChild::DeallocManagee(
        mozilla::ipc::ProtocolId aProtocolId,
        IProtocol* aListener) -> void
{
    FatalError("unreached");
    return;
}

auto PAltDataOutputStreamChild::OnMessageReceived(const Message& msg__) -> PAltDataOutputStreamChild::Result
{
    switch (msg__.type()) {
    case MANAGED_ENDPOINT_BOUND_MESSAGE_TYPE:
        {
            if (!mAwaitingManagedEndpointBind) {
                NS_WARNING("Unexpected managed endpoint lifecycle message after actor bound!");
                return MsgNotAllowed;
            }
            mAwaitingManagedEndpointBind = false;
            return MsgProcessed;
        }
    case MANAGED_ENDPOINT_DROPPED_MESSAGE_TYPE:
        {
            if (!mAwaitingManagedEndpointBind) {
                NS_WARNING("Unexpected managed endpoint lifecycle message after actor bound!");
                return MsgNotAllowed;
            }
            mAwaitingManagedEndpointBind = false;
            this->ActorDisconnected(ManagedEndpointDropped);
            return MsgProcessed;
        }
    case PAltDataOutputStream::Reply___delete____ID:
        {
            return MsgProcessed;
        }
    case PAltDataOutputStream::Msg_Error__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PAltDataOutputStream", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PAltDataOutputStreamChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PAltDataOutputStream::Msg_Error", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

            auto maybe__err = IPC::ReadParam<nsresult>((&(reader__)));
            if (!maybe__err) {
                FatalError("Error deserializing 'nsresult'");
                return MsgValueError;

            }
            auto& err = *maybe__err;
            // Sentinel = 'err'
            if ((!(((&(reader__)))->ReadSentinel(42467658)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'nsresult'");
                return MsgValueError;
            }
            reader__.EndRead();
            mozilla::ipc::IPCResult __ok = (static_cast<AltDataOutputStreamChild*>(this))->RecvError(std::move(err));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PAltDataOutputStream::Msg_DeleteSelf__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PAltDataOutputStream", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PAltDataOutputStreamChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PAltDataOutputStream::Msg_DeleteSelf", OTHER);

            mozilla::ipc::IPCResult __ok = (static_cast<AltDataOutputStreamChild*>(this))->RecvDeleteSelf();
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    default:
        return MsgNotKnown;
    }
}

auto PAltDataOutputStreamChild::OnMessageReceived(
        const Message& msg__,
        UniquePtr<Message>& reply__) -> PAltDataOutputStreamChild::Result
{
    return MsgNotKnown;
}



} // namespace net
} // namespace mozilla
namespace IPC {
auto ParamTraits<::mozilla::net::PAltDataOutputStreamChild*>::Write(
        IPC::MessageWriter* aWriter,
        const paramType& aVar) -> void
{
    IPC::WriteParam(aWriter, static_cast<mozilla::ipc::IProtocol*>(aVar));
    // Sentinel = 'PAltDataOutputStream'
    (aWriter)->WriteSentinel(1342834665);
}

auto ParamTraits<::mozilla::net::PAltDataOutputStreamChild*>::Read(IPC::MessageReader* aReader) -> IPC::ReadResult<paramType>
{
    auto maybe__actor = IPC::ReadParam<mozilla::ipc::IProtocol*>(aReader);
    if (!maybe__actor) {
        aReader->FatalError("Error deserializing managed PAltDataOutputStream actor");
        return {};

    }
    auto& actor = *maybe__actor;
    // Sentinel = 'PAltDataOutputStream'
    if ((!((aReader)->ReadSentinel(1342834665)))) {
        mozilla::ipc::SentinelReadError("Error deserializing managed PAltDataOutputStream actor");
        return {};
    }

    if (actor && actor->GetProtocolId() != PAltDataOutputStreamMsgStart) {
        aReader->FatalError("Unexpected actor type (expected PAltDataOutputStream)");

        return {};
    }
    return static_cast<::mozilla::net::PAltDataOutputStreamChild*>(actor);
}

} // namespace IPC
