LCOV - code coverage report
Current view: top level - flamenco/snapshot - fd_snapshot_istream.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 16 0.0 %
Date: 2024-11-13 11:58:15 Functions: 0 18 0.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_snapshot_fd_snapshot_istream_h
       2             : #define HEADER_fd_src_flamenco_snapshot_fd_snapshot_istream_h
       3             : 
       4             : #include "../../util/archive/fd_tar.h"
       5             : #include "../../ballet/zstd/fd_zstd.h"
       6             : 
       7             : /* Input stream API ***************************************************/
       8             : 
       9             : /* Below are APIs to support the streaming read pipeline.
      10             : 
      11             :    TODO: The indirect call architecture used here is suboptimal.
      12             :          In the future, we'd want to use a fd_tango based message
      13             :          passing architecture to allow streamlining the pipeline across
      14             :          multiple cores.  This scales better, is more secure, faster,
      15             :          and more flexible.  However, it requires non-trivial tile
      16             :          orchestration, which is still being worked on at the time of
      17             :          writing.*/
      18             : 
      19             : /* Below is an experimental object-oriented API for handling output
      20             :    streams of data.  It is dynamically dispatched (C++ style virtual
      21             :    function tables) */
      22             : 
      23             : struct fd_io_istream_vt {
      24             : 
      25             :   /* Virtual version of fd_io_read
      26             :      Assumed to be blocking (TODO fix) */
      27             : 
      28             :   int
      29             :   (* read)( void *  _this,
      30             :             void *  _dst,
      31             :             ulong   dst_max,
      32             :             ulong * _dst_sz );
      33             : 
      34             : };
      35             : 
      36             : typedef struct fd_io_istream_vt fd_io_istream_vt_t;
      37             : 
      38             : struct fd_io_istream_obj {
      39             :   void *                     this;
      40             :   fd_io_istream_vt_t const * vt;
      41             : };
      42             : 
      43             : typedef struct fd_io_istream_obj fd_io_istream_obj_t;
      44             : 
      45             : FD_PROTOTYPES_BEGIN
      46             : 
      47             : static inline int
      48             : fd_io_istream_obj_read( fd_io_istream_obj_t * obj,
      49             :                         void *                dst,
      50             :                         ulong                 dst_max,
      51           0 :                         ulong *               dst_sz ) {
      52           0 :   return obj->vt->read( obj->this, dst, dst_max, dst_sz );
      53           0 : }
      54             : 
      55             : FD_PROTOTYPES_END
      56             : 
      57             : 
      58             : /* fd_io_istream_zstd_t implements fd_io_istream_vt_t. ****************/
      59             : 
      60             : #if FD_HAS_ZSTD
      61             : 
      62             : struct fd_io_istream_zstd {
      63             :   fd_zstd_dstream_t * dstream;  /* borrowed for lifetime of self */
      64             :   fd_io_istream_obj_t src;
      65             : 
      66           0 : # define FD_IO_ISTREAM_ZSTD_BUFSZ (8192UL)  /* should probably be configurable at runtime */
      67             :   uchar   in_buf[ FD_IO_ISTREAM_ZSTD_BUFSZ ];
      68             :   uchar * in_cur;  /* in_cur in [in_buf,in_end) */
      69             :   uchar * in_end;  /* in_end in [in_buf,in_buf+FD_IO_ISTREAM_ZSTD_BUFSZ) */
      70             : 
      71             :   int dirty;
      72             : };
      73             : 
      74             : typedef struct fd_io_istream_zstd fd_io_istream_zstd_t;
      75             : 
      76             : FD_PROTOTYPES_BEGIN
      77             : 
      78             : fd_io_istream_zstd_t *
      79             : fd_io_istream_zstd_new( void *              mem,
      80             :                         fd_zstd_dstream_t * dstream,
      81             :                         fd_io_istream_obj_t src );
      82             : 
      83             : void *
      84             : fd_io_istream_zstd_delete( fd_io_istream_zstd_t * this );
      85             : 
      86             : int
      87             : fd_io_istream_zstd_read( void *  _this,
      88             :                          void *  dst,
      89             :                          ulong   dst_max,
      90             :                          ulong * dst_sz );
      91             : 
      92             : extern fd_io_istream_vt_t const fd_io_istream_zstd_vt;
      93             : 
      94             : static inline fd_io_istream_obj_t
      95           0 : fd_io_istream_zstd_virtual( fd_io_istream_zstd_t * this ) {
      96           0 :   return (fd_io_istream_obj_t) {
      97           0 :     .this = this,
      98           0 :     .vt   = &fd_io_istream_zstd_vt
      99           0 :   };
     100           0 : }
     101             : 
     102             : FD_PROTOTYPES_END
     103             : 
     104             : #endif /* FD_HAS_ZSTD */
     105             : 
     106             : 
     107             : /* fd_io_istream_file_t implements fd_io_istream_vt_t. ****************/
     108             : 
     109             : struct fd_io_istream_file {
     110             :   int fd;
     111             : };
     112             : 
     113             : typedef struct fd_io_istream_file fd_io_istream_file_t;
     114             : 
     115             : FD_PROTOTYPES_BEGIN
     116             : 
     117             : fd_io_istream_file_t *
     118             : fd_io_istream_file_new( void * mem,
     119             :                         int    fd );
     120             : 
     121             : void *
     122             : fd_io_istream_file_delete( fd_io_istream_file_t * this );
     123             : 
     124             : int
     125             : fd_io_istream_file_read( void *  _this,
     126             :                          void *  dst,
     127             :                          ulong   dst_max,
     128             :                          ulong * dst_sz );
     129             : 
     130             : extern fd_io_istream_vt_t const fd_io_istream_file_vt;
     131             : 
     132             : static inline fd_io_istream_obj_t
     133           0 : fd_io_istream_file_virtual( fd_io_istream_file_t * this ) {
     134           0 :   return (fd_io_istream_obj_t) {
     135           0 :     .this = this,
     136           0 :     .vt   = &fd_io_istream_file_vt
     137           0 :   };
     138           0 : }
     139             : 
     140             : FD_PROTOTYPES_END
     141             : 
     142             : 
     143             : /* fd_tar_io_reader_t reads a tar from an fd_io_istream_obj_t source. */
     144             : 
     145             : struct fd_tar_io_reader {
     146             :   fd_tar_reader_t *   reader;  /* borrowed for lifetime */
     147             :   fd_io_istream_obj_t src;
     148             : };
     149             : 
     150             : typedef struct fd_tar_io_reader fd_tar_io_reader_t;
     151             : 
     152             : FD_PROTOTYPES_BEGIN
     153             : 
     154             : fd_tar_io_reader_t *
     155             : fd_tar_io_reader_new( void *              mem,
     156             :                       fd_tar_reader_t *   reader,
     157             :                       fd_io_istream_obj_t src );
     158             : 
     159             : void *
     160             : fd_tar_io_reader_delete( fd_tar_io_reader_t * this );
     161             : 
     162             : int
     163             : fd_tar_io_reader_advance( fd_tar_io_reader_t * this );
     164             : 
     165             : FD_PROTOTYPES_END
     166             : 
     167             : #endif /* HEADER_fd_src_flamenco_snapshot_fd_snapshot_istream_h */

Generated by: LCOV version 1.14