Author: Marc Munro Copyright (c) 2009 - 2010 Marc Munro License: BSD $Id: veil_serialise.c,v 1.3 2008/11/18 18:45:18 bloodnok Exp $
Definition in file veil_serialise.c.
#include "postgres.h"
#include "veil_version.h"
#include "veil_funcs.h"
#include "veil_datatypes.h"
Go to the source code of this file.
Defines | |
#define | INT4VAR_HDR 'V' |
#define | RANGE_HDR 'R' |
#define | BITMAP_HDR 'B' |
#define | BITMAP_ARRAY_HDR 'A' |
#define | BITMAP_HASH_HDR 'H' |
#define | INT4_ARRAY_HDR 'I' |
#define | BITMAP_HASH_MORE '>' |
#define | BITMAP_HASH_DONE '.' |
#define | HDRLEN 8 |
#define | INT32SIZE_B64 7 |
#define | BOOLSIZE 1 |
Functions | |
static unsigned | b64_encode (const char *src, unsigned len, char *dst) |
static unsigned | b64_decode (const char *src, unsigned len, char *dst) |
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 VarEntry * | deserialise_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 VarEntry * | deserialise_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 VarEntry * | deserialise_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 VarEntry * | deserialise_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 VarEntry * | deserialise_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 VarEntry * | deserialise_bitmap_hash (char **p_stream) |
De-serialise a veil bitmap hash variable. | |
char * | vl_serialise_var (char *name) |
Serialise a veil variable. | |
VarEntry * | vl_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. | |
Variables | |
static const char | _base64 [] |
static const int8 | b64lookup [128] |
static int streamlen | ( | int | bytes | ) | [static] |
Return the length of a base64 encoded stream for a binary stream of bytes length.
bytes | The length of the input binary stream in bytes |
Definition at line 190 of file veil_serialise.c.
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.
name | The variable name to be recorded in the header |
Definition at line 205 of file veil_serialise.c.
Referenced by 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.
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.
static int4 deserialise_int4 | ( | char ** | p_stream | ) | [static] |
De-serialise an int4 value from a base64 character stream.
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. |
Definition at line 241 of file veil_serialise.c.
static void serialise_stream | ( | char ** | p_stream, | |
int4 | bytes, | |||
char * | instream | |||
) | [static] |
Serialise a binary stream as a base64 stream into *p_stream.
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 265 of file veil_serialise.c.
static void deserialise_stream | ( | char ** | p_stream, | |
int4 | bytes, | |||
char * | outstream | |||
) | [static] |
De-serialise a binary stream.
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 284 of file veil_serialise.c.
static void serialise_bool | ( | char ** | p_stream, | |
bool | value | |||
) | [static] |
Serialise a boolean value into *p_stream.
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 304 of file veil_serialise.c.
static bool deserialise_bool | ( | char ** | p_stream | ) | [static] |
De-serialise a boolean value.
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 320 of file veil_serialise.c.
static void serialise_char | ( | char ** | p_stream, | |
char | value | |||
) | [static] |
Serialise a character value into *p_stream.
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 338 of file veil_serialise.c.
static char deserialise_char | ( | char ** | p_stream | ) | [static] |
De-serialise a character value.
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 354 of file veil_serialise.c.
static void serialise_name | ( | char ** | p_stream, | |
char * | name | |||
) | [static] |
Serialise a string (containing a name) into *p_stream.
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 372 of file veil_serialise.c.
static char* deserialise_name | ( | char ** | p_stream | ) | [static] |
De-serialise a string returning a dynamically allocated string.
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 398 of file veil_serialise.c.
static char* serialise_int4var | ( | Int4Var * | var, | |
char * | name | |||
) | [static] |
Serialise a veil integer variable into a dynamically allocated string.
var | Pointer to the variable to be serialised | |
name | The name of the variable |
Definition at line 418 of file veil_serialise.c.
static VarEntry* deserialise_int4var | ( | char ** | p_stream | ) | [static] |
De-serialise a veil integer 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 440 of file veil_serialise.c.
static char* serialise_int4array | ( | Int4Array * | array, | |
char * | name | |||
) | [static] |
Serialise a veil integer array variable into a dynamically allocated string.
array | Pointer to the variable to be serialised | |
name | The name of the variable |
Definition at line 470 of file veil_serialise.c.
static VarEntry* deserialise_int4array | ( | char ** | p_stream | ) | [static] |
De-serialise a veil integer array 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 497 of file veil_serialise.c.
static char* serialise_range | ( | Range * | range, | |
char * | name | |||
) | [static] |
Serialise a veil range variable into a dynamically allocated string.
range | Pointer to the variable to be serialised | |
name | The name of the variable |
Definition at line 534 of file veil_serialise.c.
static VarEntry* deserialise_range | ( | char ** | p_stream | ) | [static] |
De-serialise a veil range 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 556 of file veil_serialise.c.
static void serialise_one_bitmap | ( | char ** | p_stream, | |
Bitmap * | bitmap | |||
) | [static] |
Serialise a single bitmap from a veil bitmap array or bitmap hash.
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 586 of file veil_serialise.c.
static char* serialise_bitmap | ( | Bitmap * | bitmap, | |
char * | name | |||
) | [static] |
Serialise a veil bitmap variable into a dynamically allocated string.
bitmap | Pointer to the variable to be serialised | |
name | The name of the variable |
Definition at line 605 of file veil_serialise.c.
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.
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 632 of file veil_serialise.c.
static VarEntry* deserialise_bitmap | ( | char ** | p_stream | ) | [static] |
De-serialise a veil bitmap 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 667 of file veil_serialise.c.
static char* serialise_bitmap_array | ( | BitmapArray * | bmarray, | |
char * | name | |||
) | [static] |
Serialise a veil bitmap array variable into a dynamically allocated string.
bmarray | Pointer to the variable to be serialised | |
name | The name of the variable |
Definition at line 688 of file veil_serialise.c.
static VarEntry* deserialise_bitmap_array | ( | char ** | p_stream | ) | [static] |
De-serialise a veil bitmap array 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 722 of file veil_serialise.c.
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.
bmhash | Pointer to the variable to be serialised | |
bitset_size | The size, in bytes, of each bitset in the bitmap hash. |
Definition at line 771 of file veil_serialise.c.
References hdrlen(), and VarEntry::key.
static char* serialise_bitmap_hash | ( | BitmapHash * | bmhash, | |
char * | name | |||
) | [static] |
Serialise a veil bitmap hash variable into a dynamically allocated string.
bmhash | Pointer to the variable to be serialised | |
name | The name of the variable |
Definition at line 795 of file veil_serialise.c.
static VarEntry* deserialise_bitmap_hash | ( | char ** | p_stream | ) | [static] |
De-serialise a veil bitmap hash 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 832 of file veil_serialise.c.
char* vl_serialise_var | ( | char * | name | ) |
Serialise a veil variable.
name | The name of the variable to be serialised. |
Definition at line 877 of file veil_serialise.c.
VarEntry* vl_deserialise_next | ( | char ** | p_stream | ) |
De-serialise the next veil variable from *p_stream.
**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 925 of file veil_serialise.c.
int4 vl_deserialise | ( | char ** | p_stream | ) |
De-serialise a base64 string containing, possibly many, derialised veil variables.
**p_stream | Pointer into the stream currently being read. |
Definition at line 964 of file veil_serialise.c.
Referenced by veil_serialise().
const char _base64[] [static] |
Initial value:
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Definition at line 46 of file veil_serialise.c.
const int8 b64lookup[128] [static] |
Initial value:
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, }
Definition at line 49 of file veil_serialise.c.