2 #include <SerializeBase.h> 3 #include <FormatSerialize.h> 4 #include <AsciiTableSerialize.h> 6 #ifndef CISSERIALIZE_H_ 7 #define CISSERIALIZE_H_ 15 seri_t empty_serializer() {
33 int update_serializer(
seri_t *s,
int type,
const void *info) {
36 cislog_error(
"update_serializer: Pointer to serializer is NULL.");
40 if ((type == ASCII_TABLE_SERI) || (type == ASCII_TABLE_ARRAY_SERI)) {
45 format_str = (
char*)(s->info);
47 format_str = (
char*)info;
50 cislog_error(
"update_serializer: Failed to allocate for asciiTable.");
53 handle[0] = asciiTable(
"seri",
"0", format_str, NULL, NULL, NULL);
55 if (s->info != NULL) {
59 s->info = (
void*)handle;
60 }
else if (info == NULL) {
65 char *format_str = (
char*)info;
66 s->size_info = 2*strlen(format_str) + 1;
67 void *t_sinfo = (
void*)realloc(s->info, s->size_info);
68 if (t_sinfo == NULL) {
69 cislog_error(
"update_serializer: Failed to reallocate for format string.");
75 strcpy((
char*)(s->info), format_str);
83 s->type = (seri_type)type;
94 seri_t * init_serializer(
int type,
const void *info) {
97 cislog_error(
"init_serializer: Failed to allocate serializer.");
100 s[0] = empty_serializer();
101 int flag = update_serializer(s, type, info);
103 cislog_error(
"init_serializer: Failed to create serializer.");
116 int free_serializer(
seri_t *s) {
117 if (s->info != NULL) {
138 int serialize(
const seri_t s,
char **buf,
const size_t buf_siz,
139 const int allow_realloc,
int *args_used, va_list ap) {
140 seri_type t = s.type;
146 if (t == DIRECT_SERI)
147 ret = serialize_direct(s, *buf, buf_siz, args_used, ap);
148 else if (t == FORMAT_SERI)
149 ret = serialize_format(s, *buf, buf_siz, args_used, ap);
150 else if (t == ASCII_TABLE_SERI)
151 ret = serialize_ascii_table(s, *buf, buf_siz, args_used, ap);
152 else if (t == ASCII_TABLE_ARRAY_SERI)
153 ret = serialize_ascii_table_array(s, *buf, buf_siz, args_used, ap);
155 cislog_error(
"serialize: Unsupported seri_type %d", t);
157 if (ret > (
int)buf_siz) {
159 *buf = (
char*)realloc(*buf, ret+1);
161 cislog_error(
"serialize: Failed to realloc buffer.");
164 ret = serialize(s, buf, ret+1, 0, args_used, ap2);
167 cislog_error(
"serialize: encoded message too large for the buffer. (buf_siz=%d, len=%d)",
187 int deserialize(
const seri_t s,
const char *buf,
const size_t buf_siz, va_list ap) {
188 seri_type t = s.type;
190 if (t == DIRECT_SERI)
191 ret = deserialize_direct(s, buf, buf_siz, ap);
192 else if (t == FORMAT_SERI)
193 ret = deserialize_format(s, buf, buf_siz, ap);
194 else if (t == ASCII_TABLE_SERI)
195 ret = deserialize_ascii_table(s, buf, buf_siz, ap);
196 else if (t == ASCII_TABLE_ARRAY_SERI)
197 ret = deserialize_ascii_table_array(s, buf, buf_siz, ap);
199 cislog_error(
"deserialize: Unsupported seri_type %d", t);
Serializer structure.
Definition: SerializeBase.h:15
Structure containing information about an ASCII table.
Definition: AsciiTable.h:76