mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:17:36 +00:00
LibSQL: Basic dynamic value classes for SQL Storage layer
This patch adds the basic dynamic value classes used by the SQL Storage layer. The most elementary class is Value, which holds a typed Value which can be converted to standard C++ types. A Tuple is a collection of Values described by a TupleDescriptor, which specifies the names, types, and ordering of the elements in the Tuple. Tuples and Values can be serialized and deserialized to and from ByteBuffers. This is mechanism which is used to save them to disk. Tuples are used as keys in SQL indexes and rows in SQL tables. Also included is a test file.
This commit is contained in:
parent
a6ba05b02b
commit
2a46529170
10 changed files with 1186 additions and 5 deletions
28
Userland/Libraries/LibSQL/Serialize.h
Normal file
28
Userland/Libraries/LibSQL/Serialize.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace SQL {
|
||||
|
||||
template<typename T>
|
||||
void deserialize_from(ByteBuffer& buffer, size_t& at_offset, T& t)
|
||||
{
|
||||
auto ptr = buffer.offset_pointer((int)at_offset);
|
||||
memcpy(&t, ptr, sizeof(T));
|
||||
at_offset += sizeof(T);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void serialize_to(ByteBuffer& buffer, T const& t)
|
||||
{
|
||||
buffer.append(&t, sizeof(T));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue