MsgPackStream work (now working now)

This commit is contained in:
Roman
2015-05-15 22:49:39 +03:00
parent 1ae96715cf
commit 87bd3dedb1
3 changed files with 106 additions and 69 deletions
+46 -6
View File
@@ -1,5 +1,8 @@
#include "stream.h"
#include <QBuffer>
#include "private/sysdep.h"
#include "msgpack_common.h"
#include <QDebug>
#undef CHECK_STREAM_PRECOND
#ifndef QT_NO_DEBUG
@@ -84,15 +87,52 @@ void MsgPackStream::setStatus(Status status)
q_status = status;
}
MsgPackStream &MsgPackStream::operator >>(quint8 &u8)
MsgPackStream &MsgPackStream::operator>>(bool &b)
{
u8 = 0;
CHECK_STREAM_PRECOND(*this)
char c;
if (!dev->getChar(&c))
quint8 p[1];
if (!dev->getChar((char *)p)) {
b = false;
setStatus(ReadPastEnd);
else
u8 = quint8(c);
} else {
if (p[0] != MsgPack::FirstByte::TRUE ||
p[0] != MsgPack::FirstByte::FALSE)
setStatus(ReadCorruptData);
b = (p[0] == MsgPack::FirstByte::TRUE);
}
return *this;
}
MsgPackStream &MsgPackStream::operator >>(quint8 &u8)
{
CHECK_STREAM_PRECOND(*this)
char c;
if (!dev->getChar(&c)) {
u8 = 0;
setStatus(ReadPastEnd);
} else {
u8 = quint8(c);
}
return *this;
}
MsgPackStream &MsgPackStream::operator>>(quint16 &u16)
{
CHECK_STREAM_PRECOND(*this);
quint8 p[3];
if (dev->read((char *)p, 3) != 3) {
u16 = 0;
setStatus(ReadPastEnd);
} else {
if (p[0] != MsgPack::FirstByte::UINT16)
setStatus(ReadCorruptData);
u16 = _msgpack_load16(quint16, (p + 1));
}
return *this;
}
MsgPackStream &MsgPackStream::operator>>(quint32 &u32)
{
}