veil_serialise.c File Reference


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.

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

Include dependency graph for veil_serialise.c:

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.
static int hdrlen (char *name)
 Return the length of the header part of a serialised data stream for the given named variable.
static void serialise_int4 (char **p_stream, int4 value)
 Serialise an int4 value as a base64 stream (truncated to save a byte) into *p_stream.
static int4 deserialise_int4 (char **p_stream)
 De-serialise an int4 value from a base64 character stream.
static void serialise_stream (char **p_stream, int4 bytes, char *instream)
 Serialise a binary stream as a base64 stream into *p_stream.
static void deserialise_stream (char **p_stream, int4 bytes, char *outstream)
 De-serialise a binary stream.
static void serialise_bool (char **p_stream, bool value)
 Serialise a boolean value into *p_stream.
static bool deserialise_bool (char **p_stream)
 De-serialise a boolean value.
static void serialise_char (char **p_stream, char value)
 Serialise a character value into *p_stream.
static char deserialise_char (char **p_stream)
 De-serialise a character value.
static void serialise_name (char **p_stream, char *name)
 Serialise a string (containing a name) into *p_stream.
static char * deserialise_name (char **p_stream)
 De-serialise a string returning a dynamically allocated string.
static char * serialise_int4var (Int4Var *var, char *name)
 Serialise a veil integer variable into a dynamically allocated string.
static VarEntrydeserialise_int4var (char **p_stream)
 De-serialise a veil integer variable.
static char * serialise_int4array (Int4Array *array, char *name)
 Serialise a veil integer array variable into a dynamically allocated string.
static VarEntrydeserialise_int4array (char **p_stream)
 De-serialise a veil integer array variable.
static char * serialise_range (Range *range, char *name)
 Serialise a veil range variable into a dynamically allocated string.
static VarEntrydeserialise_range (char **p_stream)
 De-serialise a veil range variable.
static void serialise_one_bitmap (char **p_stream, Bitmap *bitmap)
 Serialise a single bitmap from a veil bitmap array or bitmap hash.
static char * serialise_bitmap (Bitmap *bitmap, char *name)
 Serialise a veil bitmap variable into a dynamically allocated string.
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.
static VarEntrydeserialise_bitmap (char **p_stream)
 De-serialise a veil bitmap variable.
static char * serialise_bitmap_array (BitmapArray *bmarray, char *name)
 Serialise a veil bitmap array variable into a dynamically allocated string.
static VarEntrydeserialise_bitmap_array (char **p_stream)
 De-serialise a veil bitmap array variable.
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.
static char * serialise_bitmap_hash (BitmapHash *bmhash, char *name)
 Serialise a veil bitmap hash variable into a dynamically allocated string.
static VarEntrydeserialise_bitmap_hash (char **p_stream)
 De-serialise a veil bitmap hash variable.
char * vl_serialise_var (char *name)
 Serialise a veil variable.
VarEntryvl_deserialise_next (char **p_stream)
 De-serialise the next veil variable from *p_stream.
int4 vl_deserialise (char **p_stream)
 De-serialise a base64 string containing, possibly many, derialised veil variables.


Function Documentation

static int streamlen ( int  bytes  )  [static]

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

Parameters:
bytes The 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 190 of file veil_serialise.c.

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

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:
name The 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 205 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().

static void serialise_int4 ( char **  p_stream,
int4  value 
) [static]

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

Parameters:
p_stream Pointer 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.
value The value to be written to the stream.

Definition at line 222 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().

static int4 deserialise_int4 ( char **  p_stream  )  [static]

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

Parameters:
p_stream Pointer 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 240 of file veil_serialise.c.

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

static void serialise_stream ( char **  p_stream,
int4  bytes,
char *  instream 
) [static]

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

Parameters:
p_stream Pointer 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.
bytes The number of bytes to be written.
instream The binary stream to be written.

Definition at line 263 of file veil_serialise.c.

Referenced by serialise_int4array(), and serialise_one_bitmap().

