uint64_t DataIStream::getRemainingBufferSize() { if( !_checkBuffer( )) return 0; return _impl->inputSize - _impl->position; }
INT32 _readFile( const CHAR *pFilePath, CHAR **ppBuff, INT64 *pBuffLen ) { INT32 rc = SDB_OK ; BOOLEAN hasOpen = FALSE ; INT64 fileSize = 0 ; SINT64 readSize = 0 ; OSSFILE file ; stringstream ss ; if ( !ppBuff ) { rc = SDB_INVALIDARG ; goto error ; } rc = ossAccess( pFilePath ) ; if ( rc ) { ss << "Failed to access file[" << pFilePath << "], rc = " << rc << ERROR_END ; goto error ; } rc = ossOpen( pFilePath, OSS_READONLY, 0, file ) ; if ( rc ) { ss << "Failed to open file[" << pFilePath << "], rc = " << rc << ERROR_END ; goto error ; } hasOpen = TRUE ; rc = ossGetFileSize( &file, &fileSize ) ; if ( rc ) { ss << "Failed to get the size of file[" << pFilePath << "], rc = " << rc << ERROR_END ; goto error ; } rc = _checkBuffer( ppBuff, pBuffLen, fileSize ) ; if ( rc ) { ss << "Failed to check the size of buffer when read[" << pFilePath << "], rc = " << rc << ERROR_END ; goto error ; } rc = ossReadN( &file, fileSize, *ppBuff, readSize ) ; if ( rc ) { ss << "Failed to read content from file[" << pFilePath << "], rc = " << rc << ERROR_END ; } done: if ( hasOpen ) { ossClose( file ) ; } return rc ; error: cout << ss.str().c_str() << endl ; goto done ; }
void DataIStream::_read( void* data, uint64_t size ) { if( !_checkBuffer( )) { LBUNREACHABLE; LBERROR << "No more input data" << std::endl; return; } LBASSERT( _impl->input ); if( _impl->position + size > _impl->inputSize ) { LBERROR << "Not enough data in input buffer: need " << size << " bytes, " << _impl->inputSize - _impl->position << " left " << std::endl; LBUNREACHABLE; // TODO: Allow reads which are asymmetric to writes by reading from // multiple blocks here? return; } memcpy( data, _impl->input + _impl->position, size ); _impl->position += size; }
const void* DataIStream::getRemainingBuffer( const uint64_t size ) { if( !_checkBuffer( )) return 0; LBASSERT( _impl->position + size <= _impl->inputSize ); if( _impl->position + size > _impl->inputSize ) return 0; _impl->position += size; return _impl->input + _impl->position - size; }