Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
这是什么C++;反序列化成语?使用整型ID变量“reinterpret\u cast”调用文件读取器函数<;字符*>;(&;id)` 我正在阅读内部构件SEQAN库(它处理生物学特定的文件格式和数据结构),我遇到的是一个我不太理解的C++习语。p>_C++_Serialization_Deserialization_Bioinformatics_Seqan - Fatal编程技术网

这是什么C++;反序列化成语?使用整型ID变量“reinterpret\u cast”调用文件读取器函数<;字符*>;(&;id)` 我正在阅读内部构件SEQAN库(它处理生物学特定的文件格式和数据结构),我遇到的是一个我不太理解的C++习语。p>

这是什么C++;反序列化成语?使用整型ID变量“reinterpret\u cast”调用文件读取器函数<;字符*>;(&;id)` 我正在阅读内部构件SEQAN库(它处理生物学特定的文件格式和数据结构),我遇到的是一个我不太理解的C++习语。p>,c++,serialization,deserialization,bioinformatics,seqan,C++,Serialization,Deserialization,Bioinformatics,Seqan,有一个唯一的id变量record.rID,它是一个_int32。指向它的指针被传递给另一个函数,该函数从文件中读取一组数据并修改id 这是电话: res = streamReadBlock(reinterpret_cast<char *>(&record.rID), stream, 4); res=streamReadBlock(reinterpret_cast(&record.rID)),stream,4; 下面是函数实现: inline size_t streamRe

有一个唯一的id变量
record.rID
,它是一个_int32。指向它的指针被传递给另一个函数,该函数从文件中读取一组数据并修改id

这是电话:

res = streamReadBlock(reinterpret_cast<char *>(&record.rID), stream, 4);
res=streamReadBlock(reinterpret_cast(&record.rID)),stream,4;
下面是函数实现:

inline size_t
streamReadBlock(char * target, Stream<Bgzf> & stream, size_t maxLen)
{
    if (!(stream._openMode & OPEN_RDONLY))
        return 0;  // File not open for reading.

    // Memoize number of read bytes and pointer into the buffer target.
    size_t bytesRead = 0;
    char * destPtr = target;

    // Read at most maxLen characters, each loop iteration corresponds to reading the end of the first, the beginning of
    // the last or the whole "middle" buffers.  Of course, the first and only iteration can also only read parts of the
    // first buffer.
    while (bytesRead < maxLen)
    {
        // If there are no more bytes left in the current block then read and decompress the next block.
        int available = stream._blockLength - stream._blockOffset;
        if (available <= 0)
        {
            if (_bgzfReadBlock(stream) != 0)
                return -1;  // Could not read next block.
            available = stream._blockLength - stream._blockOffset;
            if (available <= 0)
                break;
        }

        // Copy out the number of bytes to be read or the number of available bytes in the next buffer, whichever number
        // is smaller.
        int copyLength = std::min(static_cast<int>(maxLen - bytesRead), available);
        char * buffer = &stream._uncompressedBlock[0];
        memcpy(destPtr, buffer + stream._blockOffset, copyLength);

        // Advance to next block.
        stream._blockOffset += copyLength;
        destPtr += copyLength;
        bytesRead += copyLength;
    }

    // If we read to the end of the block above then switch the block address to the next block and mark it as unread.
    if (stream._blockOffset == stream._blockLength)
    {
        stream._blockPosition = tell(stream._file);
        stream._blockOffset = 0;
        stream._blockLength = 0;
    }

    return bytesRead;
}
内联大小\u t
streamReadBlock(字符*目标、流和流、大小\u t最大值)
{
if(!(流._openMode&OPEN_RDONLY))
返回0;//文件未打开以进行读取。
//将读取字节数和指针记忆到缓冲区目标中。
大小字节读取=0;
char*destPtr=目标;
//读取最多maxLen个字符,每个循环迭代对应于读取第一个循环的结束,第一个循环的开始
//最后或整个“中间”缓冲区。当然,第一次也是唯一一次迭代也只能读取部分缓冲区
//第一缓冲区。
while(字节读取如果(可用这是一种写入int的聪明方法。通过将record.rID的地址强制转换为指向char的指针,您可以使用memcpy直接向其写入字节。

我猜的是流的前4个字节。_uncompressedblock持有iddumb问题-如果我正在通过
streamReadBlock
,我应该注意什么来监视流
record.rID的状态
?我在强制转换、引用和取消引用之间有点迷茫。我猜的是
static\u cast(*target)
,但它似乎没有给我退出函数时得到的值。record.rID不是通过引用传递的。在本上下文中,符号and表示“的地址”,它的地址被强制转换为一个char指针,而char指针又被值传递。哦,对了,很抱歉。不过,关于查看record.rID状态的问题仍然存在。。。