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

Commit f4169dd8 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "libbinder_ndk: support for nullable parcelables" am: 56ef5878 am:...

Merge "libbinder_ndk: support for nullable parcelables" am: 56ef5878 am: 9609d975 am: 075c04ac

Change-Id: I8b4e462d38b68605942ed8543c3f18bd99713ed6
parents 768acbc8 075c04ac
Loading
Loading
Loading
Loading
+35 −0
Original line number Original line Diff line number Diff line
@@ -448,6 +448,41 @@ static inline binder_status_t AParcel_readParcelable(const AParcel* parcel, P* p
    return p->readFromParcel(parcel);
    return p->readFromParcel(parcel);
}
}


/**
 * Convenience API for writing a nullable parcelable.
 */
template <typename P>
static inline binder_status_t AParcel_writeNullableParcelable(AParcel* parcel,
                                                              const std::optional<P>& p) {
    if (p == std::nullopt) {
        return AParcel_writeInt32(parcel, 0);  // null
    }
    binder_status_t status = AParcel_writeInt32(parcel, 1);  // non-null
    if (status != STATUS_OK) {
        return status;
    }
    return p->writeToParcel(parcel);
}

/**
 * Convenience API for reading a nullable parcelable.
 */
template <typename P>
static inline binder_status_t AParcel_readNullableParcelable(const AParcel* parcel,
                                                             std::optional<P>* p) {
    int32_t null;
    binder_status_t status = AParcel_readInt32(parcel, &null);
    if (status != STATUS_OK) {
        return status;
    }
    if (null == 0) {
        *p = std::nullopt;
        return STATUS_OK;
    }
    *p = std::optional<P>(P{});
    return (*p)->readFromParcel(parcel);
}

/**
/**
 * Writes a parcelable object of type P inside a std::vector<P> at index 'index' to 'parcel'.
 * Writes a parcelable object of type P inside a std::vector<P> at index 'index' to 'parcel'.
 */
 */