static void deserialise_stream ( char **  p_stream,
int4  bytes,
char *  outstream 
) [static]

De-serialise a binary stream.

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

Definition at line 281 of file veil_serialise.c.

References streamlen().

Referenced by deserialise_int4array(), and deserialise_one_bitmap().

Here is the call graph for this function:

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

Serialise a boolean value into *p_stream.

Parameters:
p_stream Pointer 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'.
value The boolean value to be written.

Definition at line 299 of file veil_serialise.c.

Referenced by serialise_int4var().

static bool deserialise_bool ( char **  p_stream  )  [static]

De-serialise a boolean value.

Parameters:
p_stream Pointer 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 315 of file veil_serialise.c.

Referenced by deserialise_int4var().

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

Serialise a character value into *p_stream.

Parameters:
p_stream Pointer 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.
value The character value to be written.

Definition at line 333 of file veil_serialise.c.

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

static char deserialise_char ( char **  p_stream  )  [static]

De-serialise a character value.

Parameters:
p_stream Pointer 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 349 of file veil_serialise.c.

Referenced by deserialise_bitmap_hash(), and vl_deserialise_next().

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

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

Parameters:
p_stream Pointer 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.
name The string to be written.

Definition at line 367 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().

Here is the call graph for this function:

static char* deserialise_name ( char **  p_stream  )  [static]

De-serialise a string returning a dynamically allocated string.

Parameters:
p_stream Pointer 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 393 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().

Here is the call graph for this function:

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

Serialise a veil integer variable into a dynamically allocated string.

Parameters:
var Pointer to the variable to be serialised
name The name of the variable
Returns:
Dynamically allocated string containing the serialised variable

Definition at line 412 of file veil_serialise.c.

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

Referenced by vl_serialise_var().

Here is the call graph for this function:

static VarEntry* deserialise_int4var ( char **  p_stream  )  [static]

De-serialise a veil integer variable.

Parameters:
**p_stream Pointer 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 434 of file veil_serialise.c.

References deserialise_bool(), deserialise_int4(), deserialise_name(), Int4Var::isnull, VarEntry::obj, VarEntry::shared, Int4Var::type, Int4Var::value, vl_lookup_variable(), vl_NewInt4(), and vl_type_mismatch().

Referenced by vl_deserialise_next().

Here is the call graph for this function:

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

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

Parameters:
array Pointer to the variable to be serialised
name The name of the variable
Returns:
Dynamically allocated string containing the serialised variable

Definition at line 464 of file veil_serialise.c.

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

Referenced by vl_serialise_var().

Here is the call graph for this function:

static VarEntry* deserialise_int4array ( char **  p_stream  )  [static]

De-serialise a veil integer array variable.

Parameters:
**p_stream Pointer 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 491 of file veil_serialise.c.

References Int4Array::array, deserialise_int4(), deserialise_name(), deserialise_stream(), VarEntry::obj, VarEntry::shared, Int4Array::type, vl_lookup_variable(), vl_NewInt4Array(), and vl_type_mismatch().

Referenced by vl_deserialise_next().

Here is the call graph for this function:

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

Serialise a veil range variable into a dynamically allocated string.

Parameters:
range Pointer to the variable to be serialised
name The name of the variable
Returns:
Dynamically allocated string containing the serialised variable

Definition at line 527 of file veil_serialise.c.

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

Referenced by vl_serialise_var().

Here is the call graph for this function:

static VarEntry* deserialise_range ( char **  p_stream  )  [static]

De-serialise a veil range variable.

Parameters:
**p_stream Pointer 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 549 of file veil_serialise.c.

References deserialise_int4(), deserialise_name(), Range::max, Range::min, VarEntry::obj, VarEntry::shared, Range::type, vl_lookup_variable(), vl_NewRange(), and vl_type_mismatch().

Referenced by vl_deserialise_next().

Here is the call graph for this function:

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_stream Pointer into the stream currently being read. pointer is updated to point to the next free slot in the stream after writing the stream.
bitmap The bitmap to be serialised.

