38 #ifndef included_clib_serialize_h 39 #define included_clib_serialize_h 48 struct serialize_stream_t;
51 struct serialize_stream_t * s);
53 typedef struct serialize_stream_t
72 #define SERIALIZE_END_OF_STREAM (1 << 0) 112 #define serialize_error_return(m,args...) \ 113 serialize_error (&(m)->header, clib_error_return (0, args)) 116 serialize_stream_t * s,
119 #define SERIALIZE_FLAG_IS_READ (1 << 0) 120 #define SERIALIZE_FLAG_IS_WRITE (1 << 1) 124 serialize_stream_t * s,
133 if (l == 0 && j <= s->n_buffer_bytes)
190 else if (n_bytes == 2)
192 else if (n_bytes == 4)
194 else if (n_bytes == 8)
206 else if (n_bytes == 2)
207 *(
u16 *) x = clib_net_to_host_unaligned_mem_u16 ((
u16 *) p);
208 else if (n_bytes == 4)
209 *(
u32 *) x = clib_net_to_host_unaligned_mem_u32 ((
u32 *) p);
210 else if (n_bytes == 8)
211 *(
u64 *) x = clib_net_to_host_unaligned_mem_u64 ((
u64 *) p);
267 r += (y / 4) + (p[0] << 6);
276 + (p[0] << (5 + 8 * 0))
277 + (p[1] << (5 + 8 * 1)) + (p[2] << (5 + 8 * 2)));
283 r = clib_little_to_host_u64 (r);
291 u64 u = s < 0 ? -(2 * s + 1) : 2 * s;
300 return (u & 1) ? -s : s;
328 if (n_data_bytes == 1)
330 else if (n_data_bytes == 2)
332 else if (n_data_bytes == 4)
343 if (n_data_bytes == 1)
345 else if (n_data_bytes == 2)
347 else if (n_data_bytes == 4)
371 #define vec_serialize(m,v,f) \ 372 serialize ((m), serialize_vector, (v), sizeof ((v)[0]), (f)) 374 #define vec_unserialize(m,v,f) \ 375 unserialize ((m), unserialize_vector, (v), sizeof ((*(v))[0]), (f)) 377 #define vec_unserialize_aligned(m,v,f) \ 378 unserialize ((m), unserialize_aligned_vector, (v), sizeof ((*(v))[0]), (f)) 384 #define pool_serialize(m,v,f) \ 385 serialize ((m), serialize_pool, (v), sizeof ((v)[0]), (f)) 387 #define pool_unserialize(m,v,f) \ 388 unserialize ((m), unserialize_pool, (v), sizeof ((*(v))[0]), (f)) 390 #define pool_unserialize_aligned(m,v,a,f) \ 391 unserialize ((m), unserialize_aligned_pool, (v), sizeof ((*(v))[0]), (a), (f)) clib_error_t * unserialize_open_clib_file(serialize_main_t *m, char *file)
void unserialize_multiple_4(serialize_main_t *m, void *data, uword data_stride, uword n_data)
u32 current_overflow_index
serialize_function_t unserialize_16
static u64 unserialize_likely_small_unsigned_integer(serialize_main_t *m)
adds_epu subs_epu i16x8 y
void serialize_magic(serialize_main_t *m, void *magic, u32 magic_bytes)
void unserialize_open_data(serialize_main_t *m, u8 *data, uword n_data_bytes)
static uword serialize_is_end_of_stream(serialize_main_t *m)
void unserialize_multiple_1(serialize_main_t *m, void *data, uword data_stride, uword n_data)
void serialize_close(serialize_main_t *m)
serialize_main_header_t header
static void serialize_error(serialize_main_header_t *m, clib_error_t *error)
serialize_function_t serialize_32
serialize_stream_t * streams
clib_error_t * unserialize(serialize_main_t *m,...)
serialize_function_t unserialize_64
serialize_function_t unserialize_vec_16
static void serialize_stream_set_end_of_stream(serialize_stream_t *s)
serialize_function_t serialize_pool
void clib_longjmp(clib_longjmp_t *save, uword return_value)
void unserialize_close(serialize_main_t *m)
static void * serialize_stream_read_write(serialize_main_header_t *header, serialize_stream_t *s, uword n_bytes, uword flags)
struct serialize_main_header_t serialize_main_header_t
serialize_function_t serialize_64
serialize_function_t unserialize_aligned_vector
serialize_function_t unserialize_f32
static void serialize_set_end_of_stream(serialize_main_t *m)
serialize_function_t serialize_vector
void * serialize_close_vector(serialize_main_t *m)
static i64 unserialize_likely_small_signed_integer(serialize_main_t *m)
static uword serialize_stream_is_end_of_stream(serialize_stream_t *s)
static void * serialize_get(serialize_main_t *m, uword n_bytes)
clib_error_t * serialize(serialize_main_t *m,...)
serialize_function_t unserialize_aligned_pool
void serialize_open_vector(serialize_main_t *m, u8 *vector)
static void serialize_multiple(serialize_main_t *m, void *data, uword n_data_bytes, uword data_stride, uword n_data)
void serialize_multiple_1(serialize_main_t *m, void *data, uword data_stride, uword n_data)
static uword pointer_to_uword(const void *p)
#define SERIALIZE_FLAG_IS_READ
void unserialize_multiple_2(serialize_main_t *m, void *data, uword data_stride, uword n_data)
serialize_function_t unserialize_vec_64
serialize_function_t serialize_vec_32
serialize_function_t serialize_vec_64
serialize_function_t unserialize_32
static void serialize_likely_small_unsigned_integer(serialize_main_t *m, u64 x)
void serialize_multiple_2(serialize_main_t *m, void *data, uword data_stride, uword n_data)
void unserialize_check_magic(serialize_main_t *m, void *magic, u32 magic_bytes)
void unserialize_open_clib_file_descriptor(serialize_main_t *m, int fd)
static void * unserialize_get(serialize_main_t *m, uword n_bytes)
void serialize_bitmap(serialize_main_t *m, uword *b)
u32 opaque[64-4 *sizeof(u32)-1 *sizeof(uword)-2 *sizeof(void *)]
serialize_function_t unserialize_vector
serialize_function_t unserialize_f64
serialize_function_t serialize_16
serialize_function_t unserialize_8
#define SERIALIZE_END_OF_STREAM
serialize_stream_t stream
uword * unserialize_bitmap(serialize_main_t *m)
static void unserialize_multiple(serialize_main_t *m, void *data, uword n_data_bytes, uword data_stride, uword n_data)
serialize_data_function_t * data_function
void serialize_open_clib_file_descriptor(serialize_main_t *m, int fd)
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)
static void serialize_likely_small_signed_integer(serialize_main_t *m, i64 s)
serialize_function_t serialize_heap
uword data_function_opaque
serialize_function_t serialize_vec_16
serialize_function_t unserialize_vec_8
void serialize_cstring(serialize_main_t *m, char *string)
void serialize_multiple_4(serialize_main_t *m, void *data, uword data_stride, uword n_data)
clib_error_t * va_serialize(serialize_main_t *m, va_list *va)
void unserialize_open_vector(serialize_main_t *m, u8 *vector)
void unserialize_cstring(serialize_main_t *m, char **string)
serialize_function_t serialize_f32
serialize_function_t serialize_vec_8
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void( serialize_function_t)(serialize_main_t *m, va_list *va)
serialize_main_header_t header
void serialize_open_data(serialize_main_t *m, u8 *data, uword n_data_bytes)
clib_error_t * serialize_open_clib_file(serialize_main_t *m, char *file)
#define SERIALIZE_FLAG_IS_WRITE
#define clib_mem_unaligned(pointer, type)
serialize_function_t unserialize_heap
serialize_function_t serialize_8
void( serialize_data_function_t)(struct serialize_main_header_t *h, struct serialize_stream_t *s)
struct serialize_stream_t serialize_stream_t
void * serialize_read_write_not_inline(serialize_main_header_t *m, serialize_stream_t *s, uword n_bytes, uword flags)
serialize_function_t unserialize_pool
clib_longjmp_t error_longjmp
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
serialize_function_t serialize_f64
serialize_function_t unserialize_vec_32