NewMadeleine

Documentation

nm_data.h File Reference

High-level data manipulation through iterators. More...

#include <assert.h>
#include <string.h>
#include <Padico/Puk.h>
Include dependency graph for nm_data.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  nm_data_generator_s
 state of a data generator More...
 
struct  nm_data_chunk_s
 chunk of data returned by generators More...
 
struct  nm_data_properties_s
 block of static properties for a given data descriptor More...
 
struct  nm_data_ops_s
 set of operations available on data type. More...
 
struct  nm_data_s
 a data descriptor, used to pack/unpack data from app layout to/from contiguous buffers More...
 
struct  nm_datav_s
 encapsulate a dynamic vector of nm_data More...
 
struct  nm_data_null_s
 data descriptor for 'null' data More...
 
struct  nm_data_contiguous_s
 data descriptor for contiguous data More...
 
struct  nm_data_iov_s
 data descriptor for iov data More...
 
struct  nm_data_datav_s
 data descriptor for datav in a nm_data More...
 
struct  nm_data_excerpt_s
 
struct  nm_data_slicer_s
 internal state of a data slicer. More...
 

Macros

#define _NM_DATA_CONTENT_SIZE   64
 maximum size of content descriptor for nm_data More...
 
#define _NM_DATA_GENERATOR_SIZE   64
 maximum content size for generators More...
 
#define NM_DATA_USE_COROUTINE_GENERATOR
 whether to use coroutine-based generators More...
 
#define NM_DATA_USE_COROUTINE_SLICER
 whether to use coroutine-based slicers More...
 
#define NM_DATA_CHUNK_NULL   ((struct nm_data_chunk_s){ .ptr = NULL, .len = 0 })
 
#define nm_data_generator_default_init   &nm_data_generator_coroutine_init
 
#define nm_data_generator_default_next   &nm_data_generator_coroutine_next
 
#define nm_data_generator_default_destroy   &nm_data_generator_coroutine_destroy
 
#define NM_DATA_TYPE(ENAME, CONTENT_TYPE, OPS)
 macro to generate typed functions to init/access data fields. More...
 
#define NM_DATAV_INIT_SIZE   4
 initial size of an nm_datav More...
 

Typedefs

typedef void(* nm_data_apply_t) (void *ptr, nm_len_t len, void *_context)
 function to apply to each data chunk upon traversal More...
 
typedef void(* nm_data_traversal_t) (const void *_content, const nm_data_apply_t apply, void *_context)
 funtion to traverse data with app layout, i.e. More...
 
typedef void(* nm_data_generator_init_t) (const struct nm_data_s *p_data, void *_generator)
 initializes a generator (i.e. More...
 
typedef struct nm_data_chunk_s(* nm_data_generator_next_t) (const struct nm_data_s *p_data, void *_generator)
 returns next data chunk for the given generator. More...
 
typedef void(* nm_data_generator_destroy_t) (const struct nm_data_s *p_data, void *_generator)
 destroys resources allocated by generator More...
 
typedef void(* nm_data_properties_compute_t) (struct nm_data_s *p_data)
 function to compute data properties More...
 

Functions

static int nm_data_chunk_isnull (const struct nm_data_chunk_s *p_chunk)
 
void nm_data_generator_coroutine_init (const struct nm_data_s *p_data, void *_generator)
 
struct nm_data_chunk_s nm_data_generator_coroutine_next (const struct nm_data_s *p_data, void *_generator)
 
void nm_data_generator_coroutine_destroy (const struct nm_data_s *p_data, void *_generator)
 
void nm_data_generator_generic_init (const struct nm_data_s *p_data, void *_generator)
 
struct nm_data_chunk_s nm_data_generator_generic_next (const struct nm_data_s *p_data, void *_generator)
 
void nm_data_default_properties_compute (struct nm_data_s *p_data)
 
static void nm_datav_init (struct nm_datav_s *p_datav)
 initialize a datav More...
 
static void nm_datav_destroy (struct nm_datav_s *p_datav)
 destroys a datav More...
 
static void nm_datav_add_chunk_data (struct nm_datav_s *p_datav, const struct nm_data_s *p_data)
 add a chunk of data to datav; given p_data content is copied. More...
 
static void nm_datav_add_chunk (struct nm_datav_s *p_datav, const void *ptr, nm_len_t len)
 add a chunk of contiguous data to a datav More...
 
static nm_len_t nm_datav_size (struct nm_datav_s *p_datav)
 get the size (number of bytes) of data contained in the datav More...
 
static void nm_datav_uncommit (struct nm_datav_s *p_datav)
 'uncommit' a datav: explicitely declare that nm_data pointing to this datav has been destroyed. More...
 
static void nm_data_traversal_apply (const struct nm_data_s *p_data, nm_data_apply_t apply, void *_context)
 helper function to apply iterator to data More...
 
static void nm_data_generator_init (const struct nm_data_s *p_data, struct nm_data_generator_s *p_generator)
 build a new generator for the given data type More...
 
static struct nm_data_chunk_s nm_data_generator_next (struct nm_data_generator_s *p_generator)
 get the next chunk of data More...
 
static void nm_data_generator_destroy (struct nm_data_generator_s *p_generator)
 destroy the generator after use More...
 
void nm_data_chunk_extractor_traversal (const struct nm_data_s *p_data, nm_len_t chunk_offset, nm_len_t chunk_len, nm_data_apply_t apply, void *_context)
 
void nm_data_aggregator_traversal (const struct nm_data_s *p_data, nm_data_apply_t apply, void *_context)
 
static const struct nm_data_properties_snm_data_properties_get (const struct nm_data_s *p_data)
 returns the properties block for the data More...
 
static nm_len_t nm_data_size (const struct nm_data_s *p_data)
 returns the amount of data contained in the descriptor More...
 
void * nm_data_baseptr_get (const struct nm_data_s *p_data)
 find base pointer for a data known to be contiguous More...
 
void * nm_data_chunk_baseptr_get (const struct nm_data_s *p_data, nm_len_t chunk_offset, nm_len_t chunk_len)
 find base pointer for a data chunk known to be contiguous More...
 
void nm_data_chunk_properties_compute (const struct nm_data_s *p_data, nm_len_t chunk_offset, nm_len_t chunk_len, struct nm_data_properties_s *p_props)
 compute properties of the given chunk inside the data More...
 
uint32_t nm_data_checksum (const struct nm_data_s *p_data)
 checksum data
More...
 
void nm_data_copy_from (const struct nm_data_s *p_data, nm_len_t offset, nm_len_t len, void *destbuf)
 copy chunk of data from user layout to contiguous buffer More...
 
void nm_data_copy_to (const struct nm_data_s *p_data, nm_len_t offset, nm_len_t len, const void *srcbuf)
 copy chunk of data from contiguous buffer to user layout More...
 
void nm_data_copy (struct nm_data_s *p_dest, struct nm_data_s *p_from)
 copy from nm_data to another nm_data More...
 
#define NM_DATA_SLICER_NULL   ((struct nm_data_slicer_s){ .kind = NM_DATA_SLICER_NONE })
 a slicer attached to no data More...
 
enum  nm_data_slicer_kind_t { NM_DATA_SLICER_NONE = 0 , NM_DATA_SLICER_GENERATOR , NM_DATA_SLICER_COROUTINE , NM_DATA_SLICER_UCONTEXT }
 various kinds of slicer implementations More...
 
enum  nm_data_slicer_op_e { NM_SLICER_OP_NONE = 0 , NM_SLICER_OP_FORWARD , NM_SLICER_OP_COPY_FROM , NM_SLICER_OP_COPY_TO }
 
typedef struct nm_data_slicer_s nm_data_slicer_t
 internal state of a data slicer. More...
 
typedef enum nm_data_slicer_op_e nm_data_slicer_op_t
 
static int nm_data_slicer_isnull (const nm_data_slicer_t *p_slicer)
 tests whether a slicer is null More...
 
void nm_data_slicer_coroutine_init (nm_data_slicer_t *p_slicer, const struct nm_data_s *p_data)
 
void nm_data_slicer_coroutine_op (nm_data_slicer_t *p_slicer, void *ptr, nm_len_t len, nm_data_slicer_op_t op)
 
void nm_data_slicer_coroutine_destroy (nm_data_slicer_t *p_slicer)
 
void nm_data_slicer_generator_init (nm_data_slicer_t *p_slicer, const struct nm_data_s *p_data)
 
void nm_data_slicer_generator_op (nm_data_slicer_t *p_slicer, void *ptr, nm_len_t slice_len, nm_data_slicer_op_t op)
 
void nm_data_slicer_generator_destroy (nm_data_slicer_t *p_slicer)
 
void nm_data_slicer_ucontext_init (nm_data_slicer_t *p_slicer, const struct nm_data_s *p_data)
 
void nm_data_slicer_ucontext_op (nm_data_slicer_t *p_slicer, void *ptr, nm_len_t len, nm_data_slicer_op_t op)
 
void nm_data_slicer_ucontext_destroy (nm_data_slicer_t *p_slicer)
 
void nm_data_slicer_init (nm_data_slicer_t *p_slicer, const struct nm_data_s *p_data)
 
void nm_data_slicer_op (nm_data_slicer_t *p_slicer, void *ptr, nm_len_t len, nm_data_slicer_op_t op)
 
void nm_data_slicer_copy_from (nm_data_slicer_t *p_slicer, void *dest_ptr, nm_len_t slice_len)
 
void nm_data_slicer_copy_to (nm_data_slicer_t *p_slicer, const void *src_ptr, nm_len_t slice_len)
 
void nm_data_slicer_forward (nm_data_slicer_t *p_slicer, nm_len_t offset)
 
void nm_data_slicer_destroy (nm_data_slicer_t *p_slicer)
 
const struct nm_data_ops_s nm_data_ops_null
 
const struct nm_data_ops_s nm_data_ops_contiguous
 
const struct nm_data_ops_s nm_data_ops_iov
 
const struct nm_data_ops_s nm_data_ops_datav
 
const struct nm_data_ops_s nm_data_ops_excerpt
 
static void nm_data_null_set (struct nm_data_s *p_data, struct nm_data_null_s value)
 
static struct nm_data_null_snm_data_null_content (const struct nm_data_s *p_data)
 
static void nm_data_null_build (struct nm_data_s *p_data)
 
static int nm_data_isnull (struct nm_data_s *p_data)
 
static void nm_data_contiguous_set (struct nm_data_s *p_data, struct nm_data_contiguous_s value)
 
static struct nm_data_contiguous_snm_data_contiguous_content (const struct nm_data_s *p_data)
 
static void nm_data_contiguous_build (struct nm_data_s *p_data, void *ptr, nm_len_t len)
 
static void nm_data_iov_set (struct nm_data_s *p_data, struct nm_data_iov_s value)
 
static struct nm_data_iov_snm_data_iov_content (const struct nm_data_s *p_data)
 
static void nm_data_iov_build (struct nm_data_s *p_data, const struct iovec *v, int n)
 
static void nm_data_datav_set (struct nm_data_s *p_data, struct nm_data_datav_s value)
 
static struct nm_data_datav_snm_data_datav_content (const struct nm_data_s *p_data)
 
static void nm_data_datav_build (struct nm_data_s *p_datav_data, struct nm_datav_s *p_datav)
 frontend to build a nm_data from a datav More...
 
static void nm_data_excerpt_set (struct nm_data_s *p_data, struct nm_data_excerpt_s value)
 
static struct nm_data_excerpt_snm_data_excerpt_content (const struct nm_data_s *p_data)
 
static void nm_data_excerpt_build (struct nm_data_s *p_data, struct nm_data_s *p_inner_data, nm_len_t chunk_offset, nm_len_t chunk_len)
 build a data descriptor as an excerpt of another data. More...
 

Detailed Description

High-level data manipulation through iterators.

Definition in file nm_data.h.

Macro Definition Documentation

◆ NM_DATA_SLICER_NULL

#define NM_DATA_SLICER_NULL   ((struct nm_data_slicer_s){ .kind = NM_DATA_SLICER_NONE })

a slicer attached to no data

Definition at line 519 of file nm_data.h.

Typedef Documentation

◆ nm_data_slicer_op_t

◆ nm_data_slicer_t

internal state of a data slicer.

Opaque structure for the user.

Enumeration Type Documentation

◆ nm_data_slicer_op_e

Enumerator
NM_SLICER_OP_NONE 

no operation selected

NM_SLICER_OP_FORWARD 

fast forward in slicer

NM_SLICER_OP_COPY_FROM 

copy from iterator to user buffer

NM_SLICER_OP_COPY_TO 

copy to iterator, from user buffer

Definition at line 510 of file nm_data.h.

Function Documentation

◆ nm_data_contiguous_build()

static void nm_data_contiguous_build ( struct nm_data_s p_data,
void *  ptr,
nm_len_t  len 
)
inlinestatic

◆ nm_data_contiguous_content()

static struct nm_data_contiguous_s * nm_data_contiguous_content ( const struct nm_data_s p_data)
inlinestatic

Definition at line 313 of file nm_data.h.

◆ nm_data_contiguous_set()

static void nm_data_contiguous_set ( struct nm_data_s p_data,
struct nm_data_contiguous_s  value 
)
inlinestatic

Definition at line 313 of file nm_data.h.

Referenced by nm_data_contiguous_build().

Here is the caller graph for this function:

◆ nm_data_datav_build()

static void nm_data_datav_build ( struct nm_data_s p_datav_data,
struct nm_datav_s p_datav 
)
inlinestatic

frontend to build a nm_data from a datav

Definition at line 351 of file nm_data.h.

References nm_datav_s::commited, nm_data_datav_set(), and nm_data_datav_s::p_datav.

Referenced by nm_rpc_recv_header_data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nm_data_datav_content()

static struct nm_data_datav_s * nm_data_datav_content ( const struct nm_data_s p_data)
inlinestatic

Definition at line 348 of file nm_data.h.

◆ nm_data_datav_set()

static void nm_data_datav_set ( struct nm_data_s p_data,
struct nm_data_datav_s  value 
)
inlinestatic

Definition at line 348 of file nm_data.h.

Referenced by nm_data_datav_build().

Here is the caller graph for this function:

◆ nm_data_excerpt_build()

static void nm_data_excerpt_build ( struct nm_data_s p_data,
struct nm_data_s p_inner_data,
nm_len_t  chunk_offset,
nm_len_t  chunk_len 
)
inlinestatic

build a data descriptor as an excerpt of another data.

Note
p_inner_data is not copied; it must stay allocated as long as the excerpt

Definition at line 370 of file nm_data.h.

References nm_data_excerpt_s::chunk_len, chunk_len, nm_data_excerpt_s::chunk_offset, chunk_offset, nm_data_excerpt_set(), and nm_data_excerpt_s::p_data.

Here is the call graph for this function:

◆ nm_data_excerpt_content()

static struct nm_data_excerpt_s * nm_data_excerpt_content ( const struct nm_data_s p_data)
inlinestatic

Definition at line 366 of file nm_data.h.

◆ nm_data_excerpt_set()

static void nm_data_excerpt_set ( struct nm_data_s p_data,
struct nm_data_excerpt_s  value 
)
inlinestatic

Definition at line 366 of file nm_data.h.

Referenced by nm_data_excerpt_build().

Here is the caller graph for this function:

◆ nm_data_iov_build()

static void nm_data_iov_build ( struct nm_data_s p_data,
const struct iovec *  v,
int  n 
)
inlinestatic

Definition at line 333 of file nm_data.h.

References nm_data_iov_s::n, nm_data_iov_set(), and nm_data_iov_s::v.

Referenced by nm_sr_recv_unpack_iov(), and nm_sr_send_pack_iov().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nm_data_iov_content()

static struct nm_data_iov_s * nm_data_iov_content ( const struct nm_data_s p_data)
inlinestatic

Definition at line 331 of file nm_data.h.

◆ nm_data_iov_set()

static void nm_data_iov_set ( struct nm_data_s p_data,
struct nm_data_iov_s  value 
)
inlinestatic

Definition at line 331 of file nm_data.h.

Referenced by nm_data_iov_build().

Here is the caller graph for this function:

◆ nm_data_isnull()

static int nm_data_isnull ( struct nm_data_s p_data)
inlinestatic

Definition at line 300 of file nm_data.h.

References nm_data_ops_null, nm_data_s::ops, and nm_data_ops_s::p_traversal.

◆ nm_data_null_build()

static void nm_data_null_build ( struct nm_data_s p_data)
inlinestatic

Definition at line 295 of file nm_data.h.

References nm_data_null_set().

Here is the call graph for this function:

◆ nm_data_null_content()

static struct nm_data_null_s * nm_data_null_content ( const struct nm_data_s p_data)
inlinestatic

Definition at line 294 of file nm_data.h.

◆ nm_data_null_set()

static void nm_data_null_set ( struct nm_data_s p_data,
struct nm_data_null_s  value 
)
inlinestatic

Definition at line 294 of file nm_data.h.

Referenced by nm_data_null_build().

Here is the caller graph for this function:

◆ nm_data_slicer_copy_from()

void nm_data_slicer_copy_from ( nm_data_slicer_t p_slicer,
void *  dest_ptr,
nm_len_t  slice_len 
)

◆ nm_data_slicer_copy_to()

void nm_data_slicer_copy_to ( nm_data_slicer_t p_slicer,
const void *  src_ptr,
nm_len_t  slice_len 
)

◆ nm_data_slicer_coroutine_destroy()

void nm_data_slicer_coroutine_destroy ( nm_data_slicer_t p_slicer)

◆ nm_data_slicer_coroutine_init()

void nm_data_slicer_coroutine_init ( nm_data_slicer_t p_slicer,
const struct nm_data_s p_data 
)

◆ nm_data_slicer_coroutine_op()

void nm_data_slicer_coroutine_op ( nm_data_slicer_t p_slicer,
void *  ptr,
nm_len_t  len,
nm_data_slicer_op_t  op 
)

◆ nm_data_slicer_destroy()

void nm_data_slicer_destroy ( nm_data_slicer_t p_slicer)

◆ nm_data_slicer_forward()

void nm_data_slicer_forward ( nm_data_slicer_t p_slicer,
nm_len_t  offset 
)

◆ nm_data_slicer_generator_destroy()

void nm_data_slicer_generator_destroy ( nm_data_slicer_t p_slicer)

◆ nm_data_slicer_generator_init()

void nm_data_slicer_generator_init ( nm_data_slicer_t p_slicer,
const struct nm_data_s p_data 
)

◆ nm_data_slicer_generator_op()

void nm_data_slicer_generator_op ( nm_data_slicer_t p_slicer,
void *  ptr,
nm_len_t  slice_len,
nm_data_slicer_op_t  op 
)

◆ nm_data_slicer_init()

void nm_data_slicer_init ( nm_data_slicer_t p_slicer,
const struct nm_data_s p_data 
)

◆ nm_data_slicer_isnull()

static int nm_data_slicer_isnull ( const nm_data_slicer_t p_slicer)
inlinestatic

tests whether a slicer is null

Definition at line 522 of file nm_data.h.

References nm_data_slicer_s::kind, and NM_DATA_SLICER_NONE.

◆ nm_data_slicer_op()

void nm_data_slicer_op ( nm_data_slicer_t p_slicer,
void *  ptr,
nm_len_t  len,
nm_data_slicer_op_t  op 
)

◆ nm_data_slicer_ucontext_destroy()

void nm_data_slicer_ucontext_destroy ( nm_data_slicer_t p_slicer)

◆ nm_data_slicer_ucontext_init()

void nm_data_slicer_ucontext_init ( nm_data_slicer_t p_slicer,
const struct nm_data_s p_data 
)

◆ nm_data_slicer_ucontext_op()

void nm_data_slicer_ucontext_op ( nm_data_slicer_t p_slicer,
void *  ptr,
nm_len_t  len,
nm_data_slicer_op_t  op 
)

Variable Documentation

◆ nm_data_ops_contiguous

const struct nm_data_ops_s nm_data_ops_contiguous
extern

◆ nm_data_ops_datav

const struct nm_data_ops_s nm_data_ops_datav
extern

◆ nm_data_ops_excerpt

const struct nm_data_ops_s nm_data_ops_excerpt
extern

◆ nm_data_ops_iov

const struct nm_data_ops_s nm_data_ops_iov
extern

◆ nm_data_ops_null

const struct nm_data_ops_s nm_data_ops_null
extern

Referenced by nm_data_isnull().