17 #ifndef HH_SENF_Packets_IntParser_ 18 #define HH_SENF_Packets_IntParser_ 1 22 #include <boost/cstdint.hpp> 23 #include <boost/static_assert.hpp> 24 #include <boost/integer/integer_mask.hpp> 65 :
public detail::packet::IntParserOps<Int8Parser,boost::int8_t>,
77 value_type
value()
const {
return i()[0]; }
78 void value(value_type v) {
i()[0] = v; }
85 { os << i.
value();
return os; }
92 :
public detail::packet::IntParserOps<UInt8Parser,boost::uint8_t>,
104 value_type
value()
const {
return i()[0]; }
112 { os << i.
value();
return os; }
119 :
public detail::packet::IntParserOps<Int16Parser,boost::int16_t>,
132 value_type
value()
const {
return detail::packet::parse_uint16(
i()); }
133 void value(value_type v) { detail::packet::write_uint16(
i(),v); }
140 { os << i.
value();
return os; }
147 :
public detail::packet::IntParserOps<Int16LSBParser,boost::int16_t>,
160 value_type
value()
const {
return detail::packet::parse_uint16LSB(
i()); }
161 void value(value_type v) { detail::packet::write_uint16LSB(
i(),v); }
168 { os << i.
value();
return os; }
175 :
public detail::packet::IntParserOps<UInt16Parser,boost::uint16_t>,
187 value_type
value()
const {
return detail::packet::parse_uint16(
i()); }
188 void value(value_type v) { detail::packet::write_uint16(
i(),v); }
195 { os << i.
value();
return os; }
202 :
public detail::packet::IntParserOps<UInt16LSBParser,boost::uint16_t>,
214 value_type
value()
const {
return detail::packet::parse_uint16LSB(
i()); }
215 void value(value_type v) { detail::packet::write_uint16LSB(
i(),v); }
222 { os << i.
value();
return os; }
229 :
public detail::packet::IntParserOps<Int24Parser,boost::int32_t>,
242 value_type v (detail::packet::parse_uint24(
i()));
return v&0x800000 ? v|0xff000000 : v; }
243 void value(value_type v) { detail::packet::write_uint24(
i(),v); }
250 { os << i.
value();
return os; }
257 :
public detail::packet::IntParserOps<UInt24Parser,boost::uint32_t>,
269 value_type
value()
const {
return detail::packet::parse_uint24(
i()); }
270 void value(value_type v) { detail::packet::write_uint24(
i(),v); }
277 { os << i.
value();
return os; }
284 :
public detail::packet::IntParserOps<Int32Parser,boost::int32_t>,
296 value_type
value()
const {
return detail::packet::parse_uint32(
i()); }
297 void value(value_type v) { detail::packet::write_uint32(
i(),v); }
304 { os << i.
value();
return os; }
311 :
public detail::packet::IntParserOps<UInt32Parser,boost::uint32_t>,
323 value_type
value()
const {
return detail::packet::parse_uint32(
i()); }
324 void value(value_type v) { detail::packet::write_uint32(
i(),v); }
331 { os << i.
value();
return os; }
334 :
public detail::packet::IntParserOps<UInt32LSBParser,boost::uint32_t>,
346 value_type
value()
const {
return detail::packet::parse_uint32LSB(
i()); }
347 void value(value_type v) { detail::packet::write_uint32LSB(
i(),v); }
354 { os << i.
value();
return os; }
364 :
public detail::packet::IntParserOps<Int64Parser,boost::int64_t>,
374 value_type
value()
const {
return detail::packet::parse_uint64(
i()); }
375 void value(value_type v) { detail::packet::write_uint64(
i(),v); }
382 { os << i.
value();
return os; }
390 :
public detail::packet::IntParserOps<UInt64Parser,boost::uint64_t>,
400 value_type
value()
const {
return detail::packet::parse_uint64(
i()); }
401 void value(value_type v) { detail::packet::write_uint64(
i(),v); }
408 { os << i.
value();
return os; }
415 :
public detail::packet::IntParserOps<UInt64LSBParser,boost::uint64_t>,
425 value_type
value()
const {
return detail::packet::parse_uint64LSB(
i()); }
426 void value(value_type v) { detail::packet::write_uint64LSB(
i(),v); }
433 { os << i.
value();
return os; }
457 template <
unsigned Start,
unsigned End>
459 :
public detail::packet::IntParserOps<IntFieldParser<Start,End>,boost::int32_t>,
470 static value_type
const max_value = boost::low_bits_mask_t<End-Start-1>::sig_bits;
474 value_type v (detail::packet::parse_bitfield<Start,End>::parse(
i()));
475 return v&boost::high_bit_mask_t<End-Start-1>::high_bit ?
476 v | ~boost::low_bits_mask_t<End-Start>::sig_bits : v;
478 void value(value_type v) { detail::packet::parse_bitfield<Start,End>::write(
i(),v); }
482 BOOST_STATIC_ASSERT( Start<End );
483 BOOST_STATIC_ASSERT( End-Start<=32 );
488 template <
unsigned Start,
unsigned End>
489 inline std::ostream & operator<<(std::ostream & os, IntFieldParser<Start,End>
const &
i)
490 { os <<
i.value();
return os; }
514 template <
unsigned Start,
unsigned End>
516 :
public detail::packet::IntParserOps<UIntFieldParser<Start,End>,boost::uint32_t>,
528 static value_type
const max_value = boost::low_bits_mask_t<End-Start>::sig_bits;
530 value_type
value()
const {
return detail::packet::parse_bitfield<Start,End>::parse(
i()); }
531 void value(value_type v) { detail::packet::parse_bitfield<Start,End>::write(
i(),v); }
535 BOOST_STATIC_ASSERT( Start<End );
536 BOOST_STATIC_ASSERT( End-Start<=32 );
541 template <
unsigned Start,
unsigned End>
542 inline std::ostream & operator<<(std::ostream & os, UIntFieldParser<Start,End>
const &
i)
543 { os <<
i.value();
return os; }
559 template <
unsigned Bit>
561 :
public detail::packet::IntParserOps<FlagParser<Bit>,bool>,
574 value_type
value()
const {
return i()[Bit/8] & (1<<(7-(Bit%8))); }
576 if (v)
i()[Bit/8] |= 1<<(7-(Bit%8));
577 else i()[Bit/8] &= ~(1<<(7-(Bit%8)));
584 template <
unsigned Bit>
585 inline std::ostream & operator<<(std::ostream & os, FlagParser<Bit>
const &
i)
586 { os <<
i.value();
return os; }
592 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_IntParser_i_) 593 #define HH_SENF_Packets_IntParser_i_
PacketParser public header.
boost::int16_t value_type
Parse unsigned bitfield with up to 32bit's.
boost::uint32_t value_type
std::ostream & operator<<(std::ostream &os, UInt8Parser const &i)
Write parsed value to stream.
Parse 8bit unsigned byte aligned integer.
std::ostream & operator<<(std::ostream &os, UInt32Parser const &i)
Write parsed value to stream.
boost::int32_t value_type
Parse 64bit unsigned byte aligned integer LSB.
UInt24Parser(data_iterator i, state_type s)
Parse 16bit signed byte aligned integer.
Parse 24bit signed byte aligned integer.
boost::uint64_t value_type
Int8Parser(data_iterator i, state_type s)
static size_type const fixed_bytes
UInt8Parser(data_iterator i, state_type s)
UInt64LSBParser(data_iterator i, state_type s)
Packet data STL-sequence view.
std::ostream & operator<<(std::ostream &os, UInt16LSBParser const &i)
Write parsed value to stream.
boost::uint8_t value_type
UInt16LSBParser(data_iterator i, state_type s)
data_iterator i() const
Return beginning of data to parse.
std::ostream & operator<<(std::ostream &os, UInt64LSBParser const &i)
Write parsed value to stream.
boost::int32_t value_type
Int16Parser(data_iterator i, state_type s)
boost::int16_t value_type
Parse 64bit unsigned byte aligned integer.
Int24Parser(data_iterator i, state_type s)
FlagParser(data_iterator i, state_type s)
std::ostream & operator<<(std::ostream &os, Int8Parser const &i)
Write parsed value to stream.
Parse 8bit signed byte aligned integer.
std::ostream & operator<<(std::ostream &os, Int24Parser const &i)
Write parsed value to stream.
std::ostream & operator<<(std::ostream &os, UInt64Parser const &i)
Write parsed value to stream.
Parse 16bit signed byte aligned integer LSB.
static value_type const min_value
Parse 16bit unsigned byte aligned integer LSB.
detail::packet::size_type size_type
Unsigned integral type.
std::ostream & operator<<(std::ostream &os, Int16Parser const &i)
Write parsed value to stream.
boost::uint32_t value_type
Int16LSBParser(data_iterator i, state_type s)
std::ostream & operator<<(std::ostream &os, Int16LSBParser const &i)
Write parsed value to stream.
UInt32Parser(data_iterator i, state_type s)
Int64Parser(data_iterator i, state_type s)
std::ostream & operator<<(std::ostream &os, Int32Parser const &i)
Write parsed value to stream.
boost::int64_t value_type
Parse 24bit unsigned byte aligned integer.
Parse signed bitfield with up to 32bit's.
boost::uint64_t value_type
boost::uint32_t value_type
Int8Parser const & operator=(value_type other)
Parse 32bit signed byte aligned integer.
Parse 32bit unsigned byte aligned integer.
IntFieldParser(data_iterator i, state_type s)
static value_type const max_value
std::ostream & operator<<(std::ostream &os, UInt16Parser const &i)
Write parsed value to stream.
Int32Parser(data_iterator i, state_type s)
UIntFieldParser(data_iterator i, state_type s)
Parse 16bit unsigned byte aligned integer.
std::ostream & operator<<(std::ostream &os, UInt24Parser const &i)
Write parsed value to stream.
UInt32LSBParser(data_iterator i, state_type s)
boost::uint16_t value_type
boost::uint32_t value_type
Parse 64bit signed byte aligned integer.
detail::packet::iterator data_iterator
Raw data iterator type.
UInt64Parser(data_iterator i, state_type s)
UInt16Parser(data_iterator i, state_type s)
boost::uint16_t value_type
std::ostream & operator<<(std::ostream &os, UInt32LSBParser const &i)
Write parsed value to stream.
boost::int32_t value_type
std::ostream & operator<<(std::ostream &os, Int64Parser const &i)
Write parsed value to stream.