LCOV - code coverage report
Current view: top level - flamenco/types - fd_types_meta.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 29 38 76.3 %
Date: 2024-11-13 11:58:15 Functions: 6 844 0.7 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_types_fd_types_meta_h
       2             : #define HEADER_fd_src_flamenco_types_fd_types_meta_h
       3             : 
       4             : #include "../../util/fd_util_base.h"
       5             : #include "fd_bincode.h"
       6             : 
       7             : /* fd_types_meta.h provides reflection APIs for fd_types. */
       8             : 
       9             : /* FD_FLAMENCO_TYPE_{...} identifies kinds of nodes encountered in a
      10             :    bincode/borsh data structure graph. */
      11             : 
      12           9 : #define FD_FLAMENCO_TYPE_NULL      (0x00)
      13           6 : #define FD_FLAMENCO_TYPE_BOOL      (0x01)
      14         168 : #define FD_FLAMENCO_TYPE_UCHAR     (0x02)
      15           0 : #define FD_FLAMENCO_TYPE_SCHAR     (0x03)
      16         318 : #define FD_FLAMENCO_TYPE_USHORT    (0x04)
      17           0 : #define FD_FLAMENCO_TYPE_SSHORT    (0x05)
      18          63 : #define FD_FLAMENCO_TYPE_UINT      (0x06)
      19           0 : #define FD_FLAMENCO_TYPE_SINT      (0x07)
      20        1152 : #define FD_FLAMENCO_TYPE_ULONG     (0x08)
      21          18 : #define FD_FLAMENCO_TYPE_SLONG     (0x09)
      22             : #if FD_HAS_INT128
      23           0 : #define FD_FLAMENCO_TYPE_UINT128   (0x0a)
      24           0 : #define FD_FLAMENCO_TYPE_SINT128   (0x0b)
      25             : #endif /* FD_HAS_INT128 */
      26           0 : #define FD_FLAMENCO_TYPE_FLOAT     (0x0c)
      27           0 : #define FD_FLAMENCO_TYPE_DOUBLE    (0x0d)
      28         312 : #define FD_FLAMENCO_TYPE_HASH256   (0x0e)  /* pubkey, account */
      29          78 : #define FD_FLAMENCO_TYPE_SIG512    (0x0f)
      30         186 : #define FD_FLAMENCO_TYPE_CSTR      (0x10)
      31           0 : #define FD_FLAMENCO_TYPE_HASH1024  (0x11)
      32           0 : #define FD_FLAMENCO_TYPE_HASH16384 (0x12)
      33        2682 : #define FD_FLAMENCO_TYPE_ENUM_DISC (0x13)
      34             : 
      35         117 : #define FD_FLAMENCO_TYPE_ARR       (0x20)
      36          48 : #define FD_FLAMENCO_TYPE_ARR_END   (0x21)
      37         726 : #define FD_FLAMENCO_TYPE_MAP       (0x22)
      38         345 : #define FD_FLAMENCO_TYPE_MAP_END   (0x23)
      39         675 : #define FD_FLAMENCO_TYPE_ENUM      (0x24)
      40         147 : #define FD_FLAMENCO_TYPE_ENUM_END  (0x25)
      41             : 
      42             : /* TODO: This should be called fd_types_vtable_t. */
      43             : 
      44             : struct fd_types_funcs {
      45             :   int   (*decode_fun)(void* self, fd_bincode_decode_ctx_t *);
      46             :   int   (*encode_fun)(void const * self, fd_bincode_encode_ctx_t * ctx);
      47             :   int   (*walk_fun)(void * w, void * self, fd_types_walk_fn_t, const char *, uint);
      48             :   ulong (*align_fun)( void );
      49             :   ulong (*footprint_fun)( void );
      50             :   ulong (*size_fun)(void const * self);
      51             :   void  (*destroy_fun)(void* self, fd_bincode_destroy_ctx_t * ctx);
      52             :   void* (*new_fun)(void *);
      53             : };
      54             : 
      55             : typedef struct fd_types_funcs fd_types_funcs_t;
      56             : 
      57             : FD_PROTOTYPES_BEGIN
      58             : 
      59             : /* fd_flamenco_type_is_primitive returns 1 if type does not contain
      60             :    any child nodes.  Returns 0 otherwise. */
      61             : 
      62             : FD_FN_CONST static inline int
      63          63 : fd_flamenco_type_is_primitive( int type ) {
      64          63 :   return (type&0xe0)==0x00;
      65          63 : }
      66             : 
      67             : /* fd_flamenco_type_is_collection returns 1 if node type marks the
      68             :    beginning or end of a collection.  Returns 0 otherwise. */
      69             : 
      70             : FD_FN_CONST static inline int
      71        2475 : fd_flamenco_type_is_collection( int type ) {
      72        2475 :   return (type&0xe0)==0x20;
      73        2475 : }
      74             : 
      75             : /* fd_flamenco_type_is_collection_{begin,end} return 1 if collection
      76             :    type marks the beginning or end of a collection respectively. */
      77             : 
      78             : FD_FN_CONST static inline int
      79          12 : fd_flamenco_type_is_collection_begin( int type ) {
      80          12 :   return fd_flamenco_type_is_collection(type) && ((type&1)==0);
      81          12 : }
      82             : 
      83             : FD_FN_CONST static inline int
      84        2400 : fd_flamenco_type_is_collection_end( int type ) {
      85        2400 :   return fd_flamenco_type_is_collection(type) && ((type&1)!=0);
      86        2400 : }
      87             : 
      88             : FD_PROTOTYPES_END
      89             : 
      90             : #endif /* HEADER_fd_src_flamenco_types_fd_types_meta_h */

Generated by: LCOV version 1.14