added Int16LSB, UInt16mLSB, UInt32LSB and UInt64LSB parser for little endian byte...
cni [Tue, 2 Dec 2008 15:54:20 +0000 (15:54 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@994 270642c3-0616-0410-b53a-bc976706d245

Packets/IntParser.hh
Packets/IntParser.ih

index 4b4a985..8c55605 100644 (file)
@@ -148,6 +148,34 @@ namespace senf {
     inline std::ostream & operator<<(std::ostream & os, Int16Parser const & i)
     { os << i.value(); return os; }
 
+    /** \brief Parse 16bit signed byte aligned integer LSB
+        \see parseint
+        \ingroup parseint
+     */
+    struct Int16LSBParser
+        : public detail::packet::IntParserOps<Int16LSBParser,boost::int16_t>,
+          public PacketParserBase
+    {
+        Int16LSBParser(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
+
+        ///////////////////////////////////////////////////////////////////////////
+
+        typedef boost::int16_t value_type;
+        static size_type const fixed_bytes = 2;
+        static value_type const min_value = -32768;
+        static value_type const max_value = 32767;
+
+
+        value_type value() const { return detail::packet::parse_uint16LSB(i()); }
+        void value(value_type v) { detail::packet::write_uint16LSB(i(),v); }
+        Int16LSBParser const & operator= (value_type other) { value(other); return *this; }
+    };
+    /** \brief Write parsed value to stream
+        \related Int16Parser
+     */
+    inline std::ostream & operator<<(std::ostream & os, Int16LSBParser const & i)
+    { os << i.value(); return os; }
+
     /** \brief Parse 16bit unsigned byte aligned integer
         \see parseint
         \ingroup parseint
@@ -175,6 +203,33 @@ namespace senf {
     inline std::ostream & operator<<(std::ostream & os, UInt16Parser const & i)
     { os << i.value(); return os; }
 
+    /** \brief Parse 16bit unsigned byte aligned integer LSB
+        \see parseint
+        \ingroup parseint
+     */
+    struct UInt16LSBParser
+        : public detail::packet::IntParserOps<UInt16LSBParser,boost::uint16_t>,
+          public PacketParserBase
+    {
+        UInt16LSBParser(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
+
+        ///////////////////////////////////////////////////////////////////////////
+
+        typedef boost::uint16_t value_type;
+        static size_type const fixed_bytes = 2;
+        static value_type const min_value = 0u;
+        static value_type const max_value = 65535u;
+
+        value_type value() const { return detail::packet::parse_uint16LSB(i()); }
+        void value(value_type v) { detail::packet::write_uint16LSB(i(),v); }
+        UInt16LSBParser const & operator= (value_type other) { value(other); return *this; }
+    };
+    /** \brief Write parsed value to stream
+        \related UInt16LSBParser
+     */
+    inline std::ostream & operator<<(std::ostream & os, UInt16LSBParser const & i)
+    { os << i.value(); return os; }
+
     /** \brief Parse 24bit signed byte aligned integer
         \see parseint
         \ingroup parseint
@@ -284,6 +339,32 @@ namespace senf {
     inline std::ostream & operator<<(std::ostream & os, UInt32Parser const & i)
     { os << i.value(); return os; }
 
+    struct UInt32LSBParser
+        : public detail::packet::IntParserOps<UInt32LSBParser,boost::uint32_t>,
+          public PacketParserBase
+    {
+        UInt32LSBParser(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
+
+        ///////////////////////////////////////////////////////////////////////////
+
+        typedef boost::uint32_t value_type;
+        static size_type const fixed_bytes = 4;
+        static value_type const min_value = 0u;
+        static value_type const max_value = 4294967295u;
+
+        value_type value() const { return detail::packet::parse_uint32LSB(i()); }
+        void value(value_type v) { detail::packet::write_uint32LSB(i(),v); }
+        UInt32LSBParser const & operator= (value_type other) { value(other); return *this; }
+    };
+    /** \brief Write parsed value to stream
+        \related UInt32LSBParser
+     */
+    inline std::ostream & operator<<(std::ostream & os, UInt32LSBParser const & i)
+    { os << i.value(); return os; }
+
+
+
+
     /** \brief Parse 64bit signed byte aligned integer
         \see parseint
         \ingroup parseint
@@ -335,6 +416,30 @@ namespace senf {
     inline std::ostream & operator<<(std::ostream & os, UInt64Parser const & i)
     { os << i.value(); return os; }
 
+    /** \brief Parse 64bit unsigned byte aligned integer LSB
+        \see parseint
+        \ingroup parseint
+     */
+    struct UInt64LSBParser
+        : public detail::packet::IntParserOps<UInt64LSBParser,boost::uint64_t>,
+          public PacketParserBase
+    {
+        UInt64LSBParser(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_uint64LSB(i()); }
+        void value(value_type v) { detail::packet::write_uint64LSB(i(),v); }
+        UInt64LSBParser const & operator= (value_type other) { value(other); return *this; }
+    };
+    /** \brief Write parsed value to stream
+        \related UInt64LSBParser
+     */
+    inline std::ostream & operator<<(std::ostream & os, UInt64LSBParser const & i)
+    { os << i.value(); return os; }
 
     /** \brief Parse signed bitfield with up to 32bit's
 
index d496b73..16099c1 100644 (file)
@@ -114,6 +114,25 @@ namespace packet {
         i[1] = ( v       ) & 0xff;
     }
 
+    /** \brief Internal: Extract 16bit least significant bit order value
+
+        \internal
+     */
+    inline boost::uint16_t parse_uint16LSB(iterator i)
+    {
+        return i[0] | i[1]<<8;
+    }
+
+    /** \brief Internal: Write 16bit least significant bit order value
+
+        \internal
+     */
+    inline void write_uint16LSB(iterator i, boost::uint16_t v)
+    {
+        i[0] = ( v       ) & 0xff;
+        i[1] = ( v >>  8 ) & 0xff;
+    }
+
     /** \brief Internal: Extract 24bit network byte order value
 
         \internal
@@ -155,6 +174,27 @@ namespace packet {
         i[3] = ( v       ) & 0xff;
     }
 
+    /** \brief Internal: Extract 32bit network byte order value
+
+        \internal
+     */
+    inline boost::uint32_t parse_uint32LSB(iterator i)
+    {
+        return i[0] | i[1]<<8 | i[2]<<16 | i[3]<<24;
+    }
+
+    /** \brief Internal: Write 32bit network byte order value
+
+        \internal
+     */
+    inline void write_uint32LSB(iterator i, boost::uint32_t v)
+    {
+        i[3] = ( v >> 24 ) & 0xff;
+        i[2] = ( v >> 16 ) & 0xff;
+        i[1] = ( v >>  8 ) & 0xff;
+        i[0] = ( v       ) & 0xff;
+    }
+
     /** \brief Internal: Extract 64bit network byte order value
 
         \internal
@@ -183,6 +223,34 @@ namespace packet {
         i[7] = ( v       ) & 0xff;
     }
 
+    /** \brief Internal: Extract 64bit least significant bit order value
+
+        \internal
+     */
+    inline boost::uint64_t parse_uint64LSB(iterator i)
+    {
+        return ((boost::uint64_t)i[0]) | ((boost::uint64_t)i[1])<<8
+                | ((boost::uint64_t)i[2])<<16 | ((boost::uint64_t)i[3])<<24
+                | ((boost::uint64_t)i[4])<<32 | ((boost::uint64_t)i[5])<<40
+                | ((boost::uint64_t)i[6])<<48 | ((boost::uint64_t)i[7])<<56;
+    }
+
+    /** \brief Internal: Write 64bit least significant bit order value
+
+        \internal
+     */
+    inline void write_uint64LSB(iterator i, boost::uint64_t v)
+    {
+        i[0] = ( v       ) & 0xff;
+        i[1] = ( v >> 8  ) & 0xff;
+        i[2] = ( v >> 16 ) & 0xff;
+        i[3] = ( v >> 24 ) & 0xff;
+        i[4] = ( v >> 32 ) & 0xff;
+        i[5] = ( v >> 40 ) & 0xff;
+        i[6] = ( v >> 48 ) & 0xff;
+        i[7] = ( v >> 56 ) & 0xff;
+    }
+
     ///////////////////////////////////////////////////////////////////////////
     // bitfield extraction