blob: ec0189901d9f7a91df3894428ea2f7c4fdb62a6f [file] [log] [blame]
#pragma once
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include <android/binder_interface_utils.h>
#include <android/binder_parcelable_utils.h>
#include <android/binder_to_string.h>
#ifdef BINDER_STABILITY_SUPPORT
#include <android/binder_stability.h>
#endif // BINDER_STABILITY_SUPPORT
namespace aidl {
namespace android {
namespace aidl {
namespace tests {
template <typename T, typename U, typename B>
class GenericStructuredParcelable {
public:
typedef std::false_type fixed_size;
static const char* descriptor;
int32_t a = 0;
int32_t b = 0;
binder_status_t readFromParcel(const AParcel* parcel);
binder_status_t writeToParcel(AParcel* parcel) const;
inline bool operator!=(const GenericStructuredParcelable& rhs) const {
return std::tie(a, b) != std::tie(rhs.a, rhs.b);
}
inline bool operator<(const GenericStructuredParcelable& rhs) const {
return std::tie(a, b) < std::tie(rhs.a, rhs.b);
}
inline bool operator<=(const GenericStructuredParcelable& rhs) const {
return std::tie(a, b) <= std::tie(rhs.a, rhs.b);
}
inline bool operator==(const GenericStructuredParcelable& rhs) const {
return std::tie(a, b) == std::tie(rhs.a, rhs.b);
}
inline bool operator>(const GenericStructuredParcelable& rhs) const {
return std::tie(a, b) > std::tie(rhs.a, rhs.b);
}
inline bool operator>=(const GenericStructuredParcelable& rhs) const {
return std::tie(a, b) >= std::tie(rhs.a, rhs.b);
}
static const ::ndk::parcelable_stability_t _aidl_stability = ::ndk::STABILITY_LOCAL;
inline std::string toString() const {
std::ostringstream os;
os << "GenericStructuredParcelable{";
os << "a: " << ::android::internal::ToString(a);
os << ", b: " << ::android::internal::ToString(b);
os << "}";
return os.str();
}
};
} // namespace tests
} // namespace aidl
} // namespace android
} // namespace aidl
#include "aidl/android/aidl/tests/GenericStructuredParcelable.h"
#include <android/binder_parcel_utils.h>
namespace aidl {
namespace android {
namespace aidl {
namespace tests {
template <typename T, typename U, typename B>
const char* GenericStructuredParcelable<T, U, B>::descriptor = "android.aidl.tests.GenericStructuredParcelable";
template <typename T, typename U, typename B>
binder_status_t GenericStructuredParcelable<T, U, B>::readFromParcel(const AParcel* _aidl_parcel) {
binder_status_t _aidl_ret_status = STATUS_OK;
int32_t _aidl_start_pos = AParcel_getDataPosition(_aidl_parcel);
int32_t _aidl_parcelable_size = 0;
_aidl_ret_status = AParcel_readInt32(_aidl_parcel, &_aidl_parcelable_size);
if (_aidl_ret_status != STATUS_OK) return _aidl_ret_status;
if (_aidl_parcelable_size < 4) return STATUS_BAD_VALUE;
if (_aidl_start_pos > INT32_MAX - _aidl_parcelable_size) return STATUS_BAD_VALUE;
if (AParcel_getDataPosition(_aidl_parcel) - _aidl_start_pos >= _aidl_parcelable_size) {
AParcel_setDataPosition(_aidl_parcel, _aidl_start_pos + _aidl_parcelable_size);
return _aidl_ret_status;
}
_aidl_ret_status = ::ndk::AParcel_readData(_aidl_parcel, &a);
if (_aidl_ret_status != STATUS_OK) return _aidl_ret_status;
if (AParcel_getDataPosition(_aidl_parcel) - _aidl_start_pos >= _aidl_parcelable_size) {
AParcel_setDataPosition(_aidl_parcel, _aidl_start_pos + _aidl_parcelable_size);
return _aidl_ret_status;
}
_aidl_ret_status = ::ndk::AParcel_readData(_aidl_parcel, &b);
if (_aidl_ret_status != STATUS_OK) return _aidl_ret_status;
AParcel_setDataPosition(_aidl_parcel, _aidl_start_pos + _aidl_parcelable_size);
return _aidl_ret_status;
}
template <typename T, typename U, typename B>
binder_status_t GenericStructuredParcelable<T, U, B>::writeToParcel(AParcel* _aidl_parcel) const {
binder_status_t _aidl_ret_status;
size_t _aidl_start_pos = AParcel_getDataPosition(_aidl_parcel);
_aidl_ret_status = AParcel_writeInt32(_aidl_parcel, 0);
if (_aidl_ret_status != STATUS_OK) return _aidl_ret_status;
_aidl_ret_status = ::ndk::AParcel_writeData(_aidl_parcel, a);
if (_aidl_ret_status != STATUS_OK) return _aidl_ret_status;
_aidl_ret_status = ::ndk::AParcel_writeData(_aidl_parcel, b);
if (_aidl_ret_status != STATUS_OK) return _aidl_ret_status;
size_t _aidl_end_pos = AParcel_getDataPosition(_aidl_parcel);
AParcel_setDataPosition(_aidl_parcel, _aidl_start_pos);
AParcel_writeInt32(_aidl_parcel, _aidl_end_pos - _aidl_start_pos);
AParcel_setDataPosition(_aidl_parcel, _aidl_end_pos);
return _aidl_ret_status;
}
} // namespace tests
} // namespace aidl
} // namespace android
} // namespace aidl