dpeq.serialize

Primitives used for type (de)serialization.

Members

Aliases

DeserializeF
alias DeserializeF = void function(immutable(ubyte)[] from, in FormatCode fc, in int len, scope void* val) pure @safe

Deserializing function reads 'len' bytes and writes the conversion result to the value, pointed by 'val'.

SerializeF
alias SerializeF = int function(scope ubyte[] to, scope const void* val) nothrow pure @safe

Serializing function converts value pointed to by val to PSQL network protocol format, writing it to byte buffer 'to' and returning number of bytes written, -1 if the value is null, and -2 if 'to' is too small. If result is less than -2, absolute value is the amount of bytes that is required to fully serialize the value.

VariantDeserializer
alias VariantDeserializer = NullableVariant function(scope immutable(ubyte)[] buf, in FormatCode fc, in int len) @trusted

prototype of a nullable variant deserializer, used in converter

Classes

VariantConverter
class VariantConverter(alias Serializer = DefaultFieldSerializer)

Default converter hash map. You can extend it, or define your own.

Functions

deserializeNullableStringField
void deserializeNullableStringField(immutable(ubyte)[] from, in FormatCode fc, in int len, scope Nullable!string* val)

returns inplace-constructed string without allocations. Hacky.

deserializeNumber
T deserializeNumber(scope immutable(ubyte)[] from)

Service function. Simple deserialize of some numeric type.

deserializeProtocolString
string deserializeProtocolString(immutable(ubyte)[] from, out size_t length)

dpeq utility function. Deserialize zero-terminated string from byte buffer.

deserializeString
string deserializeString(immutable(ubyte)[] from)

dpeq utility function

serializeCstring
int serializeCstring(scope ubyte[] to, scope const string s)

Service function, used for serializeling of protocol messages. Data strings are passed without trailing nulls.

Structs

FieldSpec
struct FieldSpec

Value type descriptor, constisting of an oid of the type itself and a boolean flag wich indicates wether the value can be null.

NullableVariant
struct NullableVariant

std.variant.Variant subtype that is better suited for holding SQL null. Null NullableVariant is essentially a valueless Variant instance.

Templates

DefaultSerializer
template DefaultSerializer(FieldSpec field, alias Pre = NopSerializer, alias Post = StringSerializer)

Default compile-time one-to-many mapper, wich for OID of some Postgres type gives it's native type representation, and serializing and deserializing functions. You can extend it with two custom mappers: Pre and Post.

FSpecsToFCodes
template FSpecsToFCodes(FieldSpec[] specs, alias Serializer = DefaultSerializer)

Utility template to quickly get an array of format codes from an array of FieldSpecs

NopSerializer
template NopSerializer(FieldSpec type)

Can't serialize shit

StaticFieldSerializer
template StaticFieldSerializer(FieldSpec field)

Types wich are well-known to dpeq

StringSerializer
template StringSerializer(FieldSpec field)

This is a fallback serializeler that simply accepts any type as a string

Meta

Authors

Boris-Barboris