LCOV - code coverage report
Current view: top level - flamenco/types - fd_types_meta.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 30 38 78.9 %
Date: 2025-03-20 12:08:36 Functions: 6 804 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       31986 : #define FD_FLAMENCO_TYPE_BOOL      (0x01)
      14       32340 : #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         249 : #define FD_FLAMENCO_TYPE_UINT      (0x06)
      19           0 : #define FD_FLAMENCO_TYPE_SINT      (0x07)
      20      130926 : #define FD_FLAMENCO_TYPE_ULONG     (0x08)
      21       26484 : #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       92766 : #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           6 : #define FD_FLAMENCO_TYPE_HASH16384 (0x12)
      33      256155 : #define FD_FLAMENCO_TYPE_ENUM_DISC (0x13)
      34             : 
      35         141 : #define FD_FLAMENCO_TYPE_ARR       (0x20)
      36          60 : #define FD_FLAMENCO_TYPE_ARR_END   (0x21)
      37       97644 : #define FD_FLAMENCO_TYPE_MAP       (0x22)
      38       48810 : #define FD_FLAMENCO_TYPE_MAP_END   (0x23)
      39       49140 : #define FD_FLAMENCO_TYPE_ENUM      (0x24)
      40         156 : #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_footprint_fun)(fd_bincode_decode_ctx_t *, ulong * total_sz);
      46             :   void* (*decode_fun)(void* self, fd_bincode_decode_ctx_t *);
      47             :   int   (*encode_fun)(void const * self, fd_bincode_encode_ctx_t * ctx);
      48             :   int   (*walk_fun)(void * w, void * self, fd_types_walk_fn_t, const char *, uint);
      49             :   ulong (*align_fun)( void );
      50             :   ulong (*footprint_fun)( void );
      51             :   ulong (*size_fun)(void const * self);
      52             :   void  (*destroy_fun)(void* self);
      53             :   void* (*new_fun)(void *);
      54             : };
      55             : 
      56             : typedef struct fd_types_funcs fd_types_funcs_t;
      57             : 
      58             : FD_PROTOTYPES_BEGIN
      59             : 
      60             : /* fd_flamenco_type_is_primitive returns 1 if type does not contain
      61             :    any child nodes.  Returns 0 otherwise. */
      62             : 
      63             : FD_FN_CONST static inline int
      64          63 : fd_flamenco_type_is_primitive( int type ) {
      65          63 :   return (type&0xe0)==0x00;
      66          63 : }
      67             : 
      68             : /* fd_flamenco_type_is_collection returns 1 if node type marks the
      69             :    beginning or end of a collection.  Returns 0 otherwise. */
      70             : 
      71             : FD_FN_CONST static inline int
      72      255942 : fd_flamenco_type_is_collection( int type ) {
      73      255942 :   return (type&0xe0)==0x20;
      74      255942 : }
      75             : 
      76             : /* fd_flamenco_type_is_collection_{begin,end} return 1 if collection
      77             :    type marks the beginning or end of a collection respectively. */
      78             : 
      79             : FD_FN_CONST static inline int
      80          12 : fd_flamenco_type_is_collection_begin( int type ) {
      81          12 :   return fd_flamenco_type_is_collection(type) && ((type&1)==0);
      82          12 : }
      83             : 
      84             : FD_FN_CONST static inline int
      85      255867 : fd_flamenco_type_is_collection_end( int type ) {
      86      255867 :   return fd_flamenco_type_is_collection(type) && ((type&1)!=0);
      87      255867 : }
      88             : 
      89             : FD_PROTOTYPES_END
      90             : 
      91             : #endif /* HEADER_fd_src_flamenco_types_fd_types_meta_h */

Generated by: LCOV version 1.14