diff options
-rw-r--r-- | lib/common/Archive.h | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/common/Archive.h b/lib/common/Archive.h index f2e5bd83..6d5ce88b 100644 --- a/lib/common/Archive.h +++ b/lib/common/Archive.h @@ -81,7 +81,7 @@ public: int privItem; Read(privItem); - if (privItem) + if(privItem) { rItemOut = true; } @@ -90,6 +90,12 @@ public: rItemOut = false; } } + void ReadIfPresent(bool &rItemOut, bool ValueIfNotPresent) + { + int privItem; + ReadIfPresent(privItem, ValueIfNotPresent ? 1 : 0); + rItemOut = privItem ? true : false; + } void ReadExact(uint32_t &rItemOut) { Read((int&)rItemOut); } void Read(int &rItemOut) { @@ -100,6 +106,25 @@ public: } rItemOut = ntohl(privItem); } + void ReadIfPresent(int &rItemOut, int ValueIfNotPresent) + { + int32_t privItem; + int bytesRead; + if(mrStream.ReadFullBuffer(&privItem, sizeof(privItem), &bytesRead)) + { + rItemOut = ntohl(privItem); + } + else if(bytesRead == 0) + { + // item is simply not present + rItemOut = ValueIfNotPresent; + } + else + { + // bad number of remaining bytes + THROW_EXCEPTION(CommonException, ArchiveBlockIncompleteRead) + } + } void Read(int64_t &rItemOut) { int64_t privItem; |