From 702e018ca9e780bb076033ce5d1d370d4eb7319e Mon Sep 17 00:00:00 2001 From: Javier Date: Mon, 14 Dec 2015 01:52:17 +0100 Subject: properly handle data frames with sequence numbers --- saprotocol.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'saprotocol.cc') diff --git a/saprotocol.cc b/saprotocol.cc index 9f25613..22b3111 100644 --- a/saprotocol.cc +++ b/saprotocol.cc @@ -229,6 +229,30 @@ QByteArray SAProtocol::packFrame(quint16 sessionId, const QByteArray &data) return packFrame(frame); } +SAProtocol::DataFrame SAProtocol::unpackDataFrame(const QByteArray &data, bool withSeqNum) +{ + DataFrame frame; + int offset = 0; + frame.withSeqNum = withSeqNum; + if (withSeqNum) { + frame.seqNum = read(data, offset); + frame.unk_1 = read(data, offset); + } + frame.data = data.mid(offset); + return frame; +} + +QByteArray SAProtocol::packDataFrame(const DataFrame &frame) +{ + QByteArray data; + if (frame.withSeqNum) { + append(data, frame.seqNum); + append(data, frame.unk_1); + } + data.append(frame.data); + return data; +} + SAProtocol::ServiceConnectionRequestFrame SAProtocol::unpackServiceConnectionRequestFrame(const QByteArray &data) { ServiceConnectionRequestFrame frame; -- cgit v1.2.3