Struct optee_utee::extension::LoadablePlugin

source ·
pub struct LoadablePlugin { /* private fields */ }

Implementations§

source§

impl LoadablePlugin

source

pub fn new(uuid: &Uuid) -> Self

source

pub fn invoke( &self, command_id: u32, subcommand_id: u32, data: &[u8] ) -> Result<Vec<u8>>

Invoke plugin with given request data, use when you want to post something into REE.

let plugin = LoadablePlugin::new(&uuid);
let result = plugin.invoke(command_id, subcommand_id, &request_data)?;

Caution: the size of the shared buffer is set to the len of data, you could get a ShortBuffer error if Plugin return more data than shared buffer, in that case, use invoke_with_capacity and set the capacity manually.

source

pub fn invoke_with_capacity<'a>( &'a self, command_id: u32, subcommand_id: u32, capacity: usize ) -> LoadablePluginCommand<'a>

Construct a command with shared buffer up to capacity size, write the buffer and call it manually, use when you need to control details of the invoking process.

let mut cmd = plugin.invoke_with_capacity(command_id, sub_command_id, capacity);
cmd.write_body(&request_data);
let result = cmd.call()?;

You can also imply a wrapper for performance, for example, imply a std::io::Write so serde_json can write to the buffer directly.

struct Wrapper<'a, 'b>(&'b mut LoadablePluginCommand<'a>);
impl<'a, 'b> std::io::Write for Wrapper<'a, 'b> {
    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
        self.0.write_body(buf);
        Ok(buf.len())
    }
    fn flush(&mut self) -> std::io::Result<()> {
        Ok(())
    }
}
// serialize data into command directly
let request_data = serde_json::json!({
    "age": 100,
    "name": "name"
});
let mut cmd = plugin.invoke_with_capacity(command_id, subcommand_id, capacity);
serde_json::to_writer(Wrapper(&mut cmd), &request_data).map_err(|err| {
    trace_println!("serde error: {:?}", err);
    ErrorKind::Unknown
})?;
let result = cmd.call()?;

Notice: the shared buffer could grow to fit the request data automatically.

Auto Trait Implementations§

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

§

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

§

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.