构建SubRule底层结构
This commit is contained in:
parent
33cb4a12b5
commit
ae67325332
|
@ -59,14 +59,14 @@ void SequenceRulesView::currentRuleRefresh(const QModelIndex& idx)
|
|||
void SequenceRulesView::peersRuleChanged(const QModelIndex& idx)
|
||||
{
|
||||
auto rule_idx = idx.sibling(idx.row(), 2);
|
||||
auto rule_nm = base->extactors()[rule_idx.data(Qt::DisplayRole).toString()];
|
||||
auto rule_nm = base->extractUnitList()[rule_idx.data(Qt::DisplayRole).toString()];
|
||||
auto new_inst = std::dynamic_pointer_cast<ExtractUnit>(rule_nm->newDefault());
|
||||
_rule_sequence.replace(idx.row(), new_inst);
|
||||
|
||||
if (typeid(*new_inst.get()) == typeid(BytesAsList)) {
|
||||
auto conv = std::dynamic_pointer_cast<BytesAsList>(new_inst);
|
||||
if (!conv->elementRule()) {
|
||||
conv->appendElementRule(this->base->defaultRule());
|
||||
conv->appendElementRule(this->base->defaultExtractUnit());
|
||||
}
|
||||
|
||||
if (!conv->sizeProvider()) {
|
||||
|
@ -122,11 +122,11 @@ void SequenceRulesView::addTranslateUnit()
|
|||
QList<QStandardItem*> new_row;
|
||||
new_row << new QStandardItem(QString(u8"rule_%1").arg(row_cnt));
|
||||
new_row << new QStandardItem(u8"0");
|
||||
new_row << new QStandardItem(base->defaultRule()->name());
|
||||
new_row << new QStandardItem(base->defaultExtractUnit()->name());
|
||||
new_row << new QStandardItem(u8"1");
|
||||
new_row.last()->setEditable(false);
|
||||
|
||||
auto curr_rule = base->defaultRule()->newDefault();
|
||||
auto curr_rule = base->defaultExtractUnit()->newDefault();
|
||||
this->_rule_sequence << std::static_pointer_cast<AbstractExtractor>(curr_rule);
|
||||
|
||||
auto hex_rule = std::static_pointer_cast<BytesAsHex>(curr_rule);
|
||||
|
@ -166,7 +166,7 @@ QWidget* RuleSelectDelegate::createEditor(QWidget* parent, const QStyleOptionVie
|
|||
|
||||
void RuleSelectDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
|
||||
{
|
||||
auto rule_names = this->_kernel->extactors().keys();
|
||||
auto rule_names = this->_kernel->extractUnitList().keys();
|
||||
std::sort(rule_names.begin(), rule_names.end());
|
||||
|
||||
auto combo = dynamic_cast<QComboBox*>(editor);
|
||||
|
|
|
@ -37,7 +37,7 @@ TranslateBasic::TranslateBasic()
|
|||
_size_provider_types[sz_ptr->name()] = sz_ptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<ExtractUnit> TranslateBasic::defaultRule() const
|
||||
std::shared_ptr<ExtractUnit> TranslateBasic::defaultExtractUnit() const
|
||||
{
|
||||
return _default_translate_rule;
|
||||
}
|
||||
|
@ -47,16 +47,26 @@ std::shared_ptr<SizeProvider> TranslateBasic::defaultSizeProvider() const
|
|||
return _default_size_provider;
|
||||
}
|
||||
|
||||
QHash<QString, std::shared_ptr<ExtractUnit>> TranslateBasic::extactors() const
|
||||
std::shared_ptr<RuleMatch> TranslateBasic::defaultRuleMatch() const
|
||||
{
|
||||
return _default_rule_match;
|
||||
}
|
||||
|
||||
QHash<QString, std::shared_ptr<ExtractUnit>> TranslateBasic::extractUnitList() const
|
||||
{
|
||||
return _extractor_types;
|
||||
}
|
||||
|
||||
QHash<QString, std::shared_ptr<SizeProvider>> TranslateBasic::sizeProviders() const
|
||||
QHash<QString, std::shared_ptr<SizeProvider>> TranslateBasic::sizeProviderList() const
|
||||
{
|
||||
return _size_provider_types;
|
||||
}
|
||||
|
||||
QHash<QString, std::shared_ptr<RuleMatch>> TranslateBasic::ruleMatchList() const
|
||||
{
|
||||
return _rule_match_types;
|
||||
}
|
||||
|
||||
QString ConstNumberProvider::name() const
|
||||
{
|
||||
return NAME(ConstNumberProvider);
|
||||
|
@ -69,10 +79,25 @@ int32_t ConstNumberProvider::value(const QString& expr) const
|
|||
|
||||
void ConstNumberProvider::setExpression(const QString& expr)
|
||||
{
|
||||
this->_number_value = expr;
|
||||
this->_number._value_string = expr;
|
||||
}
|
||||
|
||||
QString ConstNumberProvider::expression() const
|
||||
{
|
||||
return this->_number_value;
|
||||
return this->_number._value_string;
|
||||
}
|
||||
|
||||
void ConstNumberProvider::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj)
|
||||
{
|
||||
STRING_PEAK(_number._value_string, obj);
|
||||
}
|
||||
|
||||
void ConstNumberProvider::saveTo(QJsonObject& obj) const
|
||||
{
|
||||
STRING_SAVE(_number._value_string, obj);
|
||||
}
|
||||
|
||||
std::shared_ptr<Serializable> ConstNumberProvider::newDefault() const
|
||||
{
|
||||
return std::make_shared<ConstNumberProvider>();
|
||||
}
|
||||
|
|
|
@ -11,21 +11,30 @@ class TranslateBasic {
|
|||
private:
|
||||
QHash<QString, std::shared_ptr<ExtractUnit>> _extractor_types;
|
||||
std::shared_ptr<ExtractUnit> _default_translate_rule = nullptr;
|
||||
|
||||
QHash<QString, std::shared_ptr<SizeProvider>> _size_provider_types;
|
||||
std::shared_ptr<SizeProvider> _default_size_provider = nullptr;
|
||||
|
||||
QHash<QString, std::shared_ptr<RuleMatch>> _rule_match_types;
|
||||
std::shared_ptr<RuleMatch> _default_rule_match = nullptr;
|
||||
|
||||
public:
|
||||
TranslateBasic();
|
||||
|
||||
std::shared_ptr<ExtractUnit> defaultRule() const;
|
||||
std::shared_ptr<SizeProvider> defaultSizeProvider() const;
|
||||
QHash<QString, std::shared_ptr<ExtractUnit>> extactors() const;
|
||||
QHash<QString, std::shared_ptr<SizeProvider>> sizeProviders() const;
|
||||
QHash<QString, std::shared_ptr<SizeProvider>> sizeProviderList() const;
|
||||
std::shared_ptr<RuleMatch> defaultRuleMatch() const;
|
||||
QHash<QString, std::shared_ptr<RuleMatch>> ruleMatchList() const;
|
||||
|
||||
std::shared_ptr<ExtractUnit> defaultExtractUnit() const;
|
||||
QHash<QString, std::shared_ptr<ExtractUnit>> extractUnitList() const;
|
||||
};
|
||||
|
||||
class ConstNumberProvider : public SizeProvider {
|
||||
private:
|
||||
QString _number_value;
|
||||
public:
|
||||
struct __Private {
|
||||
QString _value_string;
|
||||
} _number;
|
||||
|
||||
public:
|
||||
QString name() const override;
|
||||
|
@ -33,4 +42,9 @@ public:
|
|||
int32_t value(const QString& expr) const override;
|
||||
void setExpression(const QString& expr) override;
|
||||
QString expression() const override;
|
||||
|
||||
void loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj) override;
|
||||
void saveTo(QJsonObject& obj) const override;
|
||||
|
||||
std::shared_ptr<Serializable> newDefault() const override;
|
||||
};
|
||||
|
|
|
@ -4,12 +4,16 @@
|
|||
#include <memory>
|
||||
|
||||
#define NAME(u) #u
|
||||
#define INT32_SAVE(varx) obj[NAME(varx)] = varx;
|
||||
#define INT32_PEAK(varx) varx = obj[NAME(varx)].toInt();
|
||||
#define STRLIST_SAVE(list) obj[NAME(list)] = list.join(";");
|
||||
#define STRLIST_PEAK(list) list = obj[NAME(list)].toString().split(";");
|
||||
#define STRING_PEAK(codec_name) codec_name = obj[NAME(codec_name)].toString();
|
||||
#define STRING_SAVE(codec_name) obj[NAME(codec_name)] = codec_name;
|
||||
#define INT32_SAVE(varx, obj) obj[NAME(varx)] = varx;
|
||||
#define INT32_PEAK(varx, obj) varx = obj[NAME(varx)].toInt();
|
||||
#define STRLIST_SAVE(list, obj) obj[NAME(list)] = list.join(";");
|
||||
#define STRLIST_PEAK(list, obj) list = obj[NAME(list)].toString().split(";");
|
||||
#define STRING_PEAK(codec_name, obj) codec_name = obj[NAME(codec_name)].toString();
|
||||
#define STRING_SAVE(codec_name, obj) obj[NAME(codec_name)] = codec_name;
|
||||
#define OBJECT_SAVE(objn, obj) obj[NAME(objn)] = objn;
|
||||
#define OBJECT_PEAK(objn, obj) objn = obj[NAME(objn)].toObject();
|
||||
#define ARRAY_SAVE(objn, obj) obj[NAME(objn)] = objn;
|
||||
#define ARRAY_PEAK(objn, obj) objn = obj[NAME(objn)].toArray();
|
||||
|
||||
class TranslateBasic;
|
||||
/// <summary>
|
||||
|
@ -48,4 +52,5 @@ enum class DataType {
|
|||
Dbl64,
|
||||
LIST_COLLECTION,
|
||||
UNION_COMBINATE,
|
||||
SUB_RULE,
|
||||
};
|
||||
|
|
|
@ -27,21 +27,21 @@ DataType AbstractValueConvert::outType() const
|
|||
void AbstractValueConvert::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj)
|
||||
{
|
||||
auto int_in_type = (int)_in_type;
|
||||
INT32_PEAK(int_in_type);
|
||||
INT32_PEAK(int_in_type, obj);
|
||||
_in_type = (DataType)int_in_type;
|
||||
|
||||
auto int_out_type = (int)_out_type;
|
||||
INT32_PEAK(int_out_type);
|
||||
INT32_PEAK(int_out_type, obj);
|
||||
_out_type = (DataType)int_out_type;
|
||||
}
|
||||
|
||||
void AbstractValueConvert::saveTo(QJsonObject& obj) const
|
||||
{
|
||||
auto int_in_type = (int)_in_type;
|
||||
INT32_SAVE(int_in_type);
|
||||
INT32_SAVE(int_in_type, obj);
|
||||
|
||||
auto int_out_type = (int)_out_type;
|
||||
INT32_SAVE(int_out_type);
|
||||
INT32_SAVE(int_out_type, obj);
|
||||
}
|
||||
|
||||
DoubleWithLSB::DoubleWithLSB()
|
||||
|
|
|
@ -45,14 +45,14 @@ int AbstractExtractor::countWithin() const
|
|||
void AbstractExtractor::loadFrom(
|
||||
std::shared_ptr<TranslateBasic> core, const QJsonObject& obj)
|
||||
{
|
||||
INT32_PEAK(_abs_data.byte_offset);
|
||||
INT32_PEAK(_abs_data.byte_count);
|
||||
INT32_PEAK(_abs_data.byte_offset, obj);
|
||||
INT32_PEAK(_abs_data.byte_count, obj);
|
||||
}
|
||||
|
||||
void AbstractExtractor::saveTo(QJsonObject& obj) const
|
||||
{
|
||||
INT32_SAVE(_abs_data.byte_offset);
|
||||
INT32_SAVE(_abs_data.byte_count);
|
||||
INT32_SAVE(_abs_data.byte_offset, obj);
|
||||
INT32_SAVE(_abs_data.byte_count, obj);
|
||||
}
|
||||
|
||||
BytesAsHex::BytesAsHex()
|
||||
|
@ -117,17 +117,20 @@ QVariant BytesAsBitCombine::parse(const QByteArray& bytes) const
|
|||
return result;
|
||||
}
|
||||
|
||||
#include <QJsonArray>
|
||||
void BytesAsBitCombine::loadFrom(
|
||||
std::shared_ptr<TranslateBasic> core, const QJsonObject& obj)
|
||||
{
|
||||
AbstractExtractor::loadFrom(core, obj);
|
||||
|
||||
QStringList value_list;
|
||||
STRLIST_PEAK(value_list);
|
||||
_combine._switch_options.clear();
|
||||
for (auto pair : value_list) {
|
||||
auto items = pair.split("=");
|
||||
_combine._switch_options[items.first().toInt()] = items.last();
|
||||
QJsonArray arr;
|
||||
ARRAY_PEAK(arr, obj);
|
||||
for (auto index = 0; index < arr.size(); ++index) {
|
||||
auto switch_obj = arr.at(index);
|
||||
auto key = switch_obj["index"].toInt();
|
||||
auto content = switch_obj["content"].toString();
|
||||
_combine._switch_options[key] = content;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,13 +138,14 @@ void BytesAsBitCombine::saveTo(QJsonObject& obj) const
|
|||
{
|
||||
AbstractExtractor::saveTo(obj);
|
||||
|
||||
QStringList value_list;
|
||||
QJsonArray arr;
|
||||
for (auto key : _combine._switch_options.keys()) {
|
||||
auto pair_str = QString("%1=%2").arg(key)
|
||||
.arg(_combine._switch_options[key]);
|
||||
value_list << pair_str;
|
||||
QJsonObject switch_obj;
|
||||
switch_obj["index"] = key;
|
||||
switch_obj["content"] = _combine._switch_options[key];
|
||||
arr.append(switch_obj);
|
||||
}
|
||||
STRLIST_SAVE(value_list);
|
||||
ARRAY_SAVE(arr, obj);
|
||||
}
|
||||
|
||||
std::shared_ptr<Serializable> BytesAsBitCombine::newDefault() const
|
||||
|
@ -214,7 +218,7 @@ void BytesAsString::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonOb
|
|||
AbstractExtractor::loadFrom(core, obj);
|
||||
|
||||
QString codec_name;
|
||||
STRING_PEAK(codec_name);
|
||||
STRING_PEAK(codec_name, obj);
|
||||
this->_strings._conv_with = QTextCodec::codecForName(codec_name.toLatin1());
|
||||
}
|
||||
|
||||
|
@ -223,7 +227,7 @@ void BytesAsString::saveTo(QJsonObject& obj) const
|
|||
AbstractExtractor::saveTo(obj);
|
||||
|
||||
auto codec_name = this->codecName();
|
||||
STRING_SAVE(codec_name);
|
||||
STRING_SAVE(codec_name, obj);
|
||||
}
|
||||
|
||||
std::shared_ptr<Serializable> BytesAsString::newDefault() const
|
||||
|
@ -350,37 +354,55 @@ int BytesAsList::countWithin() const
|
|||
#include "TranslateBasic.h"
|
||||
void BytesAsList::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj)
|
||||
{
|
||||
INT32_PEAK(_list._bytes_offset);
|
||||
INT32_PEAK(_list._bytes_offset, obj);
|
||||
|
||||
QString bind_unit_name = "";
|
||||
QString bind_size_provider_name = "";
|
||||
STRING_PEAK(bind_unit_name);
|
||||
STRING_PEAK(bind_size_provider_name);
|
||||
this->_list._bind_size_v = core->sizeProviders()[bind_size_provider_name];
|
||||
this->_list._bind_unit = core->extactors()[bind_unit_name];
|
||||
STRING_PEAK(bind_unit_name, obj);
|
||||
STRING_PEAK(bind_size_provider_name, obj);
|
||||
auto xdev = core->sizeProviderList()[bind_size_provider_name]->newDefault();
|
||||
this->_list._bind_size_v = std::dynamic_pointer_cast<SizeProvider>(xdev);
|
||||
xdev = core->extractUnitList()[bind_unit_name]->newDefault();
|
||||
this->_list._bind_unit = std::dynamic_pointer_cast<ExtractUnit>(xdev);
|
||||
|
||||
QString bind_provider_expr = "";
|
||||
STRING_SAVE(bind_provider_expr);
|
||||
STRING_SAVE(bind_provider_expr, obj);
|
||||
this->_list._bind_size_v->setExpression(bind_provider_expr);
|
||||
|
||||
QJsonObject unit_obj;
|
||||
QJsonObject size_provider_obj;
|
||||
OBJECT_PEAK(unit_obj, obj);
|
||||
OBJECT_PEAK(size_provider_obj, obj);
|
||||
|
||||
this->_list._bind_size_v->loadFrom(core, size_provider_obj);
|
||||
this->_list._bind_unit->loadFrom(core, unit_obj);
|
||||
}
|
||||
|
||||
#include <QJsonArray>
|
||||
void BytesAsList::saveTo(QJsonObject& obj) const
|
||||
{
|
||||
INT32_SAVE(_list._bytes_offset);
|
||||
INT32_SAVE(_list._bytes_offset, obj);
|
||||
|
||||
QString bind_unit_name = "";
|
||||
if (this->_list._bind_unit)
|
||||
QJsonObject unit_obj;
|
||||
if (this->_list._bind_unit) {
|
||||
bind_unit_name = this->_list._bind_unit->name();
|
||||
STRING_SAVE(bind_unit_name);
|
||||
this->_list._bind_unit->saveTo(unit_obj);
|
||||
}
|
||||
STRING_SAVE(bind_unit_name, obj);
|
||||
OBJECT_SAVE(unit_obj, obj);
|
||||
|
||||
QString bind_size_provider_name = "";
|
||||
QString bind_provider_expr = "";
|
||||
QJsonObject size_provider_obj;
|
||||
if (this->_list._bind_size_v) {
|
||||
bind_provider_expr = this->_list._bind_size_v->expression();
|
||||
bind_size_provider_name = this->_list._bind_size_v->name();
|
||||
this->_list._bind_size_v->saveTo(size_provider_obj);
|
||||
}
|
||||
STRING_SAVE(bind_size_provider_name);
|
||||
STRING_SAVE(bind_provider_expr);
|
||||
STRING_SAVE(bind_size_provider_name, obj);
|
||||
STRING_SAVE(bind_provider_expr, obj);
|
||||
OBJECT_SAVE(size_provider_obj, obj);
|
||||
}
|
||||
|
||||
QVariant BytesAsList::parse(const QByteArray& bytes) const
|
||||
|
@ -437,14 +459,47 @@ QVariant BytesAsUnion::parse(const QByteArray& bytes) const
|
|||
void BytesAsUnion::loadFrom(
|
||||
std::shared_ptr<TranslateBasic> core, const QJsonObject& obj)
|
||||
{
|
||||
INT32_PEAK(_union.byte_count);
|
||||
INT32_PEAK(_union.byte_offset);
|
||||
INT32_PEAK(_union.byte_count, obj);
|
||||
INT32_PEAK(_union.byte_offset, obj);
|
||||
|
||||
QJsonArray array;
|
||||
ARRAY_PEAK(array, obj);
|
||||
this->_union._rule_list.clear();
|
||||
for (auto index = 0; index < array.size(); ++index) {
|
||||
auto rule_obj = array.at(index);
|
||||
|
||||
QString match_name;
|
||||
STRING_PEAK(match_name, rule_obj);
|
||||
QJsonObject match_obj;
|
||||
OBJECT_PEAK(match_obj, rule_obj);
|
||||
|
||||
auto match = core->ruleMatchList()[match_name];
|
||||
auto nmatch = match->newDefault();
|
||||
nmatch->loadFrom(core, match_obj);
|
||||
|
||||
this->_union._rule_list.append(
|
||||
std::dynamic_pointer_cast<RuleMatch>(nmatch));
|
||||
}
|
||||
}
|
||||
|
||||
void BytesAsUnion::saveTo(QJsonObject& obj) const
|
||||
{
|
||||
INT32_SAVE(_union.byte_count);
|
||||
INT32_SAVE(_union.byte_offset);
|
||||
INT32_SAVE(_union.byte_count, obj);
|
||||
INT32_SAVE(_union.byte_offset, obj);
|
||||
|
||||
QJsonArray array;
|
||||
for (auto insr : this->_union._rule_list) {
|
||||
QJsonObject rule_obj;
|
||||
auto match_name = insr->name();
|
||||
STRING_SAVE(match_name, rule_obj);
|
||||
|
||||
QJsonObject match_obj;
|
||||
insr->saveTo(match_obj);
|
||||
OBJECT_SAVE(match_obj, rule_obj);
|
||||
|
||||
array.append(rule_obj);
|
||||
}
|
||||
ARRAY_SAVE(array, obj);
|
||||
}
|
||||
|
||||
std::shared_ptr<Serializable> BytesAsUnion::newDefault() const
|
||||
|
@ -479,3 +534,79 @@ bool BytesAsUnion::setOffsetSpan(int value)
|
|||
this->_union.byte_offset = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
QString BytesAsSubRule::name() const
|
||||
{
|
||||
return NAME(BytesAsSubRule);
|
||||
}
|
||||
|
||||
DataType BytesAsSubRule::outType() const
|
||||
{
|
||||
return DataType::SUB_RULE;
|
||||
}
|
||||
|
||||
bool BytesAsSubRule::setOffsetSpan(int bytes)
|
||||
{
|
||||
this->_rules._byte_offset = bytes;
|
||||
return true;
|
||||
}
|
||||
|
||||
int BytesAsSubRule::offsetSpan() const
|
||||
{
|
||||
return this->_rules._byte_offset;
|
||||
}
|
||||
|
||||
int BytesAsSubRule::countWithin() const
|
||||
{
|
||||
return this->_rules._byte_count;
|
||||
}
|
||||
|
||||
QVariant BytesAsSubRule::parse(const QByteArray& bytes) const
|
||||
{
|
||||
throw std::logic_error("The method or operation is not implemented.");
|
||||
}
|
||||
|
||||
void BytesAsSubRule::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj)
|
||||
{
|
||||
INT32_PEAK(_rules._byte_count, obj);
|
||||
INT32_PEAK(_rules._byte_offset, obj);
|
||||
|
||||
QJsonArray array;
|
||||
ARRAY_SAVE(array, obj);
|
||||
|
||||
for (auto index = 0; index < array.size(); ++index) {
|
||||
auto rule_obj = array.at(index);
|
||||
QString match_name;
|
||||
QJsonObject match_obj;
|
||||
STRING_PEAK(match_name, rule_obj);
|
||||
OBJECT_PEAK(match_obj, rule_obj);
|
||||
|
||||
auto xdev = core->extractUnitList()[match_name]->newDefault();
|
||||
xdev->loadFrom(core, match_obj);
|
||||
_rules._sub_rules.append(std::dynamic_pointer_cast<ExtractUnit>(xdev));
|
||||
}
|
||||
}
|
||||
|
||||
void BytesAsSubRule::saveTo(QJsonObject& obj) const
|
||||
{
|
||||
INT32_SAVE(_rules._byte_count, obj);
|
||||
INT32_SAVE(_rules._byte_offset, obj);
|
||||
|
||||
QJsonArray array;
|
||||
for (auto info : _rules._sub_rules) {
|
||||
QJsonObject rule_obj, match_obj;
|
||||
|
||||
QString match_name = info->name();
|
||||
STRING_SAVE(match_name, rule_obj);
|
||||
info->saveTo(match_obj);
|
||||
OBJECT_SAVE(match_obj, rule_obj);
|
||||
|
||||
array.append(rule_obj);
|
||||
}
|
||||
ARRAY_SAVE(array, obj);
|
||||
}
|
||||
|
||||
std::shared_ptr<Serializable> BytesAsSubRule::newDefault() const
|
||||
{
|
||||
return std::make_shared<BytesAsSubRule>();
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
/// <summary>
|
||||
/// 尺寸解析器
|
||||
/// </summary>
|
||||
class SizeProvider {
|
||||
class SizeProvider : public Serializable {
|
||||
public:
|
||||
virtual QString name() const = 0;
|
||||
/// <summary>
|
||||
|
@ -64,10 +64,11 @@ public:
|
|||
/// <summary>
|
||||
/// 规则匹配器
|
||||
/// </summary>
|
||||
class RuleMatch {
|
||||
class RuleMatch : public Serializable {
|
||||
public:
|
||||
virtual QString name() const = 0;
|
||||
virtual std::shared_ptr<ExtractUnit> bindRule() const = 0;
|
||||
virtual void bindRule(std::shared_ptr<ExtractUnit> rule) = 0;
|
||||
virtual bool checkpass(const QByteArray& buffer) const = 0;
|
||||
};
|
||||
|
||||
|
@ -262,6 +263,31 @@ namespace extract {
|
|||
|
||||
std::shared_ptr<Serializable> newDefault() const override;
|
||||
};
|
||||
|
||||
|
||||
class BytesAsSubRule : public ExtractUnit {
|
||||
public:
|
||||
struct __Private {
|
||||
int _byte_offset = 0, _byte_count = 1;
|
||||
QList<std::shared_ptr<ExtractUnit>> _sub_rules;
|
||||
}_rules;
|
||||
|
||||
|
||||
QString name() const override;
|
||||
DataType outType() const override;
|
||||
bool setOffsetSpan(int bytes) override;
|
||||
int offsetSpan() const override;
|
||||
int countWithin() const override;
|
||||
std::shared_ptr<Serializable> newDefault() const override;
|
||||
|
||||
|
||||
QVariant parse(const QByteArray& bytes) const override;
|
||||
|
||||
|
||||
void loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj) override;
|
||||
void saveTo(QJsonObject& obj) const override;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue