Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c5a8f965 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Parcel: add "optional" variant of writeParcelableVector" am: 99263858

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1504491

Change-Id: Ib5aac51666e6bd127972c1178d2aa82605bcc0cb
parents 00119bd1 99263858
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -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));