Veil
veil_serialise.c File Reference

Functions serialising and de-serialising session variables. The purpose of this is to allow the contents of session variables to be saved for later re-use. They may be saved in files, temporary tables or using some smart cache such as memcached (thru the pgmemcache add-in). More...

#include "postgres.h"
#include "veil_version.h"
#include "veil_funcs.h"
#include "veil_datatypes.h"

Go to the source code of this file.

Functions

static int streamlen (int bytes)
 Return the length of a base64 encoded stream for a binary stream of ::bytes length. More...
 
static int hdrlen (char *name)
 Return the length of the header part of a serialised data stream for the given named variable. More...
 
static void serialise_int4 (char **p_stream, int32 value)
 Serialise an int4 value as a base64 stream (truncated to save a byte) into *p_stream. More...
 
static int32 deserialise_int4 (char **p_stream)
 De-serialise an int4 value from a base64 character stream. More...
 
static void serialise_stream (char **p_stream, int32 bytes, char *instream)
 Serialise a binary stream as a base64 stream into *p_stream. More...
 
static void deserialise_stream (char **p_stream, int32 bytes, char *outstream)
 De-serialise a binary stream. More...
 
static void serialise_bool (char **p_stream, bool value)
 Serialise a boolean value into *p_stream. More...
 
static bool deserialise_bool (char **p_stream)
 De-serialise a boolean value. More...
 
static void serialise_char (char **p_stream, char value)
 Serialise a character value into *p_stream. More...
 
static char deserialise_char (char **p_stream)
 De-serialise a character value. More...
 
static void serialise_name (char **p_stream, char *name)
 Serialise a string (containing a name) into *p_stream. More...
 
static char * deserialise_name (char **p_stream)
 De-serialise a string returning a dynamically allocated string. More...
 
static char * serialise_int4var (Int4Var *var, char *name)
 Serialise a veil integer variable into a dynamically allocated string. More...
 
static VarEntrydeserialise_int4var (char **p_stream)
 De-serialise a veil integer variable. More...
 
static char * serialise_int4array (Int4Array *array, char *name)
 Serialise a veil integer array variable into a dynamically allocated string. More...
 
static VarEntrydeserialise_int4array (char **p_stream)
 De-serialise a veil integer array variable. More...
 
static char * serialise_range (Range *range, char *name)
 Serialise a veil range variable into a dynamically allocated string. More...
 
static VarEntrydeserialise_range (char **p_stream)
 De-serialise a veil range variable. More...
 
static void serialise_one_bitmap (char **p_stream, Bitmap *bitmap)
 Serialise a single bitmap from a veil bitmap array or bitmap hash. More...
 
static char * serialise_bitmap (Bitmap *bitmap, char *name)
 Serialise a veil bitmap variable into a dynamically allocated string. More...
 
static void deserialise_one_bitmap (Bitmap **p_bitmap, char *name, bool shared, char **p_stream)
 De-serialise a single bitmap into a veil bitmap array or bitmap hash. More...
 
static VarEntrydeserialise_bitmap (char **p_stream)
 De-serialise a veil bitmap variable. More...
 
static char * serialise_bitmap_array (BitmapArray *bmarray, char *name)
 Serialise a veil bitmap array variable into a dynamically allocated string. More...
 
static VarEntrydeserialise_bitmap_array (char **p_stream)
 De-serialise a veil bitmap array variable. More...
 
static int sizeof_bitmaps_in_hash (BitmapHash *bmhash, int bitset_size)
 Calculate the size needed for a base64 stream to contain all of the bitmaps in a bitmap hash including their keys. More...
 
static char * serialise_bitmap_hash (BitmapHash *bmhash, char *name)
 Serialise a veil bitmap hash variable into a dynamically allocated string. More...
 
static VarEntrydeserialise_bitmap_hash (char **p_stream)
 De-serialise a veil bitmap hash variable. More...
 
char * vl_serialise_var (char *name)
 Serialise a veil variable. More...
 
VarEntryvl_deserialise_next (char **p_stream)
 De-serialise the next veil variable from *p_stream. More...
 
