1
0
Fork 0

pdu_stream can read/write UUID

This commit is contained in:
Kevin Matz 2021-08-16 21:20:19 -04:00
parent ed82a617e6
commit fd0eeef934
7 changed files with 52 additions and 24 deletions

View File

@ -88,6 +88,25 @@ pdu_stream& pdu_stream::operator>> (uint64_t& val)
};
/**
* @brief pdu_stream::operator >>
* @param uuid
* @return
*/
pdu_stream& pdu_stream::operator>> (UUID::uuid& uuid)
{
uint8_t buffer[UUID_LENGTH];
read(buffer, UUID_LENGTH);
if (gcount() != UUID_LENGTH)
{
setstate(std::ios_base::failbit);
return *this;
}
uuid.setBytes(buffer);
return *this;
};
/**
* @brief pdu_stream::operator <<
* @param val
@ -135,5 +154,19 @@ pdu_stream& pdu_stream::operator<< (const uint64_t& val)
return *this;
}
/**
* @brief pdu_stream::operator <<
* @param uuid
* @return
*/
pdu_stream& pdu_stream::operator<< (const UUID::uuid& uuid)
{
write(uuid.bytes(), UUID_LENGTH);
return *this;
}
} // PDU
} // ACN

View File

@ -23,6 +23,8 @@
*/
#pragma once
#include "uuid/uuid.h"
#include <memory>
#include <iostream>
@ -46,6 +48,8 @@ public:
pdu_stream& operator>> (uint16_t& val);
pdu_stream& operator>> (uint32_t& val);
pdu_stream& operator>> (uint64_t& val);
pdu_stream& operator>> (UUID::uuid& uuid);
template<typename T> T readType()
{
@ -69,6 +73,7 @@ public:
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);
template<typename T> void writeType (const T& val)
{
auto data = reinterpret_cast<const uint8_t*>(&val);

View File

@ -46,11 +46,7 @@ void rlp_header::iStream(PDU::Stream stream)
if (!stream->good())
return;
uint8_t buffer[UUID_LENGTH];
stream->read(buffer, UUID_LENGTH);
if (stream->gcount() != UUID_LENGTH)
return stream->setstate(std::ios_base::failbit);
cid = UUID::uuid(buffer);
*stream >> cid;
}
@ -60,7 +56,7 @@ void rlp_header::iStream(PDU::Stream stream)
*/
void rlp_header::oStream(PDU::Stream stream) const
{
stream->write(cid.bytes(), UUID_LENGTH);
*stream << cid;
}

View File

@ -40,6 +40,7 @@ namespace RLP {
struct rlp_header : PDU::pdu_header
{
UUID::uuid cid;
size_t streamSize() const override;
void iStream(PDU::Stream) override;
void oStream(PDU::Stream) const override;

View File

@ -73,9 +73,8 @@ void join_accept_data_t::iStream(PDU::Stream stream)
{
if (!stream->good())
return;
uint8_t buf[16];
stream->read(buf, sizeof(buf));
leader = UUID::uuid(buf);
*stream >> leader;
*stream >> number;
*stream >> mid;
*stream >> reliable;
@ -91,9 +90,8 @@ void join_refuse_data_t::iStream(PDU::Stream stream)
{
if (!stream->good())
return;
uint8_t buf[16];
stream->read(buf, sizeof(buf));
leader = UUID::uuid(buf);
*stream >> leader;
*stream >> number;
*stream >> mid;
*stream >> reliable;
@ -109,9 +107,8 @@ void nak_data_t::iStream(PDU::Stream stream)
{
if (!stream->good())
return;
uint8_t buf[16];
stream->read(buf, sizeof(buf));
leader = UUID::uuid(buf);
*stream >> leader;
*stream >> number;
*stream >> mid;
*stream >> reliable;

View File

@ -37,12 +37,7 @@ void llrp_data::iStream(ACN::PDU::Stream stream)
return;
/// Destination CID - The Destination CID indicates the CID of the intended
/// recipient of this PDU.
uint8_t * buffer = new uint8_t[UUID_LENGTH];
stream->read(buffer, UUID_LENGTH);
if (stream->gcount() != UUID_LENGTH)
stream->setstate(std::ios_base::failbit);
destination = UUID::uuid(buffer);
delete[] buffer;
*stream >> destination;
/// Transaction Number - The Transaction Number allows an LLRP Manager to
/// associate reply messages with requests.
@ -56,7 +51,7 @@ void llrp_data::iStream(ACN::PDU::Stream stream)
*/
void llrp_data::oStream(ACN::PDU::Stream stream) const
{
stream->write(destination.bytes(), UUID_LENGTH);
*stream << destination;
*stream << transaction;
if (child)
child->oStream(stream);
@ -200,7 +195,7 @@ void reply_data::iStream(ACN::PDU::Stream stream)
*stream >> id.manufacturer;
stream->read(address, sizeof(address));
if (stream->gcount() != sizeof(address))
stream->setstate(std::ios_base::failbit);
return stream->setstate(std::ios_base::failbit);
*stream >> type;
}

View File

@ -113,7 +113,7 @@ public:
uuid();
uuid(const uuid&);
uuid(const uint8_t * raw) : uuid() { fromArray_(raw); };
uuid(const char * c_str) : uuid() { fromCstring_(c_str); };
uuid(const char * c_str) : uuid() { fromCstring_(c_str); };
uuid(std::string str) : uuid() { fromString_(str); };
~uuid();
@ -131,6 +131,7 @@ public:
std::string urn() const; // 'urn:uuid:12345678-1234-5678-1234-567812345678'
// creators
void setBytes(const uint8_t * raw) { fromArray_(raw); }
virtual uint16_t uuid1(uint64_t node, uint16_t clock_seq);
// virtual void uuid3(Namespace, std::string) {};
virtual void uuid4(); // very low quality of random