2021-07-26 21:15:20 -04:00
|
|
|
/*
|
|
|
|
pdu-stream.cpp
|
|
|
|
|
|
|
|
Copyright (c) 2020 Kevin Matz (kevin.matz@gmail.com)
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
2021-08-20 10:13:00 -04:00
|
|
|
|
2023-04-02 13:24:55 -04:00
|
|
|
#include "pdu-stream.h"
|
2021-08-20 10:13:00 -04:00
|
|
|
|
|
|
|
|
2021-08-16 21:20:19 -04:00
|
|
|
/**
|
2023-04-02 13:24:55 -04:00
|
|
|
* @brief bufferstream::operator >>
|
2021-08-16 21:20:19 -04:00
|
|
|
* @param uuid
|
|
|
|
* @return
|
|
|
|
*/
|
2023-04-02 13:24:55 -04:00
|
|
|
bufferstream& operator>> (bufferstream& s, UUID::uuid& uuid)
|
2021-08-16 21:20:19 -04:00
|
|
|
{
|
2023-04-02 13:24:55 -04:00
|
|
|
uint8_t buffer[UUID_LENGTH];
|
|
|
|
s.read(buffer, UUID_LENGTH);
|
|
|
|
if (s.gcount() != UUID_LENGTH)
|
2021-08-16 21:20:19 -04:00
|
|
|
{
|
2023-04-02 13:24:55 -04:00
|
|
|
s.setstate(std::ios_base::failbit);
|
|
|
|
return s;
|
2021-08-16 21:20:19 -04:00
|
|
|
}
|
2023-04-02 13:24:55 -04:00
|
|
|
uuid.setBytes(buffer);
|
|
|
|
return s;
|
2021-08-16 21:20:19 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-08-20 09:58:59 -04:00
|
|
|
/**
|
2023-04-02 13:24:55 -04:00
|
|
|
* @brief bufferstream::operator <<
|
2021-08-16 21:20:19 -04:00
|
|
|
* @param uuid
|
|
|
|
* @return
|
|
|
|
*/
|
2023-04-02 13:24:55 -04:00
|
|
|
bufferstream& operator<< (bufferstream& s, const UUID::uuid& uuid)
|
2021-08-16 21:20:19 -04:00
|
|
|
{
|
2023-04-02 13:24:55 -04:00
|
|
|
s.write(uuid.bytes(), UUID_LENGTH);
|
|
|
|
return s;
|
2021-08-16 21:20:19 -04:00
|
|
|
}
|