cis_config
SerializeBase.h
1 #include <../tools.h>
2 
3 #ifndef CISSERIALIZEBASE_H_
4 #define CISSERIALIZEBASE_H_
5 
6 
8 enum seri_enum { DIRECT_SERI, FORMAT_SERI, ARRAY_SERI,
9  ASCII_TABLE_SERI, ASCII_TABLE_ARRAY_SERI };
10 typedef enum seri_enum seri_type;
11 
15 typedef struct seri_t {
16  seri_type type;
17  void *info;
18  size_t size_info;
19 } seri_t;
20 
21 
32 static inline
33 int serialize_direct(const seri_t s, char *buf, const size_t buf_siz,
34  int *args_used, va_list ap) {
35  args_used[0] = 0;
36  if (s.type != DIRECT_SERI)
37  return -1;
38  char *msg = va_arg(ap, char*);
39  args_used[0] = 1;
40  int ret = (int)strlen(msg);
41  if ((ret + 1) < (int)buf_siz)
42  strcpy(buf, msg);
43  return ret;
44 };
45 
54 static inline
55 int deserialize_direct(const seri_t s, const char *buf, const size_t buf_siz,
56  va_list ap) {
57  if (s.type != DIRECT_SERI)
58  return -1;
59  char **msg = va_arg(ap, char**);
60  *msg = (char*)realloc(*msg, buf_siz + 1);
61  memcpy(*msg, buf, buf_siz);
62  (*msg)[buf_siz] = '\0';
63  return 1;
64 };
65 
66 
67 #endif /*CISSERIALIZEBASE_H_*/
Serializer structure.
Definition: SerializeBase.h:15
void * info
Pointer to any extra info serializer requires.
Definition: SerializeBase.h:17
size_t size_info
Size of allocate space for info.
Definition: SerializeBase.h:18
seri_type type
Serializer type.
Definition: SerializeBase.h:16