int32 vl_deserialise (char **p_stream)
 De-serialise a base64 string containing, possibly many, derialised veil variables. More...
 

Detailed Description

Functions serialising and de-serialising session variables. The purpose of this is to allow the contents of session variables to be saved for later re-use. They may be saved in files, temporary tables or using some smart cache such as memcached (thru the pgmemcache add-in).

Author: Marc Munro
Copyright (c) 2009 - 2011 Marc Munro
License: BSD

Definition in file veil_serialise.c.

Function Documentation

◆ streamlen()

static int streamlen ( int  bytes)
static

Return the length of a base64 encoded stream for a binary stream of ::bytes length.

Parameters
bytesThe length of the input binary stream in bytes
Returns
The length of the base64 character stream required to represent the input stream.

Definition at line 197 of file veil_serialise.c.

Referenced by deserialise_stream(), serialise_bitmap(), serialise_bitmap_array(), serialise_bitmap_hash(), and serialise_int4array().

◆ hdrlen()

static int hdrlen ( char *  name)
static

Return the length of the header part of a serialised data stream for the given named variable.

Note that the header contains the name and a base64 encode length indicator for the name.

Parameters
nameThe variable name to be recorded in the header
Returns
The length of the base64 character stream required to hold the serialised header for the named variable.

Definition at line 212 of file veil_serialise.c.

Referenced by serialise_bitmap(), serialise_bitmap_array(), serialise_bitmap_hash(), serialise_int4array(), serialise_int4var(), serialise_range(), and sizeof_bitmaps_in_hash().

◆ serialise_int4()

static void serialise_int4 ( char **  p_stream,
int32  value 
)
static

Serialise an int4 value as a base64 stream (truncated to save a byte) into *p_stream.

Parameters
p_streamPointer into stream currently being written. This must be large enought to take the contents to be written. This pointer is updated to point to the next free slot in the stream after writing the int4 value, and is null terminated at that position.
valueThe value to be written to the stream.

Definition at line 229 of file veil_serialise.c.

Referenced by serialise_bitmap_array(), serialise_bitmap_hash(), serialise_int4array(), serialise_int4var(), serialise_name(), serialise_one_bitmap(), and serialise_range().

◆ deserialise_int4()

static int32 deserialise_int4 ( char **  p_stream)
static

De-serialise an int4 value from a base64 character stream.

Parameters
p_streamPointer into the stream currently being read. must be large enought to take the contents to be written. This pointer is updated to point to the next free slot in the stream after reading the int4 value.
Returns
the int4 value read from the stream

Definition at line 247 of file veil_serialise.c.

Referenced by deserialise_bitmap_array(), deserialise_bitmap_hash(), deserialise_int4array(), deserialise_name(), and deserialise_one_bitmap().

◆ serialise_stream()

static void serialise_stream ( char **  p_stream,
int32  bytes,
char *  instream 
)
static

Serialise a binary stream as a base64 stream into *p_stream.

Parameters
p_streamPointer into stream currently being written. This pointer is updated to point to the next free slot in the stream after writing the contents of instream and is null terminated at that position.
bytesThe number of bytes to be written.
instreamThe binary stream to be written.

Definition at line 309 of file veil_serialise.c.

Referenced by serialise_int4array(), and serialise_one_bitmap().

◆ deserialise_stream()

static void deserialise_stream ( char **  p_stream,
int32  bytes,
char *  outstream 
)
static

De-serialise a binary stream.

Parameters
p_streamPointer into the stream currently being read. pointer is updated to point to the next free slot in the stream after reading the stream.
bytesThe number of bytes to be read
outstreamPointer into the pre-allocated memory are into which the binary from p_stream is to be written.

Definition at line 327 of file veil_serialise.c.

References streamlen().

◆ serialise_bool()

static void serialise_bool ( char **  p_stream,
bool  value 
)
static

Serialise a boolean value into *p_stream.

Parameters
p_streamPointer into stream currently being written. This pointer is updated to point to the next free slot in the stream after writing the contents of value and is null terminated at that position. A true value is written as 'T', and false as 'F'.
valueThe boolean value to be written.

Definition at line 345 of file veil_serialise.c.

Referenced by serialise_int4var().

