Remove Session prefix from some session-related classes and files

This commit is contained in:
Tim Wojtulewicz 2021-04-27 12:48:53 -07:00
parent 18c6aaaa33
commit 0b7ca5e7bc
37 changed files with 121 additions and 122 deletions

67
src/session/Key.cc Normal file
View file

@ -0,0 +1,67 @@
#include "zeek/session/Key.h"
#include <cstring>
namespace zeek::session::detail {
Key::Key(const void* session, size_t size, bool copy) : size(size)
{
data = reinterpret_cast<const uint8_t*>(session);
if ( copy )
CopyData();
}
Key::Key(Key&& rhs)
{
data = rhs.data;
size = rhs.size;
copied = rhs.copied;
rhs.data = nullptr;
rhs.size = 0;
rhs.copied = false;
}
Key& Key::operator=(Key&& rhs)
{
if ( this != &rhs )
{
data = rhs.data;
size = rhs.size;
copied = rhs.copied;
rhs.data = nullptr;
rhs.size = 0;
rhs.copied = false;
}
return *this;
}
Key::~Key()
{
if ( copied )
delete [] data;
}
void Key::CopyData()
{
if ( copied )
return;
copied = true;
uint8_t *temp = new uint8_t[size];
memcpy(temp, data, size);
data = temp;
}
bool Key::operator<(const Key& rhs) const
{
if ( size != rhs.size )
return size < rhs.size;
return memcmp(data, rhs.data, size) < 0;
}
} // namespace zeek::session::detail