Answer the question
In order to leave comments, you need to log in
Wrapper for raw data?
It is required to assemble / disassemble binary packages according to formal descriptions of formats.
Formal descriptions are stored by the Wrapper class.
Raw data from u_int8 *buffer is wrapped by the Wrapper class, which divides the buffer into fields, assigns a tag and field size to each field. The data structure for the Wrapper is given by a list of objects of the FieldDescription class that contain information about the fields (tag, size), and the order in the list determines the order in the Wrapper.
class Wrapper
{
Wrapper(char *);
void setStructure(vector<const FieldDescription *> description);
vector<string> getTagOrder() const;
void *getValue(string tag) const;
size_t getSize(string tag) const;
void setValue(string tag, void * dataPtr);
map<string, void *> getFieldTagToValue() const;
map<string, size_t> getFieldTagToSizes() const;
};
class Interpreter
{
public:
// интерпретация данных
enum InterpretationType
{
PARAMLIST,
NUMBER,
STRING,
IPv4,
IPv6
};
void add(Tag_t tag, InterpretationType type);
void add(Tag_t tag, map<ParamValue, ParamName_t> parmCode2Name);
void add_if(Tag_t tag, map<ParamValue_t, ParamName_t> parmValue2Name,
Tag_t conditionTag, ParamValue_t conditionValue);
void add_if(Tag_t tag, map<ParamValue, ParamName_t> parmValue2Name,
multiMap<Tag_t, ParamValue_t> conditionTags2Values);
void add_if(Tag_t tag, InterpretationType type, multiMap<Tag_t, ParamValue_t> conditionTags2Values);
map<Tag_t, string> convert(const Wrapper &prim) const;
};
Answer the question
In order to leave comments, you need to log in
Your solution is very reminiscent of google protocol buffers, and as a result, if possible, I would advise not to reinvent the wheel, but to take a ready-made solution
to your question - see how it is done in protocol buffers ,
if briefly
there are three types of fields required, optional, repeated (required - we are not interested now), if optional or required is encountered several times in the incoming message, then the last of these values for the field is taken, if the field is repeated, then all values are added to the collection.
PS protocol buffers is a binary protocol, but it can also have a textual representation. I don’t really understand why in the 21st century someone might need xml? It has three original (in the sense of Google) implementations + a bunch of compatible ones for different languages.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question