binder::binder_impl

Struct BorrowedParcel

Source
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>

Source

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.

Source

pub fn reborrow(&mut self) -> BorrowedParcel<'_>

Get a sub-reference to this reference to the parcel.

Source§

impl<'a> BorrowedParcel<'a>

Source

pub fn mark_sensitive(&mut self)

Data written to parcelable is zero’d before being deleted or reallocated.

Source

pub fn write<S: Serialize + ?Sized>( &mut self, parcelable: &S, ) -> Result<(), StatusCode>

Write a type that implements Serialize to the parcel.

Source

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.

Source

pub fn sized_write<F>(&mut self, f: F) -> Result<(), StatusCode>
where for<'b> F: FnOnce(&'b mut WritableSubParcel<'b>) -> 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]
Source

pub fn get_data_position(&self) -> i32

Returns the current position in the parcel data.

Source

pub fn get_data_size(&self) -> i32

Returns the total size of the parcel.

Source

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.

Source

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.

Source

pub fn append_all_from( &mut self, other: &impl AsNative<AParcel>, ) -> Result<(), StatusCode>

Append the contents of another parcel.

Source§

impl<'a> BorrowedParcel<'a>

Source

pub fn read<D: Deserialize>(&self) -> Result<D, StatusCode>

Attempt to read a type that implements Deserialize from this parcel.

Source

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.

Source

pub fn sized_read<F>(&self, f: F) -> Result<(), StatusCode>
where for<'b> F: FnOnce(ReadableSubParcel<'b>) -> 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(())
});
Source

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.

Source

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§

Source§

impl<'a> Debug for BorrowedParcel<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.