1 /* 2 * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef PACKAGE_DATA_H 6 #define PACKAGE_DATA_H 7 8 9 #include <package/hpkg/PackageData.h> 10 11 #include <string.h> 12 13 14 typedef BPackageKit::BHPKG::BPackageData PackageDataV2; 15 16 17 class PackageData { 18 public: 19 explicit PackageData(const PackageDataV2& data); 20 21 uint8 Version() const { return fVersion; } 22 const PackageDataV2& DataV2() const; 23 24 uint64 UncompressedSize() const; 25 26 bool IsEncodedInline() const; 27 const uint8* InlineData() const; 28 29 private: 30 static const size_t kDataSize = sizeof(PackageDataV2); 31 32 private: 33 union { 34 char fData[kDataSize]; 35 uint64 fAlignmentDummy; 36 }; 37 uint8 fVersion; 38 }; 39 40 41 inline 42 PackageData::PackageData(const PackageDataV2& data) 43 : 44 fVersion(2) 45 { 46 memcpy(&fData, &data, sizeof(data)); 47 } 48 49 50 inline const PackageDataV2& 51 PackageData::DataV2() const 52 { 53 return *(PackageDataV2*)&fData; 54 } 55 56 57 inline uint64 58 PackageData::UncompressedSize() const 59 { 60 return DataV2().Size(); 61 } 62 63 64 inline bool 65 PackageData::IsEncodedInline() const 66 { 67 return DataV2().IsEncodedInline(); 68 } 69 70 71 inline const uint8* 72 PackageData::InlineData() const 73 { 74 return DataV2().InlineData(); 75 } 76 77 78 #endif // PACKAGE_DATA_H 79