summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2020-11-19 12:53:17 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2020-11-19 12:53:17 +0000
commitbb6dce783eb5e860060113aca082887a09d80919 (patch)
tree1e4b96b98471d7cca4b3665d5992ca79c664f4a7
parentf895b7e005f16f6724d479ecad47ee4f5fb860f2 (diff)
parentaa1e200e1b4b16496e54456af70c705e4c1bcbad (diff)
Merge "Parcel: add "optional" variant of writeParcelableVector" am: 9926385827 am: c5a8f9657c am: aa1e200e1b
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1504491 Change-Id: Ieb74cb2bfffd31efd09d9876cb5e6e398e473356
-rw-r--r--libs/binder/include/binder/Parcel.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/libs/binder/include/binder/Parcel.h b/libs/binder/include/binder/Parcel.h
index ece25a0730..4b2d50df86 100644
--- a/libs/binder/include/binder/Parcel.h
+++ b/libs/binder/include/binder/Parcel.h
@@ -210,6 +210,8 @@ public:
template<typename T>
status_t writeParcelableVector(const std::shared_ptr<std::vector<std::unique_ptr<T>>>& val);
template<typename T>
+ status_t writeParcelableVector(const std::shared_ptr<std::vector<std::optional<T>>>& val);
+ template<typename T>
status_t writeParcelableVector(const std::vector<T>& val);
template<typename T>
@@ -1229,6 +1231,16 @@ status_t Parcel::writeParcelableVector(const std::shared_ptr<std::vector<std::un
return unsafeWriteTypedVector<NullableT, const NullableT&>(*val, &Parcel::writeNullableParcelable);
}
+template<typename T>
+status_t Parcel::writeParcelableVector(const std::shared_ptr<std::vector<std::optional<T>>>& val) {
+ if (val.get() == nullptr) {
+ return this->writeInt32(-1);
+ }
+
+ using NullableT = std::optional<T>;
+ return unsafeWriteTypedVector<NullableT, const NullableT&>(*val, &Parcel::writeNullableParcelable);
+}
+
template<typename T, std::enable_if_t<std::is_same_v<typename std::underlying_type_t<T>,int32_t>, bool>>
status_t Parcel::writeEnum(const T& val) {
return writeInt32(static_cast<int32_t>(val));