pub struct BorrowedParcel<'a> { /* private fields */ }
Expand description
Container for a message (data and object references) that can be sent through Binder.
This object is a borrowed variant of Parcel
. It is a separate type from
&mut Parcel
because it is not valid to mem::swap
two parcels.
Implementations§
Source§impl<'a> BorrowedParcel<'a>
impl<'a> BorrowedParcel<'a>
Sourcepub unsafe fn from_raw(ptr: *mut AParcel) -> Option<BorrowedParcel<'a>>
pub unsafe fn from_raw(ptr: *mut AParcel) -> Option<BorrowedParcel<'a>>
Create a borrowed reference to a parcel object from a raw pointer.
§Safety
This constructor is safe if the raw pointer parameter is either null
(resulting in None
), or a valid pointer to an AParcel
object.
Since the raw pointer is not restricted by any lifetime, the lifetime on
the returned BorrowedParcel
object can be chosen arbitrarily by the
caller. The caller must ensure it is valid to mutably borrow the AParcel
for the duration of the lifetime that the caller chooses. Note that
since this is a mutable borrow, it must have exclusive access to the
AParcel for the duration of the borrow.
Sourcepub fn reborrow(&mut self) -> BorrowedParcel<'_>
pub fn reborrow(&mut self) -> BorrowedParcel<'_>
Get a sub-reference to this reference to the parcel.
Source§impl<'a> BorrowedParcel<'a>
impl<'a> BorrowedParcel<'a>
Sourcepub fn mark_sensitive(&mut self)
pub fn mark_sensitive(&mut self)
Data written to parcelable is zero’d before being deleted or reallocated.
Sourcepub fn write<S: Serialize + ?Sized>(
&mut self,
parcelable: &S,
) -> Result<(), StatusCode>
pub fn write<S: Serialize + ?Sized>( &mut self, parcelable: &S, ) -> Result<(), StatusCode>
Write a type that implements Serialize
to the parcel.
Sourcepub fn write_slice_size<T>(
&mut self,
slice: Option<&[T]>,
) -> Result<(), StatusCode>
pub fn write_slice_size<T>( &mut self, slice: Option<&[T]>, ) -> Result<(), StatusCode>
Writes the length of a slice to the parcel.
This is used in AIDL-generated client side code to indicate the allocated space for an output array parameter.
Sourcepub fn sized_write<F>(&mut self, f: F) -> Result<(), StatusCode>
pub fn sized_write<F>(&mut self, f: F) -> Result<(), StatusCode>
Perform a series of writes to the parcel, prepended with the length (in bytes) of the written data.
The length 0i32
will be written to the parcel first, followed by the
writes performed by the callback. The initial length will then be
updated to the length of all data written by the callback, plus the
size of the length elemement itself (4 bytes).
§Examples
After the following call:
parcel.sized_write(|subparcel| {
subparcel.write(&1u32)?;
subparcel.write(&2u32)?;
subparcel.write(&3u32)
});
parcel
will contain the following:
[16i32, 1u32, 2u32, 3u32]
Sourcepub fn get_data_position(&self) -> i32
pub fn get_data_position(&self) -> i32
Returns the current position in the parcel data.
Sourcepub fn get_data_size(&self) -> i32
pub fn get_data_size(&self) -> i32
Returns the total size of the parcel.
Sourcepub unsafe fn set_data_position(&self, pos: i32) -> Result<(), StatusCode>
pub unsafe fn set_data_position(&self, pos: i32) -> Result<(), StatusCode>
Move the current read/write position in the parcel.
§Safety
This method is safe if pos
is less than the current size of the parcel
data buffer. Otherwise, we are relying on correct bounds checking in the
Parcel C++ code on every subsequent read or write to this parcel. If all
accesses are bounds checked, this call is still safe, but we can’t rely
on that.
Sourcepub fn append_from(
&mut self,
other: &impl AsNative<AParcel>,
start: i32,
size: i32,
) -> Result<(), StatusCode>
pub fn append_from( &mut self, other: &impl AsNative<AParcel>, start: i32, size: i32, ) -> Result<(), StatusCode>
Append a subset of another parcel.
This appends size
bytes of data from other
starting at offset
start
to the current parcel, or returns an error if not possible.
Sourcepub fn append_all_from(
&mut self,
other: &impl AsNative<AParcel>,
) -> Result<(), StatusCode>
pub fn append_all_from( &mut self, other: &impl AsNative<AParcel>, ) -> Result<(), StatusCode>
Append the contents of another parcel.
Source§impl<'a> BorrowedParcel<'a>
impl<'a> BorrowedParcel<'a>
Sourcepub fn read<D: Deserialize>(&self) -> Result<D, StatusCode>
pub fn read<D: Deserialize>(&self) -> Result<D, StatusCode>
Attempt to read a type that implements Deserialize
from this parcel.
Sourcepub fn read_onto<D: Deserialize>(&self, x: &mut D) -> Result<(), StatusCode>
pub fn read_onto<D: Deserialize>(&self, x: &mut D) -> Result<(), StatusCode>
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.
Sourcepub fn sized_read<F>(&self, f: F) -> Result<(), StatusCode>
pub fn sized_read<F>(&self, f: F) -> Result<(), StatusCode>
Safely read a sized parcelable.
Read the size of a parcelable, compute the end position
of that parcelable, then build a sized readable sub-parcel
and call a closure with the sub-parcel as its parameter.
The closure can keep reading data from the sub-parcel
until it runs out of input data. The closure is responsible
for calling ReadableSubParcel::has_more_data
to check for
more data before every read, at least until Rust generators
are stabilized.
After the closure returns, skip to the end of the current
parcelable regardless of how much the closure has read.
§Examples
let mut parcelable = Default::default();
parcel.sized_read(|subparcel| {
if subparcel.has_more_data() {
parcelable.a = subparcel.read()?;
}
if subparcel.has_more_data() {
parcelable.b = subparcel.read()?;
}
Ok(())
});
Sourcepub fn resize_out_vec<D: Default + Deserialize>(
&self,
out_vec: &mut Vec<D>,
) -> Result<(), StatusCode>
pub fn resize_out_vec<D: Default + Deserialize>( &self, out_vec: &mut Vec<D>, ) -> Result<(), StatusCode>
Read a vector size from the parcel and resize the given output vector to be correctly sized for that amount of data.
This method is used in AIDL-generated server side code for methods that take a mutable slice reference parameter.
Sourcepub fn resize_nullable_out_vec<D: Default + Deserialize>(
&self,
out_vec: &mut Option<Vec<D>>,
) -> Result<(), StatusCode>
pub fn resize_nullable_out_vec<D: Default + Deserialize>( &self, out_vec: &mut Option<Vec<D>>, ) -> Result<(), StatusCode>
Read a vector size from the parcel and either create a correctly sized vector for that amount of data or set the output parameter to None if the vector should be null.
This method is used in AIDL-generated server side code for methods that take a mutable slice reference parameter.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for BorrowedParcel<'a>
impl<'a> RefUnwindSafe for BorrowedParcel<'a>
impl<'a> !Send for BorrowedParcel<'a>
impl<'a> !Sync for BorrowedParcel<'a>
impl<'a> Unpin for BorrowedParcel<'a>
impl<'a> !UnwindSafe for BorrowedParcel<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.