swift
multiplayerpacketparser.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2014 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
4 
5 namespace swift::simplugin::fs9::private_ns
6 {
7  QByteArray readValue(const QByteArray &data, QString &val)
8  {
9  val = QString(data);
10 
11  // Up to know all packets with string data, had the string payload at the end
12  // of the packet. Therefore there should not be any data after the string.
13  // Remove the assert, if this will change in the future.
14  QByteArray leftOver = data.mid(val.size() + 1);
15  Q_ASSERT(leftOver.isEmpty());
16 
17  return leftOver;
18  }
19 
20  QByteArray writeValue(QByteArray data, const QString &value)
21  {
22  data.append(qPrintable(value), value.size() + 1);
23  return data;
24  }
25 } // namespace swift::simplugin::fs9::private_ns