diff --git a/acn/pdu.cpp b/acn/pdu.cpp index 69f0e9e..4ad3625 100644 --- a/acn/pdu.cpp +++ b/acn/pdu.cpp @@ -28,6 +28,107 @@ namespace ACN { namespace PDU { +/** + * @brief pdu_stream::operator >> + * @param val + * @return + */ +pdu_stream& pdu_stream::operator>> (uint8_t& val) +{ + val = readType(); + return *this; +}; + + +/** + * @brief pdu_stream::operator >> + * @param val + * @return + */ +pdu_stream& pdu_stream::operator>> (uint16_t& val) +{ + val = readType(); + return *this; +}; + + +/** + * @brief pdu_stream::operator >> + * @param val + * @return + */ +pdu_stream& pdu_stream::operator>> (uint32_t& val) +{ + val = readType(); + return *this; +}; + + +/** + * @brief pdu_stream::operator >> + * @param val + * @return + */ +pdu_stream& pdu_stream::operator>> (uint64_t& val) +{ + val = readType(); + return *this; +}; + + +/** + * @brief pdu_stream::operator << + * @param val + * @return + */ +pdu_stream& pdu_stream::operator<< (const uint8_t& val) +{ + writeType(val); + return *this; +} + + +/** + * @brief pdu_stream::operator << + * @param val + * @return + */ +pdu_stream& pdu_stream::operator<< (const uint16_t& val) +{ + writeType(val); + return *this; +} + + +/** + * @brief pdu_stream::operator << + * @param val + * @return + */ +pdu_stream& pdu_stream::operator<< (const uint32_t& val) +{ + writeType(val); + return *this; +} + + +/** + * @brief pdu_stream::operator << + * @param val + * @return + */ +pdu_stream& pdu_stream::operator<< (const uint64_t& val) +{ + writeType(val); + return *this; +} + + +/** + * @brief Pdu::Pdu + * @param stream + * @param vector_size + */ Pdu::Pdu(Stream stream, size_t vector_size) : flags_(stream->peek()) { @@ -76,12 +177,19 @@ Pdu::Pdu(Stream stream, size_t vector_size) } +/** + * @brief Pdu::~Pdu + */ Pdu::~Pdu() { if (header_) delete header_; if (data_) delete data_; } +/** + * @brief Pdu::vector + * @return + */ const uint32_t Pdu::vector() { if (flags_.hasVector) return vector_; @@ -91,6 +199,10 @@ const uint32_t Pdu::vector() { } +/** + * @brief Pdu::header + * @return + */ pdu_header * Pdu::header() { if (flags_.hasHeader) return header_; @@ -100,6 +212,10 @@ pdu_header * Pdu::header() { } +/** + * @brief Pdu::data + * @return + */ pdu_data * Pdu::data() { if (flags_.hasData) return data_; @@ -109,6 +225,10 @@ pdu_data * Pdu::data() { } +/** + * @brief Pdu::readLength + * @param stream + */ void Pdu::readLength(Stream stream) { length_ = stream->readType() & 0x0fff; // high 4 bytes are flags if (flags_.hasLength) @@ -116,6 +236,10 @@ void Pdu::readLength(Stream stream) { } +/** + * @brief Pdu::readVector + * @param vector_size + */ void Pdu::readVector(uint8_t vector_size) { vector_ = 0; for (int o = vector_size - 1; o >= 0; o--) @@ -123,6 +247,10 @@ void Pdu::readVector(uint8_t vector_size) { } +/** + * @brief pdu_flags::pdu_flags + * @param val + */ pdu_flags::pdu_flags(uint8_t val) { hasLength = (val >> 7) & 0b1; hasVector = (val >> 6) & 0b1; diff --git a/acn/pdu.h b/acn/pdu.h index f311fe2..ae7e36b 100644 --- a/acn/pdu.h +++ b/acn/pdu.h @@ -72,18 +72,14 @@ public: } uint32_t available() { return in_avail(); } uint8_t * data() { return gptr(); }; - pdu_stream& operator>> (uint8_t& val) { - val = readType(); - return *this; - }; - pdu_stream& operator>> (uint16_t& val) { - val = readType(); - return *this; - }; - pdu_stream& operator>> (uint32_t& val) { - val = readType(); - return *this; - }; + pdu_stream& operator>> (uint8_t& val); + pdu_stream& operator>> (uint16_t& val); + pdu_stream& operator>> (uint32_t& val); + pdu_stream& operator>> (uint64_t& val); + 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); template T readType() { if (in_avail() < sizeof(T)) { setstate(std::ios_base::failbit); @@ -97,6 +93,11 @@ public: setstate(std::ios_base::eofbit); return ret; } + template void writeType (const T& val) { + auto data = reinterpret_cast(&val); + for (int i = sizeof(T); --i >= 0; ) + put(data[i]); + } }; using Stream = shared_ptr;