Xml.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2005-2007 by Peter Dimov.
00004 
00005 This file is part of Calitko (http://www.calitko.org).
00006 
00007 Calitko is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2 of the License, or
00010 (at your option) any later version.
00011 
00012 Calitko is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Calitko; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 */
00022 
00023 #include "Qt.h"
00024 #include "Xml.h"
00025 #include "ExtensionBlock.h"
00026 
00027 using namespace Gnutella::Packets::Extensions;
00028 
00029 Xml::Xml()
00030 {
00031 }
00032 
00033 Xml * Xml::copy() const
00034 {
00035     return new Xml (*this);
00036 }
00037 
00038 Xml::~Xml()
00039 {
00040 }
00041 
00042 int Xml::prepareRead (const QByteArray &rawData)
00043 {
00044     // We read all data until ExtensionSeparator is reached or all data is read.
00045     int endPos = rawData.indexOf (ExtensionBlock::ExtensionSeparator);
00046     if (endPos == -1)
00047         endPos = rawData.length();
00048 
00049     rawData_.resize (endPos);
00050     return endPos;
00051 }
00052 
00053 void Xml::read (QDataStream &stream)
00054 {
00055     stream.readRawData (rawData_.data(), rawData_.size());
00056     xmlMetadata_ = QString::fromUtf8(rawData_.data(), rawData_.size());
00057     rawData_ = QByteArray();
00058 }
00059 
00060 int Xml::prepareWrite() const
00061 {
00062     rawData_ = xmlMetadata_.toUtf8();
00063     return rawData_.length();
00064 }
00065 
00066 void Xml::write (QDataStream &stream) const
00067 {
00068     stream.writeRawData (rawData_.data(), rawData_.length());
00069 }