From 92b20f6f46fd88e131e3b6bfaae679852b4f2c32 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 16 Nov 2021 15:22:03 +0300 Subject: [PATCH] PIByteArray getRange --- libs/main/core/pibytearray.h | 8 ++++++++ main.cpp | 3 +++ 2 files changed, 11 insertions(+) diff --git a/libs/main/core/pibytearray.h b/libs/main/core/pibytearray.h index d47740c8..721d7030 100644 --- a/libs/main/core/pibytearray.h +++ b/libs/main/core/pibytearray.h @@ -85,6 +85,8 @@ public: PIByteArray(const PIByteArray & o): PIDeque(o) {} + PIByteArray(const PIDeque & o): PIDeque(o) {} + PIByteArray(PIByteArray && o): PIDeque(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::getRange(index, count); + } + + //! Convert data to Base 64 and return this byte array PIByteArray & convertToBase64(); diff --git a/main.cpp b/main.cpp index 6c91d54f..a94d025f 100644 --- a/main.cpp +++ b/main.cpp @@ -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;