update
This commit is contained in:
parent
878d1c3854
commit
7b4ecfb9ea
|
@ -1,50 +1,50 @@
|
||||||
#include "TranslateBasic.h"
|
#include "TranslateBasic.h"
|
||||||
|
|
||||||
AbstractTranslateUnit::AbstractTranslateUnit(const QString& name)
|
AbstractExtractor::AbstractExtractor(const QString& name)
|
||||||
:_name_store(name), _byte_offset(0), _byte_count(0) {
|
:_name_store(name), _byte_offset(0), _byte_count(0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AbstractTranslateUnit::setOffsetFromPrevious(int bytes)
|
bool AbstractExtractor::setOffsetFromPrevious(int bytes)
|
||||||
{
|
{
|
||||||
this->_byte_offset = bytes;
|
this->_byte_offset = bytes;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AbstractTranslateUnit::setCountWithinParse(int bytes)
|
bool AbstractExtractor::setCountWithinParse(int bytes)
|
||||||
{
|
{
|
||||||
this->_byte_count = bytes;
|
this->_byte_count = bytes;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AbstractTranslateUnit::name() const
|
QString AbstractExtractor::name() const
|
||||||
{
|
{
|
||||||
return _name_store;
|
return _name_store;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AbstractTranslateUnit::offsetFromPrevious() const
|
int AbstractExtractor::offsetFromPrevious() const
|
||||||
{
|
{
|
||||||
return _byte_offset;
|
return _byte_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AbstractTranslateUnit::countWithinParse() const
|
int AbstractExtractor::countWithinParse() const
|
||||||
{
|
{
|
||||||
return _byte_count;
|
return _byte_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractTranslateUnit::loadFrom(const QJsonObject& obj)
|
void AbstractExtractor::loadFrom(const QJsonObject& obj)
|
||||||
{
|
{
|
||||||
INT32_PEAK(_byte_offset);
|
INT32_PEAK(_byte_offset);
|
||||||
INT32_PEAK(_byte_count);
|
INT32_PEAK(_byte_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractTranslateUnit::saveTo(QJsonObject& obj) const
|
void AbstractExtractor::saveTo(QJsonObject& obj) const
|
||||||
{
|
{
|
||||||
INT32_SAVE(_byte_count);
|
INT32_SAVE(_byte_count);
|
||||||
INT32_SAVE(_byte_offset);
|
INT32_SAVE(_byte_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
BytesAsHex::BytesAsHex()
|
BytesAsHex::BytesAsHex()
|
||||||
: AbstractTranslateUnit(NAME(BytesAsHex)) {
|
: AbstractExtractor(NAME(BytesAsHex)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant BytesAsHex::parse(const QByteArray& bytes) const
|
QVariant BytesAsHex::parse(const QByteArray& bytes) const
|
||||||
|
@ -62,7 +62,7 @@ std::shared_ptr<Serializable> BytesAsHex::newDefault() const
|
||||||
}
|
}
|
||||||
|
|
||||||
BytesAsBitCombine::BytesAsBitCombine()
|
BytesAsBitCombine::BytesAsBitCombine()
|
||||||
: AbstractTranslateUnit(NAME(BytesAsBitCombine))
|
: AbstractExtractor(NAME(BytesAsBitCombine))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ QVariant BytesAsBitCombine::parse(const QByteArray& bytes) const
|
||||||
|
|
||||||
void BytesAsBitCombine::loadFrom(const QJsonObject& obj)
|
void BytesAsBitCombine::loadFrom(const QJsonObject& obj)
|
||||||
{
|
{
|
||||||
AbstractTranslateUnit::loadFrom(obj);
|
AbstractExtractor::loadFrom(obj);
|
||||||
|
|
||||||
QStringList value_list;
|
QStringList value_list;
|
||||||
STRLIST_PEAK(value_list);
|
STRLIST_PEAK(value_list);
|
||||||
|
@ -119,7 +119,7 @@ void BytesAsBitCombine::loadFrom(const QJsonObject& obj)
|
||||||
|
|
||||||
void BytesAsBitCombine::saveTo(QJsonObject& obj) const
|
void BytesAsBitCombine::saveTo(QJsonObject& obj) const
|
||||||
{
|
{
|
||||||
AbstractTranslateUnit::saveTo(obj);
|
AbstractExtractor::saveTo(obj);
|
||||||
|
|
||||||
QStringList value_list;
|
QStringList value_list;
|
||||||
for (auto key : _switch_options.keys()) {
|
for (auto key : _switch_options.keys()) {
|
||||||
|
@ -135,13 +135,13 @@ std::shared_ptr<Serializable> BytesAsBitCombine::newDefault() const
|
||||||
|
|
||||||
void BytesAsInteger::loadFrom(const QJsonObject& obj)
|
void BytesAsInteger::loadFrom(const QJsonObject& obj)
|
||||||
{
|
{
|
||||||
AbstractTranslateUnit::loadFrom(obj);
|
AbstractExtractor::loadFrom(obj);
|
||||||
INT32_PEAK(unsigned_mark);
|
INT32_PEAK(unsigned_mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BytesAsInteger::saveTo(QJsonObject& obj) const
|
void BytesAsInteger::saveTo(QJsonObject& obj) const
|
||||||
{
|
{
|
||||||
AbstractTranslateUnit::saveTo(obj);
|
AbstractExtractor::saveTo(obj);
|
||||||
INT32_SAVE(unsigned_mark);
|
INT32_SAVE(unsigned_mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ std::shared_ptr<Serializable> BytesAsInteger::newDefault() const
|
||||||
}
|
}
|
||||||
|
|
||||||
BytesAsInteger::BytesAsInteger()
|
BytesAsInteger::BytesAsInteger()
|
||||||
:AbstractTranslateUnit(NAME(BytesAsInteger)) {
|
:AbstractExtractor(NAME(BytesAsInteger)) {
|
||||||
setCountWithinParse(8);
|
setCountWithinParse(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ bool BytesAsInteger::unsignedMark() const
|
||||||
bool BytesAsInteger::setCountWithinParse(int bytes)
|
bool BytesAsInteger::setCountWithinParse(int bytes)
|
||||||
{
|
{
|
||||||
if (bytes >= 0 && bytes <= 8)
|
if (bytes >= 0 && bytes <= 8)
|
||||||
return AbstractTranslateUnit::setCountWithinParse(bytes);
|
return AbstractExtractor::setCountWithinParse(bytes);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ QVariant BytesAsInteger::parse(const QByteArray& bytes) const
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
|
|
||||||
BytesAsString::BytesAsString()
|
BytesAsString::BytesAsString()
|
||||||
:AbstractTranslateUnit(NAME(BytesAsString)) {
|
:AbstractExtractor(NAME(BytesAsString)) {
|
||||||
_conv_with = QTextCodec::codecForName("GBK");
|
_conv_with = QTextCodec::codecForName("GBK");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ QVariant BytesAsString::parse(const QByteArray& bytes) const
|
||||||
|
|
||||||
void BytesAsString::loadFrom(const QJsonObject& obj)
|
void BytesAsString::loadFrom(const QJsonObject& obj)
|
||||||
{
|
{
|
||||||
AbstractTranslateUnit::loadFrom(obj);
|
AbstractExtractor::loadFrom(obj);
|
||||||
|
|
||||||
QString codec_name;
|
QString codec_name;
|
||||||
STRING_PEAK(codec_name);
|
STRING_PEAK(codec_name);
|
||||||
|
@ -238,7 +238,7 @@ void BytesAsString::loadFrom(const QJsonObject& obj)
|
||||||
|
|
||||||
void BytesAsString::saveTo(QJsonObject& obj) const
|
void BytesAsString::saveTo(QJsonObject& obj) const
|
||||||
{
|
{
|
||||||
AbstractTranslateUnit::saveTo(obj);
|
AbstractExtractor::saveTo(obj);
|
||||||
|
|
||||||
auto codec_name = this->codecName();
|
auto codec_name = this->codecName();
|
||||||
STRING_SAVE(codec_name);
|
STRING_SAVE(codec_name);
|
||||||
|
|
|
@ -26,12 +26,24 @@ public:
|
||||||
virtual std::shared_ptr<Serializable> newDefault() const = 0;
|
virtual std::shared_ptr<Serializable> newDefault() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ÄÚ²¿Ê¹ÓõÄÊý¾ÝÀàÐÍ
|
||||||
|
/// </summary>
|
||||||
|
enum class DataType {
|
||||||
|
ValueString,
|
||||||
|
TextString,
|
||||||
|
Int64,
|
||||||
|
Flt32,
|
||||||
|
Dbl64,
|
||||||
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 翻译单元抽象接口
|
/// 翻译单元抽象接口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class TranslateUnit : public Serializable {
|
class ExtractUnit : public Serializable {
|
||||||
public:
|
public:
|
||||||
virtual ~TranslateUnit() = default;
|
virtual ~ExtractUnit() = default;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 单元名称
|
/// 单元名称
|
||||||
|
@ -58,13 +70,13 @@ public:
|
||||||
virtual QVariant parse(const QByteArray& bytes) const = 0;
|
virtual QVariant parse(const QByteArray& bytes) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AbstractTranslateUnit : public TranslateUnit {
|
class AbstractExtractor : public ExtractUnit {
|
||||||
private:
|
private:
|
||||||
QString _name_store;
|
QString _name_store;
|
||||||
int _byte_offset, _byte_count;
|
int _byte_offset, _byte_count;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AbstractTranslateUnit(const QString& name);
|
AbstractExtractor(const QString& name);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置偏移字节数量
|
/// 设置偏移字节数量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -76,7 +88,7 @@ public:
|
||||||
/// <param name="bytes"></param>
|
/// <param name="bytes"></param>
|
||||||
virtual bool setCountWithinParse(int bytes);
|
virtual bool setCountWithinParse(int bytes);
|
||||||
|
|
||||||
// TranslateUnit ===========================
|
// ExtractUnit ===========================
|
||||||
QString name() const override;
|
QString name() const override;
|
||||||
int offsetFromPrevious() const override;
|
int offsetFromPrevious() const override;
|
||||||
int countWithinParse() const override;
|
int countWithinParse() const override;
|
||||||
|
@ -95,7 +107,7 @@ public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 转换源数值未16进制数值,默认分割方式
|
/// 转换源数值未16进制数值,默认分割方式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class BytesAsHex : public AbstractTranslateUnit {
|
class BytesAsHex : public AbstractExtractor {
|
||||||
public:
|
public:
|
||||||
BytesAsHex();
|
BytesAsHex();
|
||||||
|
|
||||||
|
@ -107,7 +119,7 @@ public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 转换源数值为位联合
|
/// 转换源数值为位联合
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class BytesAsBitCombine : public AbstractTranslateUnit {
|
class BytesAsBitCombine : public AbstractExtractor {
|
||||||
private:
|
private:
|
||||||
QHash<int, QString> _switch_options;
|
QHash<int, QString> _switch_options;
|
||||||
|
|
||||||
|
@ -118,7 +130,7 @@ public:
|
||||||
QHash<int, QString> switchOptions() const;
|
QHash<int, QString> switchOptions() const;
|
||||||
virtual void clearOptions();
|
virtual void clearOptions();
|
||||||
|
|
||||||
// TranslateUnit ============================
|
// ExtractUnit ============================
|
||||||
QVariant parse(const QByteArray& bytes) const override;
|
QVariant parse(const QByteArray& bytes) const override;
|
||||||
|
|
||||||
// Serializable ==============================
|
// Serializable ==============================
|
||||||
|
@ -130,7 +142,7 @@ public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 转换源数据为整形
|
/// 转换源数据为整形
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class BytesAsInteger : public AbstractTranslateUnit {
|
class BytesAsInteger : public AbstractExtractor {
|
||||||
private:
|
private:
|
||||||
bool unsigned_mark = false;
|
bool unsigned_mark = false;
|
||||||
|
|
||||||
|
@ -140,7 +152,7 @@ public:
|
||||||
void setUnsignedMark(bool ste);
|
void setUnsignedMark(bool ste);
|
||||||
bool unsignedMark() const;
|
bool unsignedMark() const;
|
||||||
|
|
||||||
// TranslateUnit ============================
|
// ExtractUnit ============================
|
||||||
bool setCountWithinParse(int bytes) override;
|
bool setCountWithinParse(int bytes) override;
|
||||||
QVariant parse(const QByteArray& bytes) const override;
|
QVariant parse(const QByteArray& bytes) const override;
|
||||||
|
|
||||||
|
@ -155,7 +167,7 @@ public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 转换源数据为字符串
|
/// 转换源数据为字符串
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class BytesAsString : public AbstractTranslateUnit {
|
class BytesAsString : public AbstractExtractor {
|
||||||
private:
|
private:
|
||||||
QTextCodec* _conv_with = nullptr;
|
QTextCodec* _conv_with = nullptr;
|
||||||
|
|
||||||
|
@ -165,7 +177,7 @@ public:
|
||||||
void setStrCodec(QTextCodec* ins);
|
void setStrCodec(QTextCodec* ins);
|
||||||
QString codecName() const;
|
QString codecName() const;
|
||||||
|
|
||||||
// TranslateUnit ============================
|
// ExtractUnit ============================
|
||||||
QVariant parse(const QByteArray& bytes) const override;
|
QVariant parse(const QByteArray& bytes) const override;
|
||||||
|
|
||||||
// Serializable ==============================
|
// Serializable ==============================
|
||||||
|
|
Loading…
Reference in New Issue