◆ deserialise_bool()

static bool deserialise_bool ( char **  p_stream)
static

De-serialise a boolean value.

Parameters
p_streamPointer into the stream currently being read. pointer is updated to point to the next free slot in the stream after reading the stream.
Returns
True or false depending on the contents of p_stream.

Definition at line 361 of file veil_serialise.c.

◆ serialise_char()

static void serialise_char ( char **  p_stream,
char  value 
)
static

Serialise a character value into *p_stream.

Parameters
p_streamPointer into stream currently being written. This pointer is updated to point to the next free slot in the stream after writing the contents of value and is null terminated at that position. The character is written as a single byte character.
valueThe character value to be written.

Definition at line 379 of file veil_serialise.c.

Referenced by serialise_bitmap(), serialise_bitmap_array(), serialise_bitmap_hash(), serialise_int4array(), serialise_int4var(), and serialise_range().

◆ deserialise_char()

static char deserialise_char ( char **  p_stream)
static

De-serialise a character value.

Parameters
p_streamPointer into the stream currently being read. pointer is updated to point to the next free slot in the stream after reading the stream.
Returns
The value of the character read from p_stream.

Definition at line 395 of file veil_serialise.c.

Referenced by vl_deserialise_next().

◆ serialise_name()

static void serialise_name ( char **  p_stream,
char *  name 
)
static

Serialise a string (containing a name) into *p_stream.

Parameters
p_streamPointer into stream currently being written. This pointer is updated to point to the next free slot in the stream after writing the contents of value and is null terminated at that position. The character is written as a single byte character.
nameThe string to be written.

Definition at line 413 of file veil_serialise.c.

References serialise_int4().

Referenced by serialise_bitmap(), serialise_bitmap_array(), serialise_bitmap_hash(), serialise_int4array(), serialise_int4var(), and serialise_range().

◆ deserialise_name()

static char* deserialise_name ( char **  p_stream)
static

De-serialise a string returning a dynamically allocated string.

Parameters
p_streamPointer into the stream currently being read. pointer is updated to point to the next free slot in the stream after reading the stream.
Returns
Dynamically allocated copy of string read from *p_stream

Definition at line 439 of file veil_serialise.c.

References deserialise_int4().

Referenced by deserialise_bitmap(), deserialise_bitmap_array(), deserialise_bitmap_hash(), deserialise_int4array(), deserialise_int4var(), and deserialise_range().

◆ serialise_int4var()

static char* serialise_int4var ( Int4Var var,
char *  name 
)
static

Serialise a veil integer variable into a dynamically allocated string.

Parameters
varPointer to the variable to be serialised
nameThe name of the variable
Returns
Dynamically allocated string containing the serialised variable

Definition at line 458 of file veil_serialise.c.

References hdrlen(), Int4Var::isnull, serialise_bool(), serialise_char(), serialise_int4(), serialise_name(), and Int4Var::value.

◆ deserialise_int4var()

static VarEntry* deserialise_int4var ( char **  p_stream)
static

De-serialise a veil integer variable.

Parameters
**p_streamPointer into the stream currently being read. pointer is updated to point to the next free slot in the stream after reading the stream
Returns
Pointer to the variable created or updated from the stream.

Definition at line 480 of file veil_serialise.c.

References deserialise_name(), VarEntry::obj, Int4Var::type, and vl_lookup_variable().

Referenced by vl_deserialise_next().

◆ serialise_int4array()

static char* serialise_int4array ( Int4Array array,
char *  name 
)
static

Serialise a veil integer array variable into a dynamically allocated string.

Parameters
arrayPointer to the variable to be serialised
nameThe name of the variable
Returns
Dynamically allocated string containing the serialised variable

Definition at line 510 of file veil_serialise.c.

References Int4Array::array, Int4Array::arraymax, Int4Array::arrayzero, hdrlen(), serialise_char(), serialise_int4(), serialise_name(), serialise_stream(), and streamlen().

◆ deserialise_int4array()

static VarEntry* deserialise_int4array ( char **  p_stream)
static

De-serialise a veil integer array variable.

