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:
Бычков Андрей
2022-07-27 15:43:04 +03:00
parent d13e68c206
commit 3873f0b03b
50 changed files with 323 additions and 253 deletions

View File

@@ -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());