LCOV - code coverage report
Current view: top level - choreo/tower - fd_tower_serde.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 44 0.0 %
Date: 2025-12-06 04:45:29 Functions: 0 3 0.0 %

          Line data    Source code
       1             : #include "fd_tower_serde.h"
       2             : #include "fd_tower.h"
       3             : 
       4             : #define SHORTVEC 0
       5             : 
       6           0 : #define DE( T, name ) do {                                                               \
       7           0 :     if( FD_UNLIKELY( off+sizeof(T)>buf_sz ) ) return -1;                                 \
       8           0 :     serde->name = *(T const *)fd_type_pun_const( buf+off );                              \
       9           0 :     off += sizeof(T);                                                                    \
      10           0 : } while(0)
      11             : 
      12             : static ulong
      13           0 : de_short_u16( ushort * dst, uchar const * src ) {
      14           0 :   if     ( FD_LIKELY( !(0x80U & src[0]) ) ) { *dst = (ushort)src[0];                                                                           return 1; }
      15           0 :   else if( FD_LIKELY( !(0x80U & src[1]) ) ) { *dst = (ushort)((ulong)(src[0]&0x7FUL) + (((ulong)src[1])<<7));                                  return 2; }
      16           0 :   else                                      { *dst = (ushort)((ulong)(src[0]&0x7FUL) + (((ulong)(src[1]&0x7FUL))<<7) + (((ulong)src[2])<<14)); return 3; }
      17           0 : }
      18             : 
      19             : static ulong
      20           0 : de_var_int( ulong * dst, uchar const * src ) {
      21           0 :   *dst = 0;
      22           0 :   ulong off = 0;
      23           0 :   ulong bit = 0;
      24           0 :   while( FD_LIKELY( bit < 64 ) ) {
      25           0 :     uchar byte = *(uchar const *)(src+off);
      26           0 :     off       += 1;
      27           0 :     *dst      |= (byte & 0x7FUL) << bit;
      28           0 :     if( FD_LIKELY( (byte & 0x80U) == 0U ) ) {
      29           0 :       if( FD_UNLIKELY( (*dst>>bit) != byte                ) ) FD_LOG_CRIT(( "de_varint" ));
      30           0 :       if( FD_UNLIKELY( byte==0U && (bit!=0U || *dst!=0UL) ) ) FD_LOG_CRIT(( "de_varint" ));
      31           0 :       return off;
      32           0 :     }
      33           0 :     bit += 7;
      34           0 :   }
      35           0 :   FD_LOG_CRIT(( "de_varint" ));
      36           0 : }
      37             : 
      38             : int
      39             : fd_compact_tower_sync_deserialize( fd_compact_tower_sync_serde_t * serde,
      40             :                                    uchar const *                   buf,
      41           0 :                                    ulong                           buf_sz ) {
      42           0 :   ulong off = 0;
      43           0 :   DE( ulong, root );
      44           0 :   off += de_short_u16( &serde->lockouts_cnt, buf+off );
      45           0 :   if( FD_UNLIKELY( serde->lockouts_cnt > FD_TOWER_VOTE_MAX ) ) return -1;
      46           0 :   for( ulong i = 0; i < serde->lockouts_cnt; i++ ) {
      47           0 :     off += de_var_int( &serde->lockouts[i].offset, buf+off );
      48           0 :     DE( uchar, lockouts[i].confirmation_count );
      49           0 :   }
      50           0 :   DE( fd_hash_t, hash             );
      51           0 :   DE( uchar,     timestamp_option );
      52           0 :   if( FD_LIKELY( serde->timestamp_option ) ) {
      53           0 :     DE( long, timestamp );
      54           0 :   }
      55           0 :   DE( fd_hash_t, block_id );
      56           0 :   return 0;
      57           0 : }

Generated by: LCOV version 1.14