Parameters
**p_streamPointer into the stream currently being read. pointer is updated to point to the next free slot in the stream after reading the stream
Returns
Pointer to the variable created or updated from the stream.

Definition at line 537 of file veil_serialise.c.

References deserialise_int4(), deserialise_name(), VarEntry::obj, Int4Array::type, and vl_lookup_variable().

Referenced by vl_deserialise_next().

◆ serialise_range()

static char* serialise_range ( Range range,
char *  name 
)
static

Serialise a veil range variable into a dynamically allocated string.

Parameters
rangePointer to the variable to be serialised
nameThe name of the variable
Returns
Dynamically allocated string containing the serialised variable

Definition at line 573 of file veil_serialise.c.

References hdrlen(), Range::max, Range::min, serialise_char(), serialise_int4(), and serialise_name().

◆ deserialise_range()

static VarEntry* deserialise_range ( char **  p_stream)
static

De-serialise a veil range variable.

Parameters
**p_streamPointer into the stream currently being read. pointer is updated to point to the next free slot in the stream after reading the stream
Returns
Pointer to the variable created or updated from the stream.

Definition at line 595 of file veil_serialise.c.

References deserialise_name(), VarEntry::obj, Range::type, and vl_lookup_variable().

Referenced by vl_deserialise_next().

◆ serialise_one_bitmap()

static void serialise_one_bitmap ( char **  p_stream,
Bitmap bitmap 
)
static

Serialise a single bitmap from a veil bitmap array or bitmap hash.

Parameters
p_streamPointer into the stream currently being read. pointer is updated to point to the next free slot in the stream after writing the stream.
bitmapThe bitmap to be serialised.

Definition at line 625 of file veil_serialise.c.

References ARRAYELEMS, Bitmap::bitmax, Bitmap::bitset, Bitmap::bitzero, serialise_int4(), and serialise_stream().

Referenced by serialise_bitmap(), serialise_bitmap_array(), and serialise_bitmap_hash().

◆ serialise_bitmap()

static char* serialise_bitmap ( Bitmap bitmap,
char *  name 
)
static

Serialise a veil bitmap variable into a dynamically allocated string.

Parameters
bitmapPointer to the variable to be serialised
nameThe name of the variable
Returns
Dynamically allocated string containing the serialised variable

Definition at line 644 of file veil_serialise.c.

References ARRAYELEMS, Bitmap::bitmax, Bitmap::bitzero, hdrlen(), serialise_char(), serialise_name(), serialise_one_bitmap(), and streamlen().

◆ deserialise_one_bitmap()

static void deserialise_one_bitmap ( Bitmap **  p_bitmap,
char *  name,
bool  shared,
char **  p_stream 
)
static

De-serialise a single bitmap into a veil bitmap array or bitmap hash.

Parameters
p_bitmapPointer to bitmap pointer. This may be updated to contain a dynamically allocated bitmap if none is already present.
nameThe name of the variable, for error reporting purposes.
sharedWhether the bitmap is part of a shared rather than session variable.
p_streamPointer into the stream currently being read. pointer is updated to point to the next free slot in the stream after reading the stream.

Definition at line 671 of file veil_serialise.c.

References ARRAYELEMS, deserialise_int4(), and Bitmap::type.

Referenced by deserialise_bitmap().

◆ deserialise_bitmap()

static VarEntry* deserialise_bitmap ( char **  p_stream)
static

De-serialise a veil bitmap variable.

Parameters
**p_streamPointer into the stream currently being read. pointer is updated to point to the next free slot in the stream after reading the stream
Returns
Pointer to the variable created or updated from the stream.

Definition at line 706 of file veil_serialise.c.

References deserialise_name(), deserialise_one_bitmap(), VarEntry::obj, VarEntry::shared, and vl_lookup_variable().

Referenced by vl_deserialise_next().

◆ serialise_bitmap_array()

static char* serialise_bitmap_array ( BitmapArray bmarray,
char *  name 
)
static

Serialise a veil bitmap array variable into a dynamically allocated string.

Parameters
bmarrayPointer to the variable to be serialised
nameThe name of the variable
Returns
Dynamically allocated string containing the serialised variable

Definition at line 727 of file veil_serialise.c.

