Struct Parcel

Source
pub struct Parcel { /* private fields */ }
Expand description

Parcel converts data into a byte stream (serialization), making it transferable. The receiving side then transforms this byte stream back into its original data form (deserialization).

Implementations§

Source§

impl Parcel

Source

pub fn new() -> Self

Source

pub fn with_capacity(capacity: usize) -> Self

Source

pub fn from_ipc_parts( data: *mut u8, length: usize, objects: *mut c_ulonglong, object_count: usize, free_buffer: fn(Option<&Parcel>, c_ulonglong, usize, c_ulonglong, usize) -> Result<()>, ) -> Self

Source

pub fn from_vec(data: Vec<u8>) -> Self

Source

pub fn as_mut_ptr(&mut self) -> *mut u8

Source

pub fn as_ptr(&self) -> *const u8

Source

pub fn capacity(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn set_data_size(&mut self, new_len: usize)

Source

pub fn close_file_descriptors(&self)

Source

pub fn set_data_position(&mut self, pos: usize)

Source

pub fn data_position(&self) -> usize

Source

pub fn data_size(&self) -> usize

Source

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

Read a type that implements Deserialize from the sub-parcel.

Source

pub fn read_onto<D: Deserialize>(&mut self, x: &mut D) -> Result<()>

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 data_avail(&self) -> usize

Source

pub fn sized_read<F>(&mut self, f: F) -> Result<()>
where for<'b> F: FnOnce(&mut Parcel) -> Result<()>,

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. After the closure returns, skip to the end of the current parcelable regardless of how much the closure has read.

Source

pub fn resize_out_vec<D: Default + Deserialize>( &mut self, out_vec: &mut Vec<D>, ) -> Result<()>

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>( &mut self, out_vec: &mut Option<Vec<D>>, ) -> Result<()>

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.

Source

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

Source

pub fn write_slice_size<T>(&mut self, slice: Option<&[T]>) -> Result<()>

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<()>
where for<'b> F: FnOnce(&mut Parcel) -> Result<()>,

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]

Trait Implementations§

Source§

impl Debug for Parcel

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Parcel

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for Parcel

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<const N: usize> TryFrom<&mut Parcel> for [u8; N]

Source§

type Error = StatusCode

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

fn try_from(parcel: &mut Parcel) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for Parcel

§

impl RefUnwindSafe for Parcel

§

impl Send for Parcel

§

impl Sync for Parcel

§

impl Unpin for Parcel

§

impl !UnwindSafe for Parcel

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

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

Source§

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

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

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

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &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> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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.