Definition at line 579 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().

Here is the call graph for this function:

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

Serialise a veil bitmap variable into a dynamically allocated string.

Parameters:
bitmap Pointer to the variable to be serialised
name The name of the variable
Returns:
Dynamically allocated string containing the serialised variable

Definition at line 598 of file veil_serialise.c.

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

Referenced by vl_serialise_var().

Here is the call graph for this function:

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_bitmap Pointer to bitmap pointer. This may be updated to contain a dynamically allocated bitmap if none is already present.
name The name of the variable, for error reporting purposes.
shared Whether the bitmap is part of a shared rather than session variable.
p_stream Pointer 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 625 of file veil_serialise.c.

References ARRAYELEMS, Bitmap::bitset, deserialise_int4(), deserialise_stream(), Bitmap::type, vl_NewBitmap(), and vl_type_mismatch().

Referenced by deserialise_bitmap(), deserialise_bitmap_array(), and deserialise_bitmap_hash().

Here is the call graph for this function:

static VarEntry* deserialise_bitmap ( char **  p_stream  )  [static]

De-serialise a veil bitmap variable.

Parameters:
**p_stream Pointer 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 660 of file veil_serialise.c.

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

Referenced by vl_deserialise_next().

Here is the call graph for this function:

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

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

Parameters:
bmarray Pointer to the variable to be serialised
name The name of the variable
Returns:
Dynamically allocated string containing the serialised variable

Definition at line 681 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().

Referenced by vl_serialise_var().

Here is the call graph for this function:

static VarEntry* deserialise_bitmap_array ( char **  p_stream  )  [static]

De-serialise a veil bitmap array variable.

Parameters:
**p_stream Pointer 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 714 of file veil_serialise.c.

References BitmapArray::bitmap, deserialise_int4(), deserialise_name(), deserialise_one_bitmap(), VarEntry::obj, VarEntry::shared, BitmapArray::type, vl_lookup_variable(), vl_NewBitmapArray(), and vl_type_mismatch().

Referenced by vl_deserialise_next().

Here is the call graph for this function:

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:
bmhash Pointer to the variable to be serialised
bitset_size The 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 762 of file veil_serialise.c.

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

Referenced by serialise_bitmap_hash().

Here is the call graph for this function:

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

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

Parameters:
bmhash Pointer to the variable to be serialised
name The name of the variable
Returns:
Dynamically allocated string containing the serialised variable

Definition at line 785 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().

Referenced by vl_serialise_var().

Here is the call graph for this function:

static VarEntry* deserialise_bitmap_hash ( char **  p_stream  )  [static]

De-serialise a veil bitmap hash variable.

Parameters:
**p_stream Pointer 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 820 of file veil_serialise.c.

References deserialise_char(), deserialise_int4(), deserialise_name(), deserialise_one_bitmap(), VarEntry::obj, VarEntry::shared, BitmapHash::type, vl_AddBitmapToHash(), vl_BitmapUnion(), vl_lookup_variable(), vl_NewBitmapHash(), and vl_type_mismatch().

Referenced by vl_deserialise_next().

Here is the call graph for this function:

char* vl_serialise_var ( char *  name  ) 

Serialise a veil variable.

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

Definition at line 865 of file veil_serialise.c.

References VarEntry::obj, serialise_bitmap(), serialise_bitmap_array(), serialise_bitmap_hash(), serialise_int4array(), serialise_int4var(), serialise_range(), Object::type, and vl_lookup_variable().

Here is the call graph for this function:

VarEntry* vl_deserialise_next ( char **  p_stream  ) 

De-serialise the next veil variable from *p_stream.

Parameters:
**p_stream Pointer 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 913 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().

Here is the call graph for this function:

int4 vl_deserialise ( char **  p_stream  ) 

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

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

Definition at line 952 of file veil_serialise.c.

References vl_deserialise_next().

Referenced by veil_serialise().

Here is the call graph for this function:


Generated on Mon Sep 12 15:26:57 2011 for Veil by  doxygen 1.5.6