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 static const uint8 fVersion = 2; 38 }; 39 40 41 inline 42 PackageData::PackageData(const PackageDataV2& data) 43 #if 0 44 : 45 fVersion(2) 46 #endif 47 { 48 memcpy(&fData, &data, sizeof(data)); 49 } 50 51 52 inline const PackageDataV2& 53 PackageData::DataV2() const 54 { 55 return *(PackageDataV2*)&fData; 56 } 57 58 59 inline uint64 60 PackageData::UncompressedSize() const 61 { 62 return DataV2().Size(); 63 } 64 65 66 inline bool 67 PackageData::IsEncodedInline() const 68 { 69 return DataV2().IsEncodedInline(); 70 } 71 72 73 inline const uint8* 74 PackageData::InlineData() const 75 { 76 return DataV2().InlineData(); 77 } 78 79 80 #endif // PACKAGE_DATA_H 81