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
impl Parcel
pub fn new() -> Self
pub fn with_capacity(capacity: usize) -> Self
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
pub fn from_vec(data: Vec<u8>) -> Self
pub fn as_mut_ptr(&mut self) -> *mut u8
pub fn as_ptr(&self) -> *const u8
pub fn capacity(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn set_data_size(&mut self, new_len: usize)
pub fn close_file_descriptors(&self)
pub fn set_data_position(&mut self, pos: usize)
pub fn data_position(&self) -> usize
pub fn data_size(&self) -> usize
Sourcepub fn read<D: Deserialize>(&mut self) -> Result<D>
pub fn read<D: Deserialize>(&mut self) -> Result<D>
Read a type that implements Deserialize from the sub-parcel.
Sourcepub fn read_onto<D: Deserialize>(&mut self, x: &mut D) -> Result<()>
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.
pub fn data_avail(&self) -> usize
Sourcepub fn sized_read<F>(&mut self, f: F) -> Result<()>
pub fn sized_read<F>(&mut self, f: F) -> 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.
Sourcepub fn resize_out_vec<D: Default + Deserialize>(
&mut self,
out_vec: &mut Vec<D>,
) -> Result<()>
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.
Sourcepub fn resize_nullable_out_vec<D: Default + Deserialize>(
&mut self,
out_vec: &mut Option<Vec<D>>,
) -> Result<()>
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.
pub fn write<S: Serialize + ?Sized>(&mut self, parcelable: &S) -> Result<()>
Sourcepub fn write_slice_size<T>(&mut self, slice: Option<&[T]>) -> Result<()>
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.
Sourcepub fn sized_write<F>(&mut self, f: F) -> Result<()>
pub fn sized_write<F>(&mut self, f: F) -> 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§
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> 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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§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>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§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.Source§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.