stream operators for signed integers
This commit is contained in:
parent
1c9f1e3769
commit
914be1f3f9
|
@ -136,6 +136,103 @@ pdu_stream& pdu_stream::operator>> (uint64_t& val)
|
|||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief pdu_stream::operator >>
|
||||
* @param val
|
||||
* @return
|
||||
*/
|
||||
pdu_stream& pdu_stream::operator>> (int8_t& val)
|
||||
{
|
||||
val = readType<int8_t>();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief pdu_stream::operator <<
|
||||
* @param val
|
||||
* @return
|
||||
*/
|
||||
pdu_stream& pdu_stream::operator<< (const int8_t& val)
|
||||
{
|
||||
writeType<int8_t>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief pdu_stream::operator >>
|
||||
* @param val
|
||||
* @return
|
||||
*/
|
||||
pdu_stream& pdu_stream::operator>> (int16_t& val)
|
||||
{
|
||||
val = readType<int16_t>();
|
||||
return *this;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief pdu_stream::operator <<
|
||||
* @param val
|
||||
* @return
|
||||
*/
|
||||
pdu_stream& pdu_stream::operator<< (const int16_t& val)
|
||||
{
|
||||
writeType<int16_t>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief pdu_stream::operator >>
|
||||
* @param val
|
||||
* @return
|
||||
*/
|
||||
pdu_stream& pdu_stream::operator>> (int32_t& val)
|
||||
{
|
||||
val = readType<int32_t>();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief pdu_stream::operator <<
|
||||
* @param val
|
||||
* @return
|
||||
*/
|
||||
pdu_stream& pdu_stream::operator<< (const int32_t& val)
|
||||
{
|
||||
writeType<int32_t>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief pdu_stream::operator >>
|
||||
* @param val
|
||||
* @return
|
||||
*/
|
||||
pdu_stream& pdu_stream::operator>> (int64_t& val)
|
||||
{
|
||||
val = readType<int64_t>();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief pdu_stream::operator <<
|
||||
* @param val
|
||||
* @return
|
||||
*/
|
||||
pdu_stream& pdu_stream::operator<< (const int64_t& val)
|
||||
{
|
||||
writeType<int64_t>(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief pdu_stream::operator >>
|
||||
* @param uuid
|
||||
|
|
|
@ -47,15 +47,44 @@ public:
|
|||
// input sequence
|
||||
uint32_t available() { return in_avail(); }
|
||||
uint8_t * data() { return gptr(); }
|
||||
|
||||
// output sequence
|
||||
uint32_t size() { return pptr() - pbase(); }
|
||||
uint8_t * base() { return pbase(); }
|
||||
|
||||
// stream objects
|
||||
pdu_stream& operator>> (pdu_stream_object& obj);
|
||||
pdu_stream& operator<< (const pdu_stream_object& obj);
|
||||
|
||||
// unsigned integer
|
||||
pdu_stream& operator>> (uint8_t& val);
|
||||
pdu_stream& operator<< (const uint8_t& val);
|
||||
pdu_stream& operator>> (uint16_t& val);
|
||||
pdu_stream& operator<< (const uint16_t& val);
|
||||
pdu_stream& operator>> (uint32_t& val);
|
||||
pdu_stream& operator<< (const uint32_t& val);
|
||||
pdu_stream& operator>> (uint64_t& val);
|
||||
pdu_stream& operator<< (const uint64_t& val);
|
||||
|
||||
// signed integer
|
||||
pdu_stream& operator>> (int8_t& val);
|
||||
pdu_stream& operator<< (const int8_t& val);
|
||||
pdu_stream& operator>> (int16_t& val);
|
||||
pdu_stream& operator<< (const int16_t& val);
|
||||
pdu_stream& operator>> (int32_t& val);
|
||||
pdu_stream& operator<< (const int32_t& val);
|
||||
pdu_stream& operator>> (int64_t& val);
|
||||
pdu_stream& operator<< (const int64_t& val);
|
||||
|
||||
// uuid
|
||||
pdu_stream& operator>> (UUID::uuid& uuid);
|
||||
pdu_stream& operator<< (const UUID::uuid& uuid);
|
||||
|
||||
// strings
|
||||
void readString(std::string& str, const int fixed_length = 0);
|
||||
void writeString(const std::string& str, const int fixed_length = 0);
|
||||
|
||||
// reinterpreted i/o
|
||||
template<typename T> T readType()
|
||||
{
|
||||
if (in_avail() < sizeof(T))
|
||||
|
@ -70,19 +99,6 @@ public:
|
|||
setstate(std::ios_base::eofbit);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// output sequence
|
||||
uint32_t size() { return pptr() - pbase(); }
|
||||
uint8_t * base() { return pbase(); }
|
||||
pdu_stream& operator<< (const pdu_stream_object& obj);
|
||||
pdu_stream& operator<< (const uint8_t& val);
|
||||
pdu_stream& operator<< (const uint16_t& val);
|
||||
pdu_stream& operator<< (const uint32_t& val);
|
||||
pdu_stream& operator<< (const uint64_t& val);
|
||||
pdu_stream& operator<< (const UUID::uuid& uuid);
|
||||
|
||||
void writeString(const std::string& str, const int fixed_length = 0);
|
||||
|
||||
template<typename T> void writeType (const T& val)
|
||||
{
|
||||
auto data = reinterpret_cast<const uint8_t*>(&val);
|
||||
|
|
Loading…
Reference in New Issue