예제 #1
0
파일: vdb_info.c 프로젝트: ncbi/sra-tools
static void get_meta_bam_hdr( vdb_info_bam_hdr * bam_hdr, const KMetadata * meta )
{
    const KMDataNode * node;
    rc_t rc = KMetadataOpenNodeRead ( meta, &node, "BAM_HEADER" );
    bam_hdr -> present = ( rc == 0 );
    if ( bam_hdr -> present )
    {
        bam_hdr->hdr_bytes = get_node_size( node );
        if ( bam_hdr->hdr_bytes > 0 )
        {
            char * buffer = malloc( bam_hdr->hdr_bytes );
            if ( buffer != NULL )
            {
                size_t num_read, remaining;
                rc = KMDataNodeRead( node, 0, buffer, bam_hdr->hdr_bytes, &num_read, &remaining );
                if ( rc == 0 )
                {
                    parse_buffer( bam_hdr, buffer, bam_hdr->hdr_bytes );
                }
                free( buffer );
            }
        }
        KMDataNodeRelease ( node );
    }
}
예제 #2
0
파일: vdb_info.c 프로젝트: ncbi/sra-tools
static size_t get_node_size( const KMDataNode * node )
{
    char buffer[ 10 ];
    size_t num_read, remaining, res = 0;
    rc_t rc = KMDataNodeRead( node, 0, buffer, sizeof( buffer ), &num_read, &remaining );
    if ( rc == 0 ) res = num_read + remaining;
    return res;
}
예제 #3
0
static rc_t copy_metadata_data ( const KMDataNode *snode, KMDataNode *dnode )
{
    char buffer [ 1024 ];
    size_t total, bytes, remaining;
    /* copy node data unless already set */
    rc_t rc = KMDataNodeRead ( dnode, 0, buffer, 0, & bytes, & total );
    DISP_RC( rc, "copy_metadata_child:KMDataNodeRead(dst) failed" );
    if ( rc == 0 && total == 0 )
    do
    {
        rc = KMDataNodeRead ( snode, total, buffer, sizeof buffer, & bytes, & remaining );
        DISP_RC( rc, "copy_metadata_child:KMDataNodeRead(src) failed" );
        if ( rc == 0 )
        {
            rc = KMDataNodeAppend ( dnode, buffer, bytes );
            DISP_RC( rc, "copy_metadata_child:KMDataNodeAppend(dst) failed" );
            if ( rc != 0 ) break;
        }
        total += bytes;
     } while ( remaining != 0 );
    return rc;
}
예제 #4
0
파일: untyped.c 프로젝트: ImAWolf/ncbi-vdb
static
bool KMetadataEmpty ( const KMetadata *meta, const char *path )
{
    size_t num_read, remaining;
    const KMDataNode *node;
    rc_t rc = KMetadataOpenNodeRead ( meta, & node, "%s", path );
    if ( rc != 0 )
        return true;
    rc = KMDataNodeRead ( node, 0, & num_read, 0, & num_read, & remaining );
    KMDataNodeRelease ( node );
    if ( rc == 0 && remaining != 0 )
        return false;
    return true;
}
예제 #5
0
static rc_t print_headers_from_metadata( const VDatabase * db, bool * recalc, const char * path )
{
    const KMetadata * meta;
    rc_t rc = VDatabaseOpenMetadataRead( db, &meta );
    if ( rc != 0 )
        (void)PLOGERR( klogErr, ( klogErr, rc, "cannot open metadata from '$(t)'", "t=%s", path ) );
    else
    {
        const KMDataNode * node;
        rc = KMetadataOpenNodeRead( meta, &node, "BAM_HEADER" );
        if ( rc != 0 )
        {
            if ( GetRCState( rc ) == rcNotFound )
            {
                *recalc = true;
                rc = 0;
            }
            else
                (void)PLOGERR( klogErr, ( klogErr, rc, "cannot open meta-node 'BAM_HEADER' from '$(t)'", "t=%s", path ) );
        }
        else
        {
            size_t offset = 0, num_read, remaining = ~0;
            char buffer[ 40960 ];
            while ( rc == 0 && remaining > 0 )
            {
                rc = KMDataNodeRead( node, offset, buffer, sizeof( buffer ),
                                     &num_read, &remaining );
                if ( rc == 0 )
                {
                    rc = KOutMsg( "%.*s", ( uint32_t )num_read, buffer );
                    offset += num_read;
                }
            }
            if ( rc == 0 && buffer[ num_read - 1 ] != '\n' )
            {
                rc = KOutMsg( "\n" );
            }
            KMDataNodeRelease( node );
        }
        KMetadataRelease( meta );
    }
    return rc;
}
예제 #6
0
static rc_t CC read_from_metadata_node( const void * src, uint64_t pos, void * buffer, size_t bsize, size_t * num_read )
{
    const KMDataNode * node = src;
    size_t remaining;
    return KMDataNodeRead( node, pos, buffer, bsize, num_read, &remaining );
}
예제 #7
0
파일: meta.hpp 프로젝트: ImAWolf/ncbi-vdb
 /* Read
  *  read a node value
  *
  *  "offset" [ IN ] - initial offset into metadata
  *
  *  "buffer" [ OUT ] and "bsize" [ IN ] - return buffer for read
  *
  *  "num_read" [ OUT ] - number of bytes actually read
  *
  *  "remaining" [ OUT, NULL OKAY ] - optional return parameter for
  *  the number of bytes remaining to be read.
  *  specifically, "offset" + "num_read" + "remaining" == sizeof node data
  */
  inline rc_t Read ( size_t offset, void *buffer, size_t bsize,
     size_t *num_read, size_t *remaining ) const throw()
  { return KMDataNodeRead ( this, offset, buffer, bsize, num_read, remaining ); }