79 u64 *x = va_arg (*va,
u64 *);
83 *x = ((
u64) hi << 32) | (
u64) lo;
89 u32 *x = va_arg (*va,
u32 *);
96 u16 *x = va_arg (*va,
u16 *);
105 u8 *x = va_arg (*va,
u8 *);
114 f64 x = va_arg (*va,
f64);
127 f32 x = va_arg (*va,
f64);
140 f64 *x = va_arg (*va,
f64 *);
153 f32 *x = va_arg (*va,
f32 *);
166 u32 len = s ? strlen (s) : 0;
190 if (len > 0 && len != 0xFFFFFFFF)
206 u8 *s = va_arg (*va,
u8 *);
207 u32 n = va_arg (*va,
u32);
215 u8 *s = va_arg (*va,
u8 *);
216 u32 n = va_arg (*va,
u32);
222 void serialize_vec_##n_bits (serialize_main_t * m, va_list * va) \ 224 u##n_bits * s = va_arg (*va, u##n_bits *); \ 225 u32 n = va_arg (*va, u32); \ 226 u##n_bits * p = serialize_get (m, n * sizeof (s[0])); \ 230 p[0] = clib_host_to_net_u##n_bits (s[0]); \ 231 p[1] = clib_host_to_net_u##n_bits (s[1]); \ 232 p[2] = clib_host_to_net_u##n_bits (s[2]); \ 233 p[3] = clib_host_to_net_u##n_bits (s[3]); \ 241 p[0] = clib_host_to_net_u##n_bits (s[0]); \ 248 void unserialize_vec_##n_bits (serialize_main_t * m, va_list * va) \ 250 u##n_bits * s = va_arg (*va, u##n_bits *); \ 251 u32 n = va_arg (*va, u32); \ 252 u##n_bits * p = unserialize_get (m, n * sizeof (s[0])); \ 256 s[0] = clib_net_to_host_mem_u##n_bits (&p[0]); \ 257 s[1] = clib_net_to_host_mem_u##n_bits (&p[1]); \ 258 s[2] = clib_net_to_host_mem_u##n_bits (&p[2]); \ 259 s[3] = clib_net_to_host_mem_u##n_bits (&p[3]); \ 267 s[0] = clib_net_to_host_mem_u##n_bits (&p[0]); \ 280 #define SERIALIZE_VECTOR_CHUNK_SIZE 64 285 void *vec = va_arg (*va,
void *);
286 u32 elt_bytes = va_arg (*va,
u32);
316 p = v = _vec_resize (0, l, (
uword) l * elt_bytes, header_bytes,
332 void **vec = va_arg (*va,
void **);
333 u32 elt_bytes = va_arg (*va,
u32);
335 u32 align = va_arg (*va,
u32);
347 void **vec = va_arg (*va,
void **);
348 u32 elt_bytes = va_arg (*va,
u32);
364 n_u32s = l *
sizeof (b[0]) /
sizeof (
u32);
368 for (i = 0; i < l; i++)
386 i = (n_u32s *
sizeof (
u32) +
sizeof (b[0]) - 1) /
sizeof (b[0]);
388 for (i = 0; i < n_u32s; i++)
397 b[i / 2] |= (
u64) data << (
u64) 0;
399 b[i / 2] |= (
u64) data << (
u64) 32;
413 void *pool = va_arg (*va,
void *);
414 u32 elt_bytes = va_arg (*va,
u32);
430 serialize (m, f, pool + lo * elt_bytes, hi - lo));
447 v = _vec_resize (0, l, (
uword) l * elt_bytes,
sizeof (p[0]), align);
466 void **result = va_arg (*va,
void **);
467 u32 elt_bytes = va_arg (*va,
u32);
475 void **result = va_arg (*va,
void **);
476 u32 elt_bytes = va_arg (*va,
u32);
477 u32 align = va_arg (*va,
u32);
487 for (i = 0; i < n; i++)
500 for (i = 0; i < n; i++)
511 void *heap = va_arg (*va,
void *);
523 #define foreach_serialize_heap_header_integer \ 524 _ (head) _ (tail) _ (used_count) _ (max_len) _ (flags) _ (elt_bytes) 526 #define _(f) serialize_integer (m, h->f, sizeof (h->f)); 561 void **result = va_arg (*va,
void **);
574 memset (&h, 0,
sizeof (h));
575 #define _(f) unserialize_integer (m, &h.f, sizeof (h.f)); 600 heap = *result = _heap_new (vl, h.
elt_bytes);
639 if (l != magic_bytes)
645 if (memcmp (magic, d, magic_bytes))
699 uword cur_bi, n_left_b, n_left_o;
709 if (n_left_o > 0 && n_left_b > 0)
733 while (n_left_o > 0);
735 if (n_left_o > 0 || n_left_b < n_bytes_to_write)
744 return s->
buffer + cur_bi;
753 uword cur_bi, cur_oi, n_left_b, n_left_o, n_left_to_read;
764 if (n_left_o >= n_bytes_to_read)
777 n_left_to_read = n_bytes_to_read;
778 while (n_left_to_read > 0)
784 if (n_left_o + n_left_b < n_bytes_to_read)
790 n_left_o += n_left_b;
791 n_left_to_read -= n_left_b;
809 && n_left_to_read == n_bytes_to_read && n_left_b >= n_left_to_read)
812 return s->
buffer + cur_bi;
820 n_left_o += n_left_to_read;
826 n =
clib_min (n_left_to_read, n_left_b);
884 memset (m, 0,
sizeof (m[0]));
910 memset (m, 0,
sizeof (m[0]));
928 memset (m, 0,
sizeof (m[0]));
938 uword n_left = n_data;
943 p[0] = d[0 * data_stride];
944 p[1] = d[1 * data_stride];
945 p[2] = d[2 * data_stride];
946 p[3] = d[3 * data_stride];
948 d += 4 * data_stride;
958 d += 1 * data_stride;
970 uword n_left = n_data;
976 clib_host_to_net_mem_u16 (d + 0 * data_stride);
978 clib_host_to_net_mem_u16 (d + 1 * data_stride);
980 clib_host_to_net_mem_u16 (d + 2 * data_stride);
982 clib_host_to_net_mem_u16 (d + 3 * data_stride);
984 d += 4 * data_stride;
993 clib_host_to_net_mem_u16 (d + 0 * data_stride);
995 d += 1 * data_stride;
1007 uword n_left = n_data;
1013 clib_host_to_net_mem_u32 (d + 0 * data_stride);
1015 clib_host_to_net_mem_u32 (d + 1 * data_stride);
1017 clib_host_to_net_mem_u32 (d + 2 * data_stride);
1019 clib_host_to_net_mem_u32 (d + 3 * data_stride);
1021 d += 4 * data_stride;
1030 clib_host_to_net_mem_u32 (d + 0 * data_stride);
1032 d += 1 * data_stride;
1044 uword n_left = n_data;
1049 d[0 * data_stride] = p[0];
1050 d[1 * data_stride] = p[1];
1051 d[2 * data_stride] = p[2];
1052 d[3 * data_stride] = p[3];
1054 d += 4 * data_stride;
1064 d += 1 * data_stride;
1076 uword n_left = n_data;
1082 clib_net_to_host_mem_u16 (p + 0);
1084 clib_net_to_host_mem_u16 (p + 1);
1086 clib_net_to_host_mem_u16 (p + 2);
1088 clib_net_to_host_mem_u16 (p + 3);
1090 d += 4 * data_stride;
1099 clib_net_to_host_mem_u16 (p + 0);
1101 d += 1 * data_stride;
1113 uword n_left = n_data;
1119 clib_net_to_host_mem_u32 (p + 0);
1121 clib_net_to_host_mem_u32 (p + 1);
1123 clib_net_to_host_mem_u32 (p + 2);
1125 clib_net_to_host_mem_u32 (p + 3);
1127 d += 4 * data_stride;
1136 clib_net_to_host_mem_u32 (p + 0);
1138 d += 1 * data_stride;
1164 _vec_len (s->
buffer) = 0;
1194 memset (m, 0,
sizeof (m[0]));
1225 mode = is_read ? O_RDONLY : O_RDWR | O_CREAT | O_TRUNC;
1226 fd = open (file, mode, 0666);
static void serialize_vector_write(serialize_main_header_t *m, serialize_stream_t *s)
void serialize_f32(serialize_main_t *m, va_list *va)
void unserialize_check_magic(serialize_main_t *m, void *magic, u32 magic_bytes)
u32 current_overflow_index
static u64 unserialize_likely_small_unsigned_integer(serialize_main_t *m)
adds_epu subs_epu i16x8 y
#define serialize_error_return(m, args...)
clib_error_t * serialize_open_clib_file(serialize_main_t *m, char *file)
void serialize_bitmap(serialize_main_t *m, uword *b)
void serialize_multiple_4(serialize_main_t *m, void *data, uword data_stride, uword n_data)
#define vec_serialize(m, v, f)
Fixed length block allocator.
serialize_main_header_t header
static void serialize_error(serialize_main_header_t *m, clib_error_t *error)
#define vec_unserialize(m, v, f)
static void serialize_stream_set_end_of_stream(serialize_stream_t *s)
void unserialize_32(serialize_main_t *m, va_list *va)
void unserialize_multiple_2(serialize_main_t *m, void *data, uword data_stride, uword n_data)
void serialize_f64(serialize_main_t *m, va_list *va)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
void serialize_open_clib_file_descriptor(serialize_main_t *m, int fd)
uword clib_setjmp(clib_longjmp_t *save, uword return_value_not_taken)
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
#define SERIALIZE_VECTOR_CHUNK_SIZE
#define foreach_serialize_heap_header_integer
void * unserialize_vector_ha(serialize_main_t *m, u32 elt_bytes, u32 header_bytes, u32 align, u32 max_length, serialize_function_t *f)
void unserialize_open_data(serialize_main_t *m, u8 *data, uword n_data_bytes)
#define vec_new(T, N)
Create new vector of given type and length (unspecified alignment, no header).
void unserialize_heap(serialize_main_t *m, va_list *va)
static uword serialize_stream_is_end_of_stream(serialize_stream_t *s)
static void * serialize_get(serialize_main_t *m, uword n_bytes)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
void unserialize_aligned_vector(serialize_main_t *m, va_list *va)
static uword heap_is_free(heap_elt_t *e)
#define vec_resize(V, N)
Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V...
#define clib_error_create(args...)
static void * serialize_read_not_inline(serialize_main_header_t *m, serialize_stream_t *s, uword n_bytes_to_read, uword flags)
static heap_elt_t * heap_next(heap_elt_t *e)
void serialize_16(serialize_main_t *m, va_list *va)
#define SERIALIZE_FLAG_IS_READ
void unserialize_vec_8(serialize_main_t *m, va_list *va)
serialize_function_t serialize_vec_32
static pool_header_t * pool_header(void *v)
Get pool header from user pool pointer.
void serialize_open_data(serialize_main_t *m, u8 *data, uword n_data_bytes)
static void serialize_likely_small_unsigned_integer(serialize_main_t *m, u64 x)
void serialize_pool(serialize_main_t *m, va_list *va)
void unserialize_multiple_4(serialize_main_t *m, void *data, uword data_stride, uword n_data)
#define clib_error_return_unix(e, args...)
void unserialize_8(serialize_main_t *m, va_list *va)
void serialize_8(serialize_main_t *m, va_list *va)
static void serialize_open_clib_file_descriptor_helper(serialize_main_t *m, int fd, uword is_read)
static void * unserialize_get(serialize_main_t *m, uword n_bytes)
static void serialize_read_write_close(serialize_main_header_t *m, serialize_stream_t *s, uword flags)
void unserialize_cstring(serialize_main_t *m, char **s)
void * serialize_read_write_not_inline(serialize_main_header_t *m, serialize_stream_t *s, uword n_bytes, uword flags)
#define uword_to_pointer(u, type)
serialize_stream_t stream
static void clib_file_read(serialize_main_header_t *m, serialize_stream_t *s)
clib_error_t * serialize(serialize_main_t *m,...)
void serialize_open_vector(serialize_main_t *m, u8 *vector)
#define vec_free(V)
Free vector's memory (no header).
clib_error_t * unserialize_open_clib_file(serialize_main_t *m, char *file)
#define clib_memcpy(a, b, c)
static uword heap_offset(heap_elt_t *e)
serialize_data_function_t * data_function
static void unserialize_integer(serialize_main_t *m, void *x, u32 n_bytes)
static void serialize_integer(serialize_main_t *m, u64 x, u32 n_bytes)
void unserialize_close(serialize_main_t *m)
static void serialize_vec_heap_elt(serialize_main_t *m, va_list *va)
uword data_function_opaque
void serialize_multiple_2(serialize_main_t *m, void *data, uword data_stride, uword n_data)
void serialize_magic(serialize_main_t *m, void *magic, u32 magic_bytes)
void unserialize_16(serialize_main_t *m, va_list *va)
void serialize_vec_8(serialize_main_t *m, va_list *va)
void unserialize_aligned_pool(serialize_main_t *m, va_list *va)
void unserialize_multiple_1(serialize_main_t *m, void *data, uword data_stride, uword n_data)
#define vec_delete(V, N, M)
Delete N elements starting at element M.
static word unix_error_is_fatal(word error)
void serialize_close(serialize_main_t *m)
#define pool_foreach_region(LO, HI, POOL, BODY)
Optimized iteration through pool.
clib_error_t * unserialize(serialize_main_t *m,...)
static uword heap_elt_size(void *v, heap_elt_t *e)
static heap_header_t * heap_header(void *v)
void serialize_cstring(serialize_main_t *m, char *s)
static void unserialize_vec_heap_elt(serialize_main_t *m, va_list *va)
void serialize_32(serialize_main_t *m, va_list *va)
template key/value backing page structure
static void * serialize_write_not_inline(serialize_main_header_t *m, serialize_stream_t *s, uword n_bytes_to_write, uword flags)
void unserialize_f64(serialize_main_t *m, va_list *va)
void unserialize_vector(serialize_main_t *m, va_list *va)
void unserialize_f32(serialize_main_t *m, va_list *va)
uword * unserialize_bitmap(serialize_main_t *m)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void( serialize_function_t)(serialize_main_t *m, va_list *va)
void serialize_heap(serialize_main_t *m, va_list *va)
void serialize_vector(serialize_main_t *m, va_list *va)
clib_error_t * va_serialize(serialize_main_t *sm, va_list *va)
void unserialize_pool(serialize_main_t *m, va_list *va)
static void * unserialize_pool_helper(serialize_main_t *m, u32 elt_bytes, u32 align, serialize_function_t *f)
static void clib_file_write(serialize_main_header_t *m, serialize_stream_t *s)
#define SERIALIZE_FLAG_IS_WRITE
static clib_error_t * serialize_open_clib_file_helper(serialize_main_t *m, char *file, uword is_read)
#define clib_mem_unaligned(pointer, type)
#define vec_foreach(var, vec)
Vector iterator.
void unserialize_open_clib_file_descriptor(serialize_main_t *m, int fd)
void * serialize_close_vector(serialize_main_t *m)
void unserialize_64(serialize_main_t *m, va_list *va)
void serialize_64(serialize_main_t *m, va_list *va)
void serialize_multiple_1(serialize_main_t *m, void *data, uword data_stride, uword n_data)
clib_longjmp_t error_longjmp
serialize_function_t unserialize_vec_32