Files
pilotclient/src/plugins/simulator/fs9/multiplayerpacketparser.cpp
Roland Winklmeier a13f7eb1d4 [FS9] Add missing null termination when serializing QStrings
The produced QByteArray was missing the null terminating character,
since QByteArray::append() only added up to and not including '\0'.
This was also the reason why sometimes planes did not change their
aircraft models properly.
2016-12-06 09:46:44 +01:00

39 lines
1.3 KiB
C++

/* Copyright (C) 2014
* swift project community / contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "multiplayerpacketparser.h"
namespace BlackSimPlugin
{
namespace Fs9
{
namespace Private
{
QByteArray readValue(const QByteArray &data, QString &val)
{
val = QString(data);
// Up to know all packets with string data, had the string payload at the end
// of the packet. Therefore there should not be any data after the string.
// Remove the assert, if this will change in the future.
QByteArray leftOver = data.mid(val.size() + 1);
Q_ASSERT(leftOver.isEmpty());
return leftOver;
}
QByteArray writeValue(QByteArray data, const QString &value)
{
data.append(qPrintable(value), value.size() + 1);
return data;
}
}
}
}