diff --git a/src/private/pack_p.cpp b/src/private/pack_p.cpp index 7fa5166..757327c 100644 --- a/src/private/pack_p.cpp +++ b/src/private/pack_p.cpp @@ -37,6 +37,8 @@ quint8 *MsgPackPrivate::pack(const QVariant &v, quint8 *p, bool wr, QVector &user_data); diff --git a/src/stream.cpp b/src/stream.cpp index 468d226..42baf83 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -204,6 +204,52 @@ MsgPackStream &MsgPackStream::operator>>(qint64 &i64) return *this; } +MsgPackStream &MsgPackStream::operator>>(float &f) +{ + CHECK_STREAM_PRECOND(*this); + quint8 *fp = (quint8 *)&f; + quint8 p[5]; + if (dev->read((char *)&p, 1) != 1) { + setStatus(ReadPastEnd); + return *this; + } + if (p[0] != MsgPack::FirstByte::FLOAT32) { + setStatus(ReadCorruptData); + return *this; + } +#ifdef __LITTLE_ENDIAN__ + for (int i = 0; i < 4; ++i) + *(fp + 3 - i) = *(p + i + 1); +#else + for (int i = 0; i < 4; ++i) + *(fp + i) = *(p + i + 1); +#endif + return *this; +} + +MsgPackStream &MsgPackStream::operator>>(double &d) +{ + CHECK_STREAM_PRECOND(*this); + quint8 *fp = (quint8 *)&f; + quint8 p[9]; + if (dev->read((char *)&p, 1) != 1) { + setStatus(ReadPastEnd); + return *this; + } + if (p[0] != MsgPack::FirstByte::FLOAT64) { + setStatus(ReadCorruptData); + return *this; + } +#ifdef __LITTLE_ENDIAN__ + for (int i = 0; i < 8; ++i) + *(fp + 7 - i) = *(p + i + 1); +#else + for (int i = 0; i < 8; ++i) + *(fp + i) = *(p + i + 1); +#endif + return *this; +} + MsgPackStream &MsgPackStream::operator>>(QString &str) { CHECK_STREAM_PRECOND(*this); @@ -239,6 +285,21 @@ MsgPackStream &MsgPackStream::operator>>(QString &str) delete[] data; } +MsgPackStream &MsgPackStream::operator>>(QByteArray &array) +{ + +} + +MsgPackStream &MsgPackStream::operator>>(QVariantList &list) +{ + +} + +MsgPackStream &MsgPackStream::operator>>(QVariantMap &map) +{ + +} + MsgPackStream &MsgPackStream::operator<<(bool b) { CHECK_STREAM_WRITE_PRECOND(*this); @@ -289,6 +350,26 @@ MsgPackStream &MsgPackStream::operator<<(qint64 i64) return *this; } +MsgPackStream &MsgPackStream::operator<<(float f) +{ + CHECK_STREAM_WRITE_PRECOND(*this); + quint8 p[5]; + quint8 sz = MsgPackPrivate::pack_float(f, p, true) - p; + if (dev->write((char *)p, sz) != sz) + setStatus(WriteFailed); + return *this; +} + +MsgPackStream &MsgPackStream::operator<<(double d) +{ + CHECK_STREAM_WRITE_PRECOND(*this); + quint8 p[9]; + quint8 sz = MsgPackPrivate::pack_float(d, p, true) - p; + if (dev->write((char *)p, sz) != sz) + setStatus(WriteFailed); + return *this; +} + MsgPackStream &MsgPackStream::operator<<(QString str) { CHECK_STREAM_WRITE_PRECOND(*this); @@ -316,6 +397,21 @@ MsgPackStream &MsgPackStream::operator<<(const char *str) return *this; } +MsgPackStream &MsgPackStream::operator<<(QByteArray array) +{ + +} + +MsgPackStream &MsgPackStream::operator<<(QVariantList list) +{ + +} + +MsgPackStream &MsgPackStream::operator<<(QVariantMap map) +{ + +} + bool MsgPackStream::unpack_upto_quint8(quint8 &u8, quint8 *p) { if (*p <= MsgPack::FirstByte::POSITIVE_FIXINT) {