1 #ifndef CISSERIALIZE_H_ 2 #define CISSERIALIZE_H_ 5 #include "SerializeBase.h" 6 #include "FormatSerialize.h" 7 #include "AsciiTableSerialize.h" 8 #include "PlySerialize.h" 9 #include "ObjSerialize.h" 20 seri_t empty_serializer() {
38 int update_serializer(
seri_t *s,
int type,
const void *info) {
41 cislog_error(
"update_serializer: Pointer to serializer is NULL.");
45 if ((type == ASCII_TABLE_SERI) || (type == ASCII_TABLE_ARRAY_SERI)) {
50 format_str = (
char*)(s->info);
52 format_str = (
char*)info;
55 cislog_error(
"update_serializer: Failed to allocate for asciiTable.");
58 handle[0] = asciiTable(
"seri",
"0", format_str, NULL, NULL, NULL);
60 if (s->info != NULL) {
64 s->info = (
void*)handle;
65 }
else if (info == NULL) {
70 char *format_str = (
char*)info;
71 s->size_info = 2*strlen(format_str) + 1;
72 void *t_sinfo = (
void*)realloc(s->info, s->size_info);
73 if (t_sinfo == NULL) {
74 cislog_error(
"update_serializer: Failed to reallocate for format string.");
80 strcpy((
char*)(s->info), format_str);
88 s->type = (seri_type)type;
99 seri_t * init_serializer(
int type,
const void *info) {
102 cislog_error(
"init_serializer: Failed to allocate serializer.");
105 s[0] = empty_serializer();
106 int flag = update_serializer(s, type, info);
108 cislog_error(
"init_serializer: Failed to create serializer.");
121 int free_serializer(
seri_t *s) {
122 if (s->info != NULL) {
143 int serialize(
const seri_t s,
char **buf,
const size_t buf_siz,
144 const int allow_realloc,
int *args_used, va_list ap) {
145 seri_type t = s.type;
151 if (t == DIRECT_SERI)
152 ret = serialize_direct(s, *buf, buf_siz, args_used, ap);
153 else if (t == FORMAT_SERI)
154 ret = serialize_format(s, *buf, buf_siz, args_used, ap);
155 else if (t == ASCII_TABLE_SERI)
156 ret = serialize_ascii_table(s, *buf, buf_siz, args_used, ap);
157 else if (t == ASCII_TABLE_ARRAY_SERI)
158 ret = serialize_ascii_table_array(s, *buf, buf_siz, args_used, ap);
159 else if (t == PLY_SERI)
160 ret = serialize_ply(s, *buf, buf_siz, args_used, ap);
161 else if (t == OBJ_SERI)
162 ret = serialize_obj(s, *buf, buf_siz, args_used, ap);
164 cislog_error(
"serialize: Unsupported seri_type %d", t);
166 if (ret > (
int)buf_siz) {
168 *buf = (
char*)realloc(*buf, ret+1);
170 cislog_error(
"serialize: Failed to realloc buffer.");
173 ret = serialize(s, buf, ret+1, 1, args_used, ap2);
176 cislog_error(
"serialize: encoded message too large for the buffer. (buf_siz=%d, len=%d)",
196 int deserialize(
const seri_t s,
const char *buf,
const size_t buf_siz, va_list ap) {
197 seri_type t = s.type;
199 if (t == DIRECT_SERI)
200 ret = deserialize_direct(s, buf, buf_siz, ap);
201 else if (t == FORMAT_SERI)
202 ret = deserialize_format(s, buf, buf_siz, ap);
203 else if (t == ASCII_TABLE_SERI)
204 ret = deserialize_ascii_table(s, buf, buf_siz, ap);
205 else if (t == ASCII_TABLE_ARRAY_SERI)
206 ret = deserialize_ascii_table_array(s, buf, buf_siz, ap);
207 else if (t == PLY_SERI)
208 ret = deserialize_ply(s, buf, buf_siz, ap);
209 else if (t == OBJ_SERI)
210 ret = deserialize_obj(s, buf, buf_siz, ap);
212 cislog_error(
"deserialize: Unsupported seri_type %d", t);
Serializer structure.
Definition: SerializeBase.h:19
Structure containing information about an ASCII table.
Definition: AsciiTable.h:80