References ARRAYELEMS, BitmapArray::arraymax, BitmapArray::arrayzero, BitmapArray::bitmap, BitmapArray::bitmax, BitmapArray::bitzero, hdrlen(), serialise_char(), serialise_int4(), serialise_name(), serialise_one_bitmap(), and streamlen().

◆ deserialise_bitmap_array()

static VarEntry* deserialise_bitmap_array ( char **  p_stream)
static

De-serialise a veil bitmap array variable.

Parameters
**p_streamPointer into the stream currently being read. pointer is updated to point to the next free slot in the stream after reading the stream
Returns
Pointer to the variable created or updated from the stream.

Definition at line 760 of file veil_serialise.c.

References deserialise_int4(), deserialise_name(), VarEntry::obj, BitmapArray::type, and vl_lookup_variable().

Referenced by vl_deserialise_next().

◆ sizeof_bitmaps_in_hash()

static int sizeof_bitmaps_in_hash ( BitmapHash bmhash,
int  bitset_size 
)
static

Calculate the size needed for a base64 stream to contain all of the bitmaps in a bitmap hash including their keys.

Parameters
bmhashPointer to the variable to be serialised
bitset_sizeThe size, in bytes, of each bitset in the bitmap hash.
Returns
Number of bytes required to contain all of the bitmaps and keys in the bitmap_hash

Definition at line 808 of file veil_serialise.c.

References BitmapHash::hash, hdrlen(), VarEntry::key, and vl_NextHashEntry().

Referenced by serialise_bitmap_hash().

◆ serialise_bitmap_hash()

static char* serialise_bitmap_hash ( BitmapHash bmhash,
char *  name 
)
static

Serialise a veil bitmap hash variable into a dynamically allocated string.

Parameters
bmhashPointer to the variable to be serialised
nameThe name of the variable
Returns
Dynamically allocated string containing the serialised variable

Definition at line 831 of file veil_serialise.c.

References ARRAYELEMS, BitmapHash::bitmax, BitmapHash::bitzero, BitmapHash::hash, hdrlen(), VarEntry::key, VarEntry::obj, serialise_char(), serialise_int4(), serialise_name(), serialise_one_bitmap(), sizeof_bitmaps_in_hash(), streamlen(), and vl_NextHashEntry().

◆ deserialise_bitmap_hash()

static VarEntry* deserialise_bitmap_hash ( char **  p_stream)
static

De-serialise a veil bitmap hash variable.

Parameters
**p_streamPointer into the stream currently being read. pointer is updated to point to the next free slot in the stream after reading the stream
Returns
Pointer to the variable created or updated from the stream.

Definition at line 866 of file veil_serialise.c.

References deserialise_int4(), deserialise_name(), VarEntry::obj, BitmapHash::type, and vl_lookup_variable().

Referenced by vl_deserialise_next().

◆ vl_serialise_var()

char* vl_serialise_var ( char *  name)

Serialise a veil variable.

Parameters
nameThe name of the variable to be serialised.
Returns
Dynamically allocated string containing the serialised value.

Definition at line 911 of file veil_serialise.c.

References VarEntry::obj, Object::type, and vl_lookup_variable().

Referenced by veil_serialise().

◆ vl_deserialise_next()

VarEntry* vl_deserialise_next ( char **  p_stream)

De-serialise the next veil variable from *p_stream.

Parameters
**p_streamPointer into the stream currently being read. pointer is updated to point to the next free slot in the stream after reading the stream
Returns
The deserialised variable.

Definition at line 958 of file veil_serialise.c.

References deserialise_bitmap(), deserialise_bitmap_array(), deserialise_bitmap_hash(), deserialise_char(), deserialise_int4array(), deserialise_int4var(), and deserialise_range().

Referenced by vl_deserialise().

◆ vl_deserialise()

int32 vl_deserialise ( char **  p_stream)

De-serialise a base64 string containing, possibly many, derialised veil variables.

Parameters
**p_streamPointer into the stream currently being read.
Returns
A count of the number of variables that have been de-serialised.

Definition at line 996 of file veil_serialise.c.

References vl_deserialise_next().

Referenced by veil_deserialise().