/* This file is autogenerated. DO NOT CHANGE. All changes will be lost */


#include "google/protobuf/timestamp.qpb.h"

#include <QtProtobuf/qprotobufregistration.h>

#include <QtProtobufWellKnownTypes/private/qprotobufwellknowntypesjsonserializers_p.h>

#include <QtCore/QTimeZone>

#include <cmath>

namespace google::protobuf {

class Timestamp_QtProtobufData : public QSharedData
{
public:
    Timestamp_QtProtobufData()
        : QSharedData(),
          m_seconds(0),
          m_nanos(0)
    {
    }

    Timestamp_QtProtobufData(const Timestamp_QtProtobufData &other)
        : QSharedData(other),
          m_seconds(other.m_seconds),
          m_nanos(other.m_nanos)
    {
    }

    QtProtobuf::int64 m_seconds;
    QtProtobuf::int32 m_nanos;
};

Timestamp::~Timestamp() = default;

static constexpr struct {
    QtProtobufPrivate::QProtobufPropertyOrdering::Data data;
    const std::array<uint, 9> qt_protobuf_Timestamp_uint_data;
    const char qt_protobuf_Timestamp_char_data[41];
} qt_protobuf_Timestamp_metadata {
    // data
    {
        0, /* = version */
        2, /* = num fields */
        3, /* = field number offset */
        5, /* = property index offset */
        7, /* = field flags offset */
        25, /* = message full name length */
    },
    // uint_data
    {
        // JSON name offsets:
        26, /* = seconds */
        34, /* = nanos */
        40, /* = end-of-string-marker */
        // Field numbers:
        1, /* = seconds */
        2, /* = nanos */
        // Property indices:
        0, /* = seconds */
        1, /* = nanos */
        // Field flags:
        uint(QtProtobufPrivate::FieldFlag::NoFlags), /* = seconds */
        uint(QtProtobufPrivate::FieldFlag::NoFlags), /* = nanos */
    },
    // char_data
    /* metadata char_data: */
    "google.protobuf.Timestamp\0" /* = full message name */
    /* field char_data: */
    "seconds\0nanos\0"
};

const QtProtobufPrivate::QProtobufPropertyOrdering Timestamp::staticPropertyOrdering = {
    &qt_protobuf_Timestamp_metadata.data
};

void Timestamp::registerTypes()
{
    qRegisterMetaType<Timestamp>();
    qRegisterMetaType<QList<Timestamp>>();
    QT_PREPEND_NAMESPACE(QtProtobufWellKnownTypesPrivate)::registerTimestampCustomJsonHandler();
}

Timestamp::Timestamp()
    : QProtobufMessage(&Timestamp::staticMetaObject, &Timestamp::staticPropertyOrdering),
      dptr(new Timestamp_QtProtobufData)
{
}

Timestamp::Timestamp(const Timestamp &other)
    = default;
Timestamp &Timestamp::operator =(const Timestamp &other)
{
    Timestamp temp(other);
    swap(temp);
    return *this;
}
Timestamp::Timestamp(Timestamp &&other) noexcept
    = default;
Timestamp::operator QVariant() const
{
    return QVariant::fromValue(*this);
}
bool comparesEqual(const Timestamp &lhs, const Timestamp &rhs) noexcept
{
    return operator ==(static_cast<const QProtobufMessage&>(lhs),
                       static_cast<const QProtobufMessage&>(rhs))
        && lhs.dptr->m_seconds == rhs.dptr->m_seconds
        && lhs.dptr->m_nanos == rhs.dptr->m_nanos;
}

QtProtobuf::int64 Timestamp::seconds() const
{
    return dptr->m_seconds;
}

QtProtobuf::int32 Timestamp::nanos() const
{
    return dptr->m_nanos;
}

void Timestamp::setSeconds(QtProtobuf::int64 seconds)
{
    if (dptr->m_seconds != seconds) {
        dptr.detach();
        dptr->m_seconds = seconds;
    }
}

void Timestamp::setNanos(QtProtobuf::int32 nanos)
{
    if (dptr->m_nanos != nanos) {
        dptr.detach();
        dptr->m_nanos = nanos;
    }
}

Timestamp Timestamp::fromDateTime(const QDateTime &dateTime)
{
    Timestamp ts;
    ts.setSeconds(dateTime.toMSecsSinceEpoch() / 1000);
    ts.setNanos((dateTime.toMSecsSinceEpoch() % 1000) * 1000000);
    return ts;
}

QDateTime Timestamp::toDateTime() const
{
    return QDateTime::fromMSecsSinceEpoch(
            seconds() * 1000 + nanos() / 1000000, QTimeZone(QTimeZone::UTC));
}

} // namespace google::protobuf

#include "moc_timestamp.qpb.cpp"
