serialize.h

00001 /* 
00002  * Copyright (C) 2005 iptelorg GmbH
00003  *
00004  * This file is part of ser, a free SIP server.
00005  *
00006  * ser is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version
00010  *
00011  * For a license to use the ser software under conditions
00012  * other than those described here, or to purchase support for this
00013  * software, please contact iptel.org by e-mail at the following addresses:
00014  *    info@iptel.org
00015  *
00016  * ser is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  */
00025 
00026 #ifndef __SERIALIZE_H
00027 #define __SERIALIZE_H
00028 
00029 /* serialization/deserialization data structures and functions */
00030 
00031 #include <cds/dstring.h>
00032 
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036 
00037 typedef struct {
00038         dstring_t out; /* output string */
00039         str_t in; /* input string */
00040         int in_pos; /* position in input */
00041         enum { sstream_in, sstream_out } type;
00042 } sstream_t;
00043 
00044 #define is_input_sstream(ss)    (ss->type == sstream_in)
00045 
00046 int init_input_sstream(sstream_t *ss, char *data_in, int data_len);
00047 int init_output_sstream(sstream_t *ss, int out_buff_resize);
00048 
00050 int get_serialized_sstream(sstream_t *ss, str_t *dst);
00051 
00053 int get_serialized_sstream_len(sstream_t *ss);
00054 
00056 int get_serialized_sstream_data(sstream_t *ss, char *dst);
00057 
00058 void destroy_sstream(sstream_t *ss);
00059 
00060 int sstream_put(sstream_t *ss, const char *s, int len);
00061 int sstream_put_str(sstream_t *ss, str_t *s);
00062 int sstream_put_zt(sstream_t *ss, const char *s);
00063 
00064 int sstream_get(sstream_t *ss, char *c);
00065 
00066 /* returns a part of string of given length - it is NOT a copy !!! */
00067 int sstream_get_str_ex(sstream_t *ss, int len, str_t *dst);
00068 
00069 /* returns a copy of string from input buffer */
00070 int sstream_get_str(sstream_t *ss, int len, str_t *dst);
00071 
00072 
00073 int serialize_int(sstream_t *ss, int *num);
00074 int serialize_uint(sstream_t *ss, unsigned int *num);
00075 int serialize_char(sstream_t *ss, char *c);
00076 int serialize_uchar(sstream_t *ss, unsigned char *c);
00077 int serialize_str(sstream_t *ss, str_t *s);
00078 int serialize_str_ex(sstream_t *ss, str_t *s); /* doesn't duplicate read strings */
00079 
00080 #ifdef __cplusplus
00081 }
00082 #endif
00083 
00084 #endif