2021-08-18 20:50:13 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibSQL/Serializer.h>
|
|
|
|
|
|
|
|
|
|
namespace SQL {
|
|
|
|
|
|
2023-12-16 17:49:34 +03:30
|
|
|
void Serializer::serialize(ByteString const& text)
|
2021-08-18 20:50:13 -04:00
|
|
|
{
|
2023-04-19 19:03:00 +02:00
|
|
|
serialize<u32>(text.length());
|
2021-08-18 20:50:13 -04:00
|
|
|
if (!text.is_empty())
|
|
|
|
|
write((u8 const*)text.characters(), text.length());
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-16 17:49:34 +03:30
|
|
|
void Serializer::deserialize_to(ByteString& text)
|
2021-08-18 20:50:13 -04:00
|
|
|
{
|
|
|
|
|
auto length = deserialize<u32>();
|
|
|
|
|
if (length > 0) {
|
2023-12-16 17:49:34 +03:30
|
|
|
text = ByteString(reinterpret_cast<char const*>(read(length)), length);
|
2021-08-18 20:50:13 -04:00
|
|
|
} else {
|
|
|
|
|
text = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|