/src/serenity/Userland/Libraries/LibSQL/Serializer.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021, Jan de Visser <jan@de-visser.net> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibSQL/Serializer.h> |
8 | | |
9 | | namespace SQL { |
10 | | |
11 | | void Serializer::serialize(ByteString const& text) |
12 | 0 | { |
13 | 0 | serialize<u32>(text.length()); |
14 | 0 | if (!text.is_empty()) |
15 | 0 | write((u8 const*)text.characters(), text.length()); |
16 | 0 | } |
17 | | |
18 | | void Serializer::deserialize_to(ByteString& text) |
19 | 0 | { |
20 | 0 | auto length = deserialize<u32>(); |
21 | 0 | if (length > 0) { |
22 | 0 | text = ByteString(reinterpret_cast<char const*>(read(length)), length); |
23 | 0 | } else { |
24 | 0 | text = ""; |
25 | 0 | } |
26 | 0 | } |
27 | | |
28 | | } |