summaryrefslogtreecommitdiff
path: root/shared/serialize.cpp
blob: f71207befa4111de864d8660d95aa8efa45062c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html       *
// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de)                    *
// **************************************************************************
//
#include "serialize.h"
#include <wx/intl.h>

using namespace util;


void ReadInputStream::throwReadError() const  //throw FileError()
{
    throw ffs3::FileError(wxString(_("Error reading from synchronization database:")) + wxT(" \n") +
                          wxT("\"") +  errorObjName_ + wxT("\""));
}


ReadInputStream::CharArray ReadInputStream::readArrayC() const
{
    const boost::uint32_t byteCount = readNumberC<boost::uint32_t>();
    CharArray buffer(new std::vector<char>(byteCount));
    if (byteCount > 0)
    {
        stream_.Read(&(*buffer)[0], byteCount);
        check();
        if (stream_.LastRead() != byteCount) //some additional check
            throwReadError();
    }
    return buffer;
}


//--------------------------------------------------------------------------------------------------------
void WriteOutputStream::throwWriteError() const //throw FileError()
{
    throw ffs3::FileError(wxString(_("Error writing to synchronization database:")) + wxT(" \n") +
                          wxT("\"") + errorObjName_ + wxT("\""));
}


void WriteOutputStream::writeArrayC(const std::vector<char>& buffer) const
{
    writeNumberC<boost::uint32_t>(static_cast<boost::uint32_t>(buffer.size()));
    if (buffer.size() > 0)
    {
        stream_.Write(&buffer[0], buffer.size());
        check();
        if (stream_.LastWrite() != buffer.size()) //some additional check
            throwWriteError();
    }
}
bgstack15