cis_config
SerializeBase.h
1 #ifndef CISSERIALIZEBASE_H_
2 #define CISSERIALIZEBASE_H_
3 
4 #include <../tools.h>
5 
6 #ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
7 extern "C" {
8 #endif
9 
11 enum seri_enum { DIRECT_SERI, FORMAT_SERI, ARRAY_SERI,
12  ASCII_TABLE_SERI, ASCII_TABLE_ARRAY_SERI,
13  PLY_SERI, OBJ_SERI};
14 typedef enum seri_enum seri_type;
15 
19 typedef struct seri_t {
20  seri_type type;
21  void *info;
22  size_t size_info;
23 } seri_t;
24 
25 
36 static inline
37 int serialize_direct(const seri_t s, char *buf, const size_t buf_siz,
38  int *args_used, va_list ap) {
39  args_used[0] = 0;
40  if (s.type != DIRECT_SERI)
41  return -1;
42  char *msg = va_arg(ap, char*);
43  args_used[0] = 1;
44  int ret = (int)strlen(msg);
45  if ((ret + 1) < (int)buf_siz)
46  strcpy(buf, msg);
47  return ret;
48 };
49 
58 static inline
59 int deserialize_direct(const seri_t s, const char *buf, const size_t buf_siz,
60  va_list ap) {
61  if (s.type != DIRECT_SERI)
62  return -1;
63  char **msg = va_arg(ap, char**);
64  *msg = (char*)realloc(*msg, buf_siz + 1);
65  memcpy(*msg, buf, buf_siz);
66  (*msg)[buf_siz] = '\0';
67  return 1;
68 };
69 
70 #ifdef __cplusplus /* If this is a C++ compiler, end C linkage */
71 }
72 #endif
73 
74 #endif /*CISSERIALIZEBASE_H_*/
Serializer structure.
Definition: SerializeBase.h:19
void * info
Pointer to any extra info serializer requires.
Definition: SerializeBase.h:21
size_t size_info
Size of allocate space for info.
Definition: SerializeBase.h:22
seri_type type
Serializer type.
Definition: SerializeBase.h:20