Motr  M0
xcode.h File Reference
#include "lib/vec.h"
#include "lib/types.h"
#include "lib/assert.h"
#include "xcode/xcode_attr.h"
#include "xcode/enum.h"
Include dependency graph for xcode.h:

Go to the source code of this file.

Data Structures

struct  m0_xcode_field
 
struct  m0_xcode_type
 
struct  m0_xcode_obj
 
struct  m0_xcode_type_ops
 
struct  m0_xcode_cursor
 
struct  m0_xcode_cursor::m0_xcode_cursor_frame
 
struct  m0_xcode_ctx
 

Macros

#define __MOTR_XCODE_XCODE_H__
 
#define M0_XCODE_VAL(obj, fieldno, elno, __type)   ((__type *)m0_xcode_addr(obj, fieldno, elno))
 
#define M0_XCODE_OBJ(type, ptr)
 

Typedefs

typedef char m0_void_t[0]
 

Enumerations

enum  m0_xcode_aggr {
  M0_XA_RECORD, M0_XA_UNION, M0_XA_SEQUENCE, M0_XA_ARRAY,
  M0_XA_TYPEDEF, M0_XA_OPAQUE, M0_XA_ATOM, M0_XA_NR
}
 
enum  m0_xode_atom_type {
  M0_XAT_VOID, M0_XAT_U8, M0_XAT_U32, M0_XAT_U64,
  M0_XAT_NR
}
 
enum  { M0_XCODE_DECOR_READ, M0_XCODE_DECOR_MAX = 10 }
 
enum  m0_xcode_type_flags { M0_XCODE_TYPE_FLAG_DOM_BE = 1 << 0, M0_XCODE_TYPE_FLAG_DOM_RPC = 1 << 1, M0_XCODE_TYPE_FLAG_DOM_CONF = 1 << 2 }
 
enum  { M0_XCODE_DEPTH_MAX = 10 }
 

Functions

 M0_BASSERT (sizeof(enum m0_xcode_type_flags)<=sizeof(uint32_t))
 
M0_INTERNAL int m0_xcode_read (struct m0_xcode_obj *obj, const char *str)
 
M0_INTERNAL int m0_xcode_print (const struct m0_xcode_obj *obj, char *str, int nr)
 
M0_INTERNAL void m0_xcode_free_obj (struct m0_xcode_obj *obj)
 
M0_INTERNAL void m0_xcode_free (struct m0_xcode_ctx *ctx)
 
M0_INTERNAL int m0_xcode_cmp (const struct m0_xcode_obj *o0, const struct m0_xcode_obj *o1)
 
M0_INTERNAL int m0_xcode_dup (struct m0_xcode_ctx *dest, struct m0_xcode_ctx *src)
 
M0_INTERNAL bool m0_xcode_type_flags (struct m0_xcode_type *xt, uint32_t on, uint32_t off, uint64_t aggr_umask)
 
M0_INTERNAL void * m0_xcode_addr (const struct m0_xcode_obj *obj, int fileno, uint64_t elno)
 
M0_INTERNAL uint64_t m0_xcode_atom (const struct m0_xcode_obj *obj)
 
M0_INTERNAL int m0_xcode_subobj (struct m0_xcode_obj *subobj, const struct m0_xcode_obj *obj, int fieldno, uint64_t elno)
 
M0_INTERNAL uint64_t m0_xcode_tag (const struct m0_xcode_obj *obj)
 
M0_INTERNAL int m0_xcode_find (struct m0_xcode_obj *obj, const struct m0_xcode_type *xt, void **place)
 
bool m0_xcode_type_invariant (const struct m0_xcode_type *xt)
 
M0_INTERNAL void m0_xcode_union_init (struct m0_xcode_type *un, const char *name, const char *discriminator, size_t maxbranches)
 
M0_INTERNAL void m0_xcode_union_fini (struct m0_xcode_type *un)
 
M0_INTERNAL void m0_xcode_union_add (struct m0_xcode_type *un, const char *name, const struct m0_xcode_type *xt, uint64_t tag)
 
M0_INTERNAL void m0_xcode_union_close (struct m0_xcode_type *un)
 
M0_INTERNAL int m0_xcode_decor_register (void)
 
M0_INTERNAL void m0_xcode_bob_type_init (struct m0_bob_type *bt, const struct m0_xcode_type *xt, size_t magix_field, uint64_t magix)
 
M0_INTERNAL void * m0_xcode_ctx_top (const struct m0_xcode_ctx *ctx)
 
void m0_xc_u8_init (void)
 
void m0_xc_u16_init (void)
 
void m0_xc_u32_init (void)
 
void m0_xc_u64_init (void)
 
void m0_xc_void_init (void)
 
void m0_xc_opaque_init (void)
 

Variables

const char * m0_xcode_aggr_name [M0_XA_NR]
 
const char * m0_xcode_atom_type_name [M0_XAT_NR]
 
const struct m0_xcode_type M0_XT_VOID
 
const struct m0_xcode_type M0_XT_U8
 
const struct m0_xcode_type M0_XT_U32
 
