SimsWorld/MessageBasic/messagebasic.cpp

168 lines
3.7 KiB
C++
Raw Blame History

#include "messagebasic.h"
#include <QVariant>
void from_to_save(uint64_t f, uint64_t t, QJsonObject& o) {
o["source_entity"] = QJsonValue::fromVariant(QVariant::fromValue(f));
o["target_entity"] = QJsonValue::fromVariant(QVariant::fromValue(t));
}
void from_to_recovery(uint64_t& f, uint64_t& t, const QJsonObject& o) {
f = o["source_entity"].toVariant().toULongLong();
t = o["target_entity"].toVariant().toULongLong();
}
DeduceRequest::DeduceRequest()
:AbstractMessage(NAME(DeduceRequest)) {
}
SyncRequest::SyncRequest()
:AbstractMessage(NAME(SyncRequest)),
_time_current(0) {
}
void SyncRequest::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
DOUOBLE_PEAK(_time_current);
}
void SyncRequest::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
DOUBLE_SAVE(_time_current);
}
RespondDefault::RespondDefault()
:AbstractMessage(NAME(RespondDefault)),
_time_consume(0) {
}
void RespondDefault::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
DOUOBLE_PEAK(_time_consume);
}
void RespondDefault::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
DOUBLE_SAVE(_time_consume);
}
Get3DBox::Get3DBox()
:AbstractMessage(NAME(Get3DBox)) {
}
Box3DDesc::Box3DDesc()
:AbstractMessage(NAME(Box3DDesc)) {
}
void Box3DDesc::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
DOUOBLE_PEAK(this->_d3_data._height_m);
DOUOBLE_PEAK(this->_d3_data._length_m);
DOUOBLE_PEAK(this->_d3_data._width_m);
DOUOBLE_PEAK(this->_lla_pos._lon_deg);
DOUOBLE_PEAK(this->_lla_pos._lat_deg);
DOUOBLE_PEAK(this->_lla_pos._alt_m);
DOUOBLE_PEAK(this->_posture_d3._azimuth_deg);
DOUOBLE_PEAK(this->_posture_d3._pitch_deg);
DOUOBLE_PEAK(this->_posture_d3._roll_deg);
}
void Box3DDesc::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
DOUBLE_SAVE(this->_d3_data._height_m);
DOUBLE_SAVE(this->_d3_data._length_m);
DOUBLE_SAVE(this->_d3_data._width_m);
DOUBLE_SAVE(this->_lla_pos._lon_deg);
DOUBLE_SAVE(this->_lla_pos._lat_deg);
DOUBLE_SAVE(this->_lla_pos._alt_m);
DOUBLE_SAVE(this->_posture_d3._azimuth_deg);
DOUBLE_SAVE(this->_posture_d3._pitch_deg);
DOUBLE_SAVE(this->_posture_d3._roll_deg);
}
EntityAllocte::EntityAllocte()
:AbstractMessage(NAME(EntityAllocte)) {
}
void EntityAllocte::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
STRING_PEAK(_entity_templet);
}
void EntityAllocte::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
STRING_SAVE(_entity_templet);
}
AbstractMessage::AbstractMessage(const QString& topic) :_topic_string(topic) {}
void AbstractMessage::reset(uint64_t from, uint64_t to) {
this->_from_id = from;
this->_to_id = to;
}
// ͨ<><CDA8> WsMessage <20>̳<EFBFBD>
void AbstractMessage::recoveryFrom(const QJsonObject& obj) {
from_to_recovery(_from_id, _to_id, obj);
}
void AbstractMessage::saveTo(QJsonObject& obj) const
{
from_to_save(_from_id, _to_id, obj);
}
QString AbstractMessage::topicString() const
{
return _topic_string;
}
uint64_t AbstractMessage::targetEntity() const
{
return _to_id;
}
uint64_t AbstractMessage::sourceEntity() const
{
return _from_id;
}
EntityTotalGet::EntityTotalGet()
:AbstractMessage(NAME(EntityTotalGet)) {
}
void EntityTotalList::recoveryFrom(const QJsonObject& obj)
{
AbstractMessage::recoveryFrom(obj);
QStringList strs;
STRLIST_PEAK(strs);
std::transform(strs.begin(), strs.end(),
std::back_inserter(_entities_list),
[](QString v) { return v.toULongLong(); });
}
void EntityTotalList::saveTo(QJsonObject& obj) const
{
AbstractMessage::saveTo(obj);
QStringList strs;
std::transform(_entities_list.begin(), _entities_list.end(),
std::back_inserter(strs),
[](int v) { return QString(",").arg(v); });
STRLIST_SAVE(strs);
}