Exemple #1
0
int HexDoc::GetSerializedLength(THSIZE nOffset, THSIZE nSize)
{
    int sSize = sizeof(SerialDataHeader);

    std::vector<DataSource*> sources;
    std::vector<DataSource*>::const_iterator iter;

    THSIZE segStart;
    Segment *ts = GetSegment(nOffset, &segStart);
    THSIZE segOffset = nOffset - segStart;
    while (ts != NULL && segStart < nOffset + nSize)
    {
        int nSource = 0;
        if (ts->pDS)
        {
            iter = std::find(sources.begin(), sources.end(), ts->pDS);
            if (iter == sources.end())
            {
                sources.push_back(ts->pDS);
                sSize += ts->pDS->GetSerializedLength();
            }
        }
        THSIZE copySize = min(nSize, ts->size - segOffset);
        sSize += ts->GetSerializedLength(segOffset, copySize);
        segStart += ts->size;
        segOffset = 0;
        ts = ts->next;
    }
    return sSize;
}
Exemple #2
0
void HexDoc::Serialize(THSIZE nOffset, THSIZE nSize, uint8 *target)
{
    SerialDataHeader &hdr = *(SerialDataHeader*)target;
    int sOffset = sizeof(hdr);
    hdr.endianMode = NATIVE_ENDIAN_MODE;
    hdr.nSegments = 0;
    hdr.nSources = 0;

    std::vector<DataSource*> sources;
    std::vector<DataSource*>::const_iterator iter;

    THSIZE segStart;
    Segment *ts = GetSegment(nOffset, &segStart);
    THSIZE segOffset = nOffset - segStart;
    while (ts != NULL && segStart < nOffset + nSize)
    {
        hdr.nSegments++;
        int nSource = 0;
        if (ts->pDS)
        {
            iter = std::find(sources.begin(), sources.end(), ts->pDS);
            if (iter == sources.end())
            {
                sources.push_back(ts->pDS);
                hdr.nSources++;
            }
        }
        THSIZE copySize = min(nOffset + nSize, segStart + ts->size) - (segStart + segOffset);
        int sSize = ts->GetSerializedLength(segOffset, copySize);
        ts->Serialize(segOffset, copySize, nSource, target + sOffset);
        sOffset += sSize;
        segStart += ts->size;
        segOffset = 0;
        ts = ts->next;
    }

    for (iter = sources.begin(); iter < sources.end(); iter++)
    {
        DataSource *pDS = *iter;
        int sSize = pDS->GetSerializedLength();
        pDS->Serialize(target + sOffset);
        sOffset += sSize;
    }
}