#include "PacketContent.hpp"

#include <cstring>
#include <stdexcept>

#include "Packet.hpp"
#include "SecurityMode.hpp"
#include "behavior/events/types.hpp"
#include "utils/serialize/basics.hpp"


namespace drp::packet::base {


PacketContent::PacketContent() = default;

PacketContent::PacketContent(const event::EventType eventType, const std::vector<std::uint8_t>& data) {
    this->eventType = eventType;
    this->data = data;
}


std::vector<std::uint8_t> PacketContent::serialize() const {
    // serialize the members
    const auto serializedEventType = util::serialize::serializeObject(static_cast<std::uint8_t>(this->eventType));
    const auto serializedData = util::serialize::serializeVector(this->data);

    // create a buffer to store our members
    std::vector<std::uint8_t> data;

    // store our members
    data.insert(data.end(), serializedEventType.begin(), serializedEventType.end());
    data.insert(data.end(), serializedData.begin(), serializedData.end());

    return data;
}

PacketContent PacketContent::deserialize(std::vector<std::uint8_t>& data) {
    // deserialize the members
    const auto contentEventType = static_cast<event::EventType>(util::serialize::deserializeObject<std::uint8_t>(data));
    const auto contentData = util::serialize::deserializeVector<std::uint8_t>(data);

    return {contentEventType, contentData};
}


}
