Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
senf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wiback
senf
Commits
19dce5f2
Commit
19dce5f2
authored
16 years ago
by
g0dil
Browse files
Options
Downloads
Patches
Plain Diff
Packets: Allow collections in derived parsers to reference aux fields in the base parser
parent
e3d96b10
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Packets/ParseHelpers.hh
+3
-0
3 additions, 0 deletions
Packets/ParseHelpers.hh
Packets/ParseHelpers.ih
+10
-4
10 additions, 4 deletions
Packets/ParseHelpers.ih
Packets/VectorParser.test.cc
+53
-0
53 additions, 0 deletions
Packets/VectorParser.test.cc
with
66 additions
and
4 deletions
Packets/ParseHelpers.hh
+
3
−
0
View file @
19dce5f2
...
...
@@ -353,6 +353,9 @@
SENF_PARSER_INHERIT(BaseParser)
\endcode
If you want to define collection fields which reference auxiliary fields in the base parser,
<em>you must define the base parser as a variable parser not a fixed parser</em>.
\param[in] base name of base class
\hideinitializer
...
...
This diff is collapsed.
Click to expand it.
Packets/ParseHelpers.ih
+
10
−
4
View file @
19dce5f2
...
...
@@ -147,15 +147,19 @@
# // SENF_PARSER_I_FIELD_OFS_*
#
# define SENF_PARSER_I_FIELD_OFS_var(name, type, access) \
protected: \
size_type BOOST_PP_CAT(name,_offset)() const { \
return field_offset_(static_cast<senf::mpl::rv<BOOST_PP_CAT(name,_index)-1>*>(0)); \
} \
static size_type const BOOST_PP_CAT(name, _init_bytes) = \
SENF_MPL_SLOT_GET(init_bytes);
SENF_MPL_SLOT_GET(init_bytes); \
private:
#
# define SENF_PARSER_I_FIELD_OFS_fix(name, type, access) \
protected: \
static size_type const BOOST_PP_CAT(name, _offset) = \
SENF_MPL_SLOT_GET(offset);
SENF_MPL_SLOT_GET(offset); \
private:
#
# ////////////////////////////////////////
# // SENF_PARSER_I_ADVANCE_OFS_*
...
...
@@ -180,7 +184,9 @@
return BOOST_PP_CAT(name, _next_offset)(); \
} \
SENF_MPL_SLOT_SET(init_bytes, BOOST_PP_CAT(name,_next_init_bytes)); \
protected: \
static size_type const BOOST_PP_CAT(name, _group) = SENF_MPL_SLOT_GET(group) + isvar; \
private: \
SENF_MPL_SLOT_SET(group, BOOST_PP_CAT(name, _group)); \
access:
#
...
...
@@ -195,7 +201,7 @@
# // SENF_PARSER_I_FIELD_VAL_*
#
# define SENF_PARSER_I_FIELD_VAL_rw(name, type, access) \
pr
ivate:
\
pr
otected:
\
BOOST_PP_CAT(name, _t) BOOST_PP_CAT(name, _)() const { \
return parse<type>( SENF_PARSER_OFFSET(name) ); \
} \
...
...
@@ -205,7 +211,7 @@
}
#
# define SENF_PARSER_I_FIELD_VAL_ro(name, type, access) \
pr
ivate:
\
pr
otected:
\
BOOST_PP_CAT(name, _t) BOOST_PP_CAT(name, _)() const { \
return parse<type>( SENF_PARSER_OFFSET(name) ); \
} \
...
...
This diff is collapsed.
Click to expand it.
Packets/VectorParser.test.cc
+
53
−
0
View file @
19dce5f2
...
...
@@ -284,6 +284,59 @@ BOOST_AUTO_UNIT_TEST(vectorMacro_create)
BOOST_CHECK
(
equal
(
p
.
data
().
begin
(),
p
.
data
().
end
(),
data
));
}
namespace
{
struct
TestVectorBaseParser
:
public
senf
::
PacketParserBase
{
# include SENF_PARSER()
SENF_PARSER_PRIVATE_FIELD
(
size1
,
senf
::
UInt8Parser
);
SENF_PARSER_FIELD_RO
(
size2
,
senf
::
UInt8Parser
);
SENF_PARSER_FIELD
(
dummy
,
senf
::
UInt32Parser
);
\
SENF_PARSER_FINALIZE
(
TestVectorBaseParser
);
};
struct
TestVectorDerivedParser
:
public
TestVectorBaseParser
{
# include SENF_PARSER()
SENF_PARSER_INHERIT
(
TestVectorBaseParser
);
SENF_PARSER_VECTOR
(
vec1
,
transform
(
TestTransform
,
size1
)
,
senf
::
UInt16Parser
);
SENF_PARSER_VECTOR
(
vec2
,
bytes
(
size2
)
,
senf
::
UInt16Parser
);
SENF_PARSER_FINALIZE
(
TestVectorDerivedParser
);
};
}
BOOST_AUTO_UNIT_TEST
(
vectorMacro_inherit
)
{
unsigned
char
data
[]
=
{
0x05
,
// size1
0x04
,
// size2
0x01
,
0x02
,
0x03
,
0x04
,
// dummy
0x05
,
0x06
,
// vec1[0]
0x07
,
0x08
,
// vec1[1]
0x09
,
0x0A
,
// vec1[2]
0x0B
,
0x0C
,
// vec2[0]
0x0D
,
0x0E
};
// vec2[1]
senf
::
DataPacket
p
(
senf
::
DataPacket
::
create
(
data
));
TestVectorDerivedParser
parser
(
p
.
data
().
begin
(),
&
p
.
data
());
BOOST_CHECK_EQUAL
(
parser
.
vec1
().
size
(),
3u
);
BOOST_CHECK_EQUAL
(
parser
.
vec2
().
size
(),
2u
);
BOOST_CHECK_EQUAL
(
parser
.
dummy
(),
0x01020304u
);
BOOST_CHECK_EQUAL
(
parser
.
vec1
()[
0
],
0x0506u
);
BOOST_CHECK_EQUAL
(
parser
.
vec1
()[
1
],
0x0708u
);
BOOST_CHECK_EQUAL
(
parser
.
vec1
()[
2
],
0x090Au
);
BOOST_CHECK_EQUAL
(
parser
.
vec2
()[
0
],
0x0B0Cu
);
BOOST_CHECK_EQUAL
(
parser
.
vec2
()[
1
],
0x0D0Eu
);
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment