serenity/Userland/Libraries/LibSQL/Serialize.h
Jan de Visser 2a46529170 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.
2021-06-19 22:06:45 +02:00

28 lines
507 B
C++

/*
* 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));
}
}