📄 tpdu.cpp
字号:
/*************************************************************************** tpdu.cpp - description ------------------- begin : Wed Feb 14 2001 copyright : (C) 2001 by Matthias Welwarsky email : matze@stud.fbi.fh-darmstadt.de ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#include <kdebug.h>#include "tpdu.h"const QString TPDU::hexDigit = "0123456789ABCDEF"; TPDU::TPDU(){}TPDU::~TPDU(){}/** converts the PDU from it's internal format into a QString * containing a PDU in hexadecimal representation. */QString TPDU::toQString() const { QString result; for (unsigned int index=0; index < pduData.size(); ++index) { unsigned char byte = pduData[index]; result += hexDigit[byte / 16]; result += hexDigit[byte & 15]; } return result;}/** assigns a QString containing a PDU in hexadecimal * representations to the TPDU object */TPDU& TPDU::operator=(const QString& pdu) { pduData.resize(pdu.length()/2); bool hiNibble = true; int pduIndex = 0; unsigned char byte; for (unsigned int index = 0; index < pdu.length(); ++index) { if (hiNibble) { byte = hexDigit.find(pdu[index])*16; hiNibble = false; } else { byte += hexDigit.find(pdu[index]); pduData[pduIndex++] = byte; hiNibble = true; } } return *this;}/** No descriptions */TPDU::TPDU(const QString& pdu) { *this = pdu;}/** converts a list of TPDUs to a QByteArray */QByteArray TPDU::toByteArray(const TPDU::List& pduList) { int size = 0; if (pduList.isEmpty()) return QByteArray(); QListIterator<TPDU> it(pduList); for (; it.current(); ++it) { size += (*it)->size(); } int bitmapPos = 0; QByteArray data(size); for (it = pduList; it.current(); ++it) { for (int index = 0; index < (*it)->size(); index++) data[bitmapPos++] = (**it)[index]; } return data;}/** returns the size of the stored PDU */int TPDU::size() const{ return pduData.size();}/** No descriptions */char& TPDU::operator[](int pos) const { return pduData[pos];}/** splits a QByteArray into a list of TPDUs with a given maximum size. */TPDU::List TPDU::split(const QByteArray& data, int maxSize) { TPDU::List result; int size = data.size(); const char* rawData = (const char*)data; while (size > 0) { int copy = (size > maxSize)? maxSize:size; QByteArray ba(copy); ba.assign(rawData, copy); result.append(new TPDU(ba)); size -= copy; rawData += copy; } return result;}/** constructs a TPDU from a QByteArray */TPDU::TPDU(const QByteArray& data){ pduData = data;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -