PIByteArray getRange

This commit is contained in:
Andrey
2021-11-16 15:22:03 +03:00
parent 04d7ed77d9
commit 92b20f6f46
2 changed files with 11 additions and 0 deletions

View File

@@ -85,6 +85,8 @@ public:
PIByteArray(const PIByteArray & o): PIDeque<uchar>(o) {}
PIByteArray(const PIDeque<uchar> & o): PIDeque<uchar>(o) {}
PIByteArray(PIByteArray && o): PIDeque<uchar>(std::move(o)) {}
//! Constructs 0-filled byte array with size "size"
@@ -116,6 +118,12 @@ public:
//! Return resized byte array
PIByteArray resized(uint new_size) const {PIByteArray ret(new_size); memcpy(ret.data(), data(), new_size); return ret;}
//! Return sub-array starts from "index" and has "count" or less bytes
PIByteArray getRange(size_t index, size_t count) const {
return PIDeque<uchar>::getRange(index, count);
}
//! Convert data to Base 64 and return this byte array
PIByteArray & convertToBase64();

View File

@@ -22,6 +22,9 @@ int main(int argc, char * argv[]) {
t3.stop();
piMSleep(100);
piCout << "exit" << cnt1 << cnt2 << cnt3;
PIByteArray ba = PIByteArray::fromHex("00aabbcc");
PIByteArray ba2 = ba.getRange(1, 2);
piCout << ba2.toHex();
// m.unlock();
// piMSleep(10);
return 0;