summaryrefslogtreecommitdiff
path: root/automotive/vehicle/aidl/impl/vhal/include/ParcelableUtils.h
diff options
context:
space:
mode:
Diffstat (limited to 'automotive/vehicle/aidl/impl/vhal/include/ParcelableUtils.h')
-rw-r--r--automotive/vehicle/aidl/impl/vhal/include/ParcelableUtils.h32
1 files changed, 12 insertions, 20 deletions
diff --git a/automotive/vehicle/aidl/impl/vhal/include/ParcelableUtils.h b/automotive/vehicle/aidl/impl/vhal/include/ParcelableUtils.h
index dcb15b9c63..4b7c2f3221 100644
--- a/automotive/vehicle/aidl/impl/vhal/include/ParcelableUtils.h
+++ b/automotive/vehicle/aidl/impl/vhal/include/ParcelableUtils.h
@@ -31,19 +31,18 @@ namespace vehicle {
template <class T1, class T2>
::ndk::ScopedAStatus vectorToStableLargeParcelable(std::vector<T1>&& values, T2* output) {
+ output->payloads = std::move(values);
auto result = ::android::automotive::car_binder_lib::LargeParcelableBase::
- parcelableVectorToStableLargeParcelable(values);
+ parcelableToStableLargeParcelable(*output);
if (!result.ok()) {
return toScopedAStatus(
result, ::aidl::android::hardware::automotive::vehicle::StatusCode::INTERNAL_ERROR);
}
auto& fd = result.value();
- if (fd == nullptr) {
- // If we no longer needs values, move it inside the payloads to avoid copying.
- output->payloads = std::move(values);
- } else {
+ if (fd != nullptr) {
// Move the returned ScopedFileDescriptor pointer to ScopedFileDescriptor value in
// 'sharedMemoryFd' field.
+ output->payloads.clear();
output->sharedMemoryFd = std::move(*fd);
}
return ::ndk::ScopedAStatus::ok();
@@ -57,12 +56,13 @@ template <class T1, class T2>
return vectorToStableLargeParcelable(std::move(valuesCopy), output);
}
-template <class T1, class T2>
-::android::base::expected<std::vector<T1>, ::ndk::ScopedAStatus> stableLargeParcelableToVector(
- const T2& largeParcelable) {
- ::android::base::Result<std::optional<std::vector<T1>>> result =
- ::android::automotive::car_binder_lib::LargeParcelableBase::
- stableLargeParcelableToParcelableVector<T1>(largeParcelable.sharedMemoryFd);
+template <class T>
+::android::base::expected<
+ ::android::automotive::car_binder_lib::LargeParcelableBase::BorrowedOwnedObject<T>,
+ ::ndk::ScopedAStatus>
+fromStableLargeParcelable(const T& largeParcelable) {
+ auto result = ::android::automotive::car_binder_lib::LargeParcelableBase::
+ stableLargeParcelableToParcelable(largeParcelable);
if (!result.ok()) {
return ::android::base::unexpected(toScopedAStatus(
@@ -70,15 +70,7 @@ template <class T1, class T2>
"failed to parse large parcelable"));
}
- if (!result.value().has_value()) {
- return ::android::base::unexpected(
- ::ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage(
- toInt(::aidl::android::hardware::automotive::vehicle::StatusCode::
- INVALID_ARG),
- "empty request"));
- }
-
- return std::move(result.value().value());
+ return std::move(result.value());
}
} // namespace vehicle