const struct m0_xcode_type M0_XT_U64
 
const struct m0_xcode_type M0_XT_OPAQUE
 

iteration

xcode provides an iteration interface to walk through the hierarchy of types and fields.

This interface consists of two functions: m0_xcode_next(), m0_xcode_skip() and m0_xcode_cursor data-type.

m0_xcode_next() takes a starting type (m0_xcode_type) and walks the tree of its fields, their types, their fields &c., all the way down to the atomic types.

m0_xcode_next() can be used to walk the tree in any "standard" order: preorder, inorder and postorder traversals are supported. To this end, m0_xcode_next() visits each tree node multiple times, setting the flag m0_xcode_cursor::xcu_stack[]::s_flag according to the order.

enum  m0_xcode_cursor_flag {
  M0_XCODE_CURSOR_NONE, M0_XCODE_CURSOR_PRE, M0_XCODE_CURSOR_IN, M0_XCODE_CURSOR_POST,
  M0_XCODE_CURSOR_NR
}
 
const char * m0_xcode_cursor_flag_name [M0_XCODE_CURSOR_NR]
 
M0_INTERNAL void m0_xcode_cursor_init (struct m0_xcode_cursor *it, const struct m0_xcode_obj *obj)
 
M0_INTERNAL int m0_xcode_next (struct m0_xcode_cursor *it)
 
M0_INTERNAL void m0_xcode_skip (struct m0_xcode_cursor *it)
 
M0_INTERNAL struct m0_xcode_cursor_frame * m0_xcode_cursor_top (struct m0_xcode_cursor *it)
 
M0_INTERNAL const struct m0_xcode_fieldm0_xcode_cursor_field (const struct m0_xcode_cursor *it)
 

xcoding.

Encoding-decoding (collectively xcoding) support is implemented on top of introspection facilities provided by the xcode module. xcoding provides 3 operations:

- sizing (m0_xcode_length()): returns the size of a buffer sufficient to
  hold serialized object representation;

- encoding (m0_xcode_encode()): constructs a serialized object
  representation in a given buffer;

- decoding (m0_xcode_decode()): constructs an in-memory object, given its
  serialized representation.

xcoding traverses the tree of sub-objects, starting from the topmost object to be xcoded. For each visited object, if a method, corresponding to the xcoding operation (encode, decode, length) is not NULL in object's type m0_xcode_type_ops vector, this method is called and no further processing of this object is done. Otherwise, "standard xcoding" takes place.

Standard xcoding is non-trivial only for leaves in the sub-object tree (i.e., for objects of ATOM aggregation type):

- for encoding, place object's value into the buffer, convert it to
  desired endianness and advance buffer position;

- for decoding, extract value from the buffer, convert it, store in the
  in-memory object and advance buffer position;

- for sizing, increment required buffer size by the size of atomic type.

In addition, decoding allocates memory as necessary.

enum  m0_xcode_endianness { M0_XEND_LE, M0_XEND_BE, M0_XEND_NR }
 
enum  m0_xcode_what { M0_XCODE_ENCODE = 0, M0_XCODE_DECODE = 1 }
 
const char * m0_xcode_endianness_name [M0_XEND_NR]
 
M0_INTERNAL void m0_xcode_ctx_init (struct m0_xcode_ctx *ctx, const struct m0_xcode_obj *obj)
 
M0_INTERNAL int m0_xcode_decode (struct m0_xcode_ctx *ctx)
 
M0_INTERNAL int m0_xcode_encode (struct m0_xcode_ctx *ctx)
 
M0_INTERNAL int m0_xcode_length (struct m0_xcode_ctx *ctx)
 
M0_INTERNAL void m0_xcode_type_iterate (struct m0_xcode_type *xt, void(*t)(struct m0_xcode_type *, void *), void(*f)(struct m0_xcode_type *, struct m0_xcode_field *, void *), void *datum)
 
M0_INTERNAL int m0_xcode_encdec (struct m0_xcode_obj *obj, struct m0_bufvec_cursor *cur, enum m0_xcode_what what)
 
M0_INTERNAL int m0_xcode_obj_enc_to_buf (struct m0_xcode_obj *obj, void **buf, m0_bcount_t *len)
 
M0_INTERNAL int m0_xcode_obj_dec_from_buf (struct m0_xcode_obj *obj, void *buf, m0_bcount_t len)
 
M0_INTERNAL int m0_xcode_data_size (struct m0_xcode_ctx *ctx, const struct m0_xcode_obj *obj)
 
M0_INTERNAL void * m0_xcode_alloc (struct m0_xcode_cursor *it, size_t nob)
 
M0_INTERNAL bool m0_xcode_is_byte_array (const struct m0_xcode_type *xt)
 
M0_EXTERN ssize_t m0_xcode_alloc_obj (struct m0_xcode_cursor *it, void *(*alloc)(struct m0_xcode_cursor *, size_t))
 

Macro Definition Documentation

◆ __MOTR_XCODE_XCODE_H__

#define __MOTR_XCODE_XCODE_H__

Definition at line 26 of file xcode.h.