#define GET_CSTRING(CLASS_NAME, FUNC_NAME, ELEMENT_NAME) \
const char* CLASS_NAME::FUNC_NAME() const { \
- return GetCString(index_.ELEMENT_NAME); \
+ return GetCString(index_->ELEMENT_NAME); \
}
#define GET_LIST_ITERATOR(TYPE, FUNC_NAME, CLASS_NAME, ELEMENT_NAME) \
Iterable<TYPE> CLASS_NAME::FUNC_NAME() const { \
- int index = index_.ELEMENT_NAME; \
+ int index = index_->ELEMENT_NAME; \
if (index < 0) \
return Iterable<TYPE>(parcel_, -1); \
return Iterable<TYPE>(parcel_, index); \
return true;
}
+uint8_t* SerializedBase::GetRaw() const {
+ return parcel_->GetData();
+}
+
+size_t SerializedBase::GetRawSize() const {
+ return parcel_->GetDataSize();
+}
+
GET_CSTRING(Label, Name, name)
GET_CSTRING(Label, Text, text)
GET_CSTRING(Label, Lang, lang)
}
PkgInfoHandle::PkgInfoHandle(std::unique_ptr<tizen_base::Parcel> parcel)
- : Serialized<PkgInfoIndex>(parcel.get(), parcel->GetDataSize() - sizeof(index_)),
+ : Serialized<PkgInfoIndex>(parcel.get(), parcel->GetDataSize() - sizeof(*index_)),
base_parcel_(std::move(parcel)) {}
PkgInfoHandle& PkgInfoHandle::operator=(PkgInfoHandle&& h) noexcept {
}
AppInfoHandle::AppInfoHandle(std::unique_ptr<tizen_base::Parcel> parcel)
- : Serialized<AppInfoIndex>(parcel.get(), parcel->GetDataSize() - sizeof(index_)),
+ : Serialized<AppInfoIndex>(parcel.get(), parcel->GetDataSize() - sizeof(*index_)),
base_parcel_(std::move(parcel)) {}
AppInfoHandle& AppInfoHandle::operator=(AppInfoHandle&& h) noexcept {
const char* GetCString(int index) const;
bool GetInt(int index, int* result) const;
bool GetBuf(int index, void* buf, uint32_t size) const;
+ uint8_t* GetRaw() const;
+ size_t GetRawSize() const;
protected:
const tizen_base::Parcel* parcel_;
template<typename T>
class EXPORT_API Serialized : public SerializedBase {
public:
- Serialized(const tizen_base::Parcel* parcel, int data_index) : SerializedBase(parcel) {
- if (data_index < 0) {
- memset(&index_, -1, sizeof(index_));
+ Serialized(const tizen_base::Parcel* parcel, int data_index) : SerializedBase(parcel), index_(nullptr) {
+ if (size_t(data_index + sizeof(T)) > GetRawSize())
+ return;
+
+ if (data_index < 0)
return;
- }
- if (!GetBuf(data_index, &index_, sizeof(index_)))
- memset(&index_, -1, sizeof(index_));
+ index_ = (T*)(GetRaw() + data_index);
}
Serialized(const Serialized& h) = delete;
if (this != &h) {
SerializedBase::operator=(std::move(h));
index_ = h.index_;
- memset(&h.index_, -1, sizeof(h.index_));
+ h.index_ = nullptr;
}
return *this;
}
protected:
- T index_;
+ T* index_;
};
template<typename T>