PIIODevice::bytesAvailible()
fix pistringlist pibinarystream write pibinarystream::binaryStreamSize() PIByteArray pibinarystream read with more size fix pistring pibinarystream read optimization fix bug in PIIOBinaryStream read and write if failed workaround in PIIOString::readDevice PISPI readDevice bug Fixed
This commit is contained in:
@@ -51,8 +51,9 @@ class PIBinaryStream {
|
||||
public:
|
||||
// one should implement next methods:
|
||||
//
|
||||
// bool binaryStreamAppendImp(const void * d, size_t s);
|
||||
// bool binaryStreamTakeImp ( void * d, size_t s);
|
||||
// bool binaryStreamAppendImp (const void * d, size_t s);
|
||||
// bool binaryStreamTakeImp (void * d, size_t s);
|
||||
// ssize_t binaryStreamSizeImp () const;
|
||||
|
||||
bool binaryStreamAppend(const void * d, size_t s) {
|
||||
if (!static_cast<P*>(this)->binaryStreamAppendImp(d, s)) {
|
||||
@@ -68,24 +69,16 @@ public:
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ssize_t binaryStreamSize() const {
|
||||
return static_cast<P*>(this)->binaryStreamSizeImp();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void binaryStreamAppend(T v) {binaryStreamAppend(&v, sizeof(v));}
|
||||
uchar binaryStreamTakeByte(bool * ok = nullptr) {
|
||||
uchar r = 0;
|
||||
if (binaryStreamTake(&r, sizeof(r))) {
|
||||
if (ok) *ok = true;
|
||||
} else {
|
||||
if (ok) *ok = false;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
int binaryStreamTakeInt(bool * ok = nullptr) {
|
||||
int binaryStreamTakeInt() {
|
||||
int r = 0;
|
||||
if (binaryStreamTake(&r, sizeof(r))) {
|
||||
if (ok) *ok = true;
|
||||
} else {
|
||||
if (ok) *ok = false;
|
||||
}
|
||||
binaryStreamTake(&r, sizeof(r));
|
||||
return r;
|
||||
}
|
||||
};
|
||||
@@ -100,13 +93,27 @@ public:
|
||||
};
|
||||
|
||||
|
||||
template<typename P, typename T> inline PIBinaryStream<P> & operator <<(PIBinaryStreamTrivialRef<P> s, const T & v) {s.p << v; return s.p;}
|
||||
template<typename P, typename T> inline PIBinaryStream<P> & operator >>(PIBinaryStreamTrivialRef<P> s, T & v) {s.p >> v; return s.p;}
|
||||
template<typename P, typename T> inline PIBinaryStream<P> & operator <<(PIBinaryStreamTrivialRef<P> s, const T & v) {
|
||||
s.p << v;
|
||||
return s.p;
|
||||
}
|
||||
template<typename P, typename T> inline PIBinaryStream<P> & operator >>(PIBinaryStreamTrivialRef<P> s, T & v) {
|
||||
s.p >> v;
|
||||
return s.p;
|
||||
}
|
||||
|
||||
|
||||
// specify types
|
||||
template<typename P> inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const bool v) {s.binaryStreamAppend((uchar)v); return s;}
|
||||
template<typename P> inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, bool & v) {v = s.binaryStreamTakeByte(); return s;}
|
||||
template<typename P> inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const bool v) {
|
||||
s.binaryStreamAppend((uchar)v);
|
||||
return s;
|
||||
}
|
||||
template<typename P> inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, bool & v) {
|
||||
uchar c;
|
||||
s.binaryStreamTake(&c, sizeof(c));
|
||||
v = c;
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename P> inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIMemoryBlock v) {
|
||||
s.binaryStreamAppend(v.data(), v.size());
|
||||
|
||||
@@ -1136,13 +1136,15 @@ public:
|
||||
return true;
|
||||
}
|
||||
bool binaryStreamTakeImp(void * d_, size_t s) {
|
||||
if (size() < s)
|
||||
return false;
|
||||
memcpy(d_, data(), s);
|
||||
remove(0, s);
|
||||
return true;
|
||||
size_t rs = size();
|
||||
if (rs > s) rs = s;
|
||||
memcpy(d_, data(), rs);
|
||||
remove(0, rs);
|
||||
return rs == s;
|
||||
}
|
||||
|
||||
ssize_t binaryStreamSizeImp() const {return size();}
|
||||
|
||||
private:
|
||||
PIDeque<uchar> d;
|
||||
|
||||
|
||||
@@ -1511,7 +1511,7 @@ BINARY_STREAM_WRITE(PIString) {s << v.d; return s;}
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Restore operator.
|
||||
//! \~russian Оператор извлечения.
|
||||
BINARY_STREAM_READ(PIString) {v.d.clear(); s >> v.d; return s;}
|
||||
BINARY_STREAM_READ(PIString) {s >> v.d; return s;}
|
||||
|
||||
|
||||
//! \~english Returns concatenated string.
|
||||
|
||||
@@ -127,15 +127,11 @@ public:
|
||||
|
||||
|
||||
BINARY_STREAM_WRITE(PIStringList) {
|
||||
s.binaryStreamAppend(v.size());
|
||||
for (int i = 0; i < v.size_s(); ++i)
|
||||
s << v[i];
|
||||
s << static_cast<const PIDeque<PIString> &>(v);
|
||||
return s;
|
||||
}
|
||||
BINARY_STREAM_READ(PIStringList) {
|
||||
v.resize(s.binaryStreamTakeInt());
|
||||
for (int i = 0; i < v.size_s(); ++i)
|
||||
s >> v[i];
|
||||
s >> static_cast<PIDeque<PIString> &>(v);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -147,8 +147,8 @@ public:
|
||||
//! \~english Read character
|
||||
//! \~russian Читает символ
|
||||
char takeChar(bool * rok) {
|
||||
bool ok = true;
|
||||
char ret = (char)s->binaryStreamTakeByte(&ok);
|
||||
char ret;
|
||||
bool ok = s->binaryStreamTake(&ret, sizeof(ret));
|
||||
if (!ok) is_end = true;
|
||||
if (rok) *rok = ok;
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user