binder_rs: Add in-place deserialization methods
This adds deserialize_from methods to the Deserialize
and DeserializeOption traits in libbinder_rs that perform
in-place deserialization of values on top of existing objects.
The new methods are used for partial deserialization of parcelables
in the AIDL compiler.
Also adds a helper impl_deserialize_for_parcelable! helper macro.
Bug: 186724059
Test: m
Change-Id: I9fcbd4c7fa4ab85d8ab84792c9c5595ee149879f
diff --git a/libs/binder/rust/src/parcel.rs b/libs/binder/rust/src/parcel.rs
index 6c34824..ef84ade 100644
--- a/libs/binder/rust/src/parcel.rs
+++ b/libs/binder/rust/src/parcel.rs
@@ -219,6 +219,13 @@
D::deserialize(self)
}
+ /// Attempt to read a type that implements [`Deserialize`] from this
+ /// `Parcel` onto an existing value. This operation will overwrite the old
+ /// value partially or completely, depending on how much data is available.
+ pub fn read_onto<D: Deserialize>(&self, x: &mut D) -> Result<()> {
+ x.deserialize_from(self)
+ }
+
/// Read a vector size from the `Parcel` and resize the given output vector
/// to be correctly sized for that amount of data.
///