Skip to content
Snippets Groups Projects
Commit 5aa40ceb authored by tho's avatar tho
Browse files

added (U)Int64Parser

parent 3549f9fe
No related branches found
No related tags found
No related merge requests found
...@@ -284,8 +284,60 @@ namespace senf { ...@@ -284,8 +284,60 @@ namespace senf {
inline std::ostream & operator<<(std::ostream & os, UInt32Parser const & i) inline std::ostream & operator<<(std::ostream & os, UInt32Parser const & i)
{ os << i.value(); return os; } { os << i.value(); return os; }
/** \brief Parse 64bit signed byte aligned integer
\see parseint
\ingroup parseint
*/
struct Int64Parser
: public detail::packet::IntParserOps<Int64Parser,boost::int64_t>,
public PacketParserBase
{
Int64Parser(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
///////////////////////////////////////////////////////////////////////////
typedef boost::int64_t value_type;
static size_type const fixed_bytes = 8;
value_type value() const { return detail::packet::parse_uint64(i()); }
void value(value_type v) { detail::packet::write_uint64(i(),v); }
Int64Parser const & operator= (value_type other) { value(other); return *this; }
};
/** \brief Write parsed value to stream
\related Int64Parser
*/
inline std::ostream & operator<<(std::ostream & os, Int64Parser const & i)
{ os << i.value(); return os; }
/** \brief Parse 64bit unsigned byte aligned integer
\see parseint
\ingroup parseint
*/
struct UInt64Parser
: public detail::packet::IntParserOps<UInt64Parser,boost::uint64_t>,
public PacketParserBase
{
UInt64Parser(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
///////////////////////////////////////////////////////////////////////////
typedef boost::uint64_t value_type;
static size_type const fixed_bytes = 8;
value_type value() const { return detail::packet::parse_uint64(i()); }
void value(value_type v) { detail::packet::write_uint64(i(),v); }
UInt64Parser const & operator= (value_type other) { value(other); return *this; }
};
/** \brief Write parsed value to stream
\related UInt64Parser
*/
inline std::ostream & operator<<(std::ostream & os, UInt64Parser const & i)
{ os << i.value(); return os; }
/** \brief Parse signed bitfield with up to 32bit's /** \brief Parse signed bitfield with up to 32bit's
This parser will parse a bitfield beginning at the bit \a Start and ending \e before \a This parser will parse a bitfield beginning at the bit \a Start and ending \e before \a
End. Bits are numbered <em>most significant bit first</em> as this is the customary End. Bits are numbered <em>most significant bit first</em> as this is the customary
numbering used when defining packet data structures. \a Start and \a End can be \e numbering used when defining packet data structures. \a Start and \a End can be \e
...@@ -303,7 +355,7 @@ namespace senf { ...@@ -303,7 +355,7 @@ namespace senf {
compile-time constants, the compiler will create optimized bit-masks to directly access compile-time constants, the compiler will create optimized bit-masks to directly access
the value. The parser is also optimized to access the minimum number of data bytes the value. The parser is also optimized to access the minimum number of data bytes
necessary. necessary.
\ingroup parseint \ingroup parseint
*/ */
template <unsigned Start, unsigned End> template <unsigned Start, unsigned End>
...@@ -343,7 +395,7 @@ namespace senf { ...@@ -343,7 +395,7 @@ namespace senf {
{ os << i.value(); return os; } { os << i.value(); return os; }
/** \brief Parse unsigned bitfield with up to 32bit's /** \brief Parse unsigned bitfield with up to 32bit's
This parser will parse a bitfield beginning at the bit \a Start and ending \e before \a This parser will parse a bitfield beginning at the bit \a Start and ending \e before \a
End. Bits are numbered <em>most significant bit first</em> as this is the customary End. Bits are numbered <em>most significant bit first</em> as this is the customary
numbering used when defining packet data structures. \a Start and \a End can be \e numbering used when defining packet data structures. \a Start and \a End can be \e
...@@ -361,7 +413,7 @@ namespace senf { ...@@ -361,7 +413,7 @@ namespace senf {
compile-time constants, the compiler will create optimized bit-masks to directly access compile-time constants, the compiler will create optimized bit-masks to directly access
the value. The parser is also optimized to access the minimum number of data bytes the value. The parser is also optimized to access the minimum number of data bytes
necessary. necessary.
\ingroup parseint \ingroup parseint
*/ */
template <unsigned Start, unsigned End> template <unsigned Start, unsigned End>
...@@ -449,7 +501,7 @@ namespace senf { ...@@ -449,7 +501,7 @@ namespace senf {
//#include "IntParser.cti" //#include "IntParser.cti"
#endif #endif
// Local Variables: // Local Variables:
// mode: c++ // mode: c++
// fill-column: 100 // fill-column: 100
......
...@@ -155,6 +155,34 @@ namespace packet { ...@@ -155,6 +155,34 @@ namespace packet {
i[3] = ( v ) & 0xff; i[3] = ( v ) & 0xff;
} }
/** \brief Internal: Extract 64bit network byte order value
\internal
*/
inline boost::uint64_t parse_uint64(iterator i)
{
return ((boost::uint64_t)i[7]) | ((boost::uint64_t)i[6])<<8
| ((boost::uint64_t)i[5])<<16 | ((boost::uint64_t)i[4])<<24
| ((boost::uint64_t)i[3])<<32 | ((boost::uint64_t)i[2])<<40
| ((boost::uint64_t)i[1])<<48 | ((boost::uint64_t)i[0])<<56;
}
/** \brief Internal: Write 64bit network byte order value
\internal
*/
inline void write_uint64(iterator i, boost::uint64_t v)
{
i[0] = ( v >> 56 ) & 0xff;
i[1] = ( v >> 48 ) & 0xff;
i[2] = ( v >> 40 ) & 0xff;
i[3] = ( v >> 32 ) & 0xff;
i[4] = ( v >> 24 ) & 0xff;
i[5] = ( v >> 16 ) & 0xff;
i[6] = ( v >> 8 ) & 0xff;
i[7] = ( v ) & 0xff;
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// bitfield extraction // bitfield extraction
...@@ -263,7 +291,7 @@ namespace packet { ...@@ -263,7 +291,7 @@ namespace packet {
///////////////////////////////ih.e//////////////////////////////////////// ///////////////////////////////ih.e////////////////////////////////////////
#endif #endif
// Local Variables: // Local Variables:
// mode: c++ // mode: c++
// fill-column: 100 // fill-column: 100
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment