BlobRef

Struct BlobRef 

Source
pub struct BlobRef {
    pub id: BlobId,
    pub size: u32,
    pub key: BlobKey,
}

Fields§

§id: BlobId§size: u32§key: BlobKey

Implementations§

Source§

impl BlobRef

Source

pub fn from_slice(data: &[u8]) -> Self

Examples found in repository?
examples/chatwith.rs (line 29)
14async fn handle_message(envelope: &Envelope, content: &[u8]) -> bool{
15    let msg_type = content[0];
16    let msg = &content[1..];
17    use threema_client::msg_types::*;
18    match (msg_type, msg.len()) {
19        (TEXT, _) => {
20            println!("{:?} ({}) => {:?}: {}", envelope.sender, envelope.nickname, &envelope.recipient, String::from_utf8_lossy(msg));
21            true
22        }
23        (TYPING_INDICATOR, 1) => {
24            let x = if msg[0] == 1 {"is"} else {"has stopped"};
25            println!("{} ({:?}) {} typing", envelope.nickname, envelope.sender, x);
26            false
27        }
28        (CONTACT_SET_PHOTO, 52) => {
29            let blobref = threema_client::blob_api::BlobRef::from_slice(msg);
30            println!("CONTACT_SET_PHOTO, blob {:?}, {}", blobref, blobref.hex());
31            //let res = blob_api::Client::new().download(&blobref).await;
32            //println!(":) {:?}", res);
33            false
34        }
35        (unknown_type, unknown_length) => {
36            eprintln!("Message with unknown type {} or length {}: {:?}", unknown_type, unknown_length, msg);
37            false
38        }
39    }
40}
More examples
Hide additional examples
examples/connect.rs (line 65)
51    async fn handle_message(&mut self, envelope: &transport::Envelope, content: Vec<u8>) {
52        let msg_type = content[0];
53        let msg = &content[1..];
54        use msg_types::*;
55        match (msg_type, msg.len()) {
56            (TEXT, _) => {
57                println!("{:?} ({}) => {:?}: {}", envelope.sender, envelope.nickname, &envelope.recipient, String::from_utf8_lossy(msg));
58                let _res = self.w.send_download_ack(envelope).await;
59            }
60            (TYPING_INDICATOR, 1) => {
61                let x = if msg[0] == 1 {"is"} else {"has stopped"};
62                println!("{} ({:?}) {} typing", envelope.nickname, envelope.sender, x);
63            }
64            (CONTACT_SET_PHOTO, 52) => {
65                let blobref = blob_api::BlobRef::from_slice(msg);
66                println!("CONTACT_SET_PHOTO, blob {:?}, {}", blobref, blobref.hex());
67                //let res = blob_api::Client::new().download(&blobref).await;
68                //println!(":) {:?}", res);
69                
70            }
71            (unknown_type, unknown_length) => {
72                eprintln!("Message with unknown type {} or length {}: {:?}", unknown_type, unknown_length, msg)
73            }
74        }
75    }
Source

pub fn from_hex(data: &str) -> Result<Self, ParseError>

Examples found in repository?
examples/getblob.rs (line 24)
7async fn main(){
8    env_logger::init();
9    let argv = std::env::args().collect::<Vec<_>>();
10    let hexid;
11    let mark_done;
12    if argv.len() == 2 {
13        hexid = &argv[1];
14        mark_done = false;
15    }
16    else if argv.len() == 3 && argv[1] == "-d" {
17        hexid = &argv[2];
18        mark_done = true;
19    }
20    else {
21        eprintln!("usage: {} HEXBLOBREF", std::env::args().next().unwrap());
22        std::process::exit(1);
23    }
24    let blobref = blob_api::BlobRef::from_hex(hexid).expect("invalid id given.");
25    let c = blob_api::Client::new();
26    let blob = c.download(&blobref).await.expect("retrieving blob");
27    std::io::stdout().lock().write_all(&blob).expect("write out failed");
28    if mark_done {
29        c.mark_done(&blobref.id).await.expect("mark_done failed");
30    }
31}
Source

pub fn to_slice(&self, out: &mut [u8])

Source

pub fn hex(&self) -> String

Examples found in repository?
examples/putblob.rs (line 22)
8async fn main(){
9    env_logger::init();
10    let argv = std::env::args().collect::<Vec<_>>();
11    let mut blob = vec![];
12    if argv.len() == 2 {
13        let fname = &argv[1];
14        let f = std::fs::File::open(fname).expect(fname);
15        BufReader::new(f).read_to_end(&mut blob).expect(fname);
16    }
17    else {
18        std::io::stdin().lock().read_to_end(&mut blob).expect("reading stdin");
19    }
20    let c = blob_api::Client::new();
21    let blobid = c.upload(&blob).await.expect("upload blob");
22    println!("{}", blobid.hex());
23}
More examples
Hide additional examples
examples/chatwith.rs (line 30)
14async fn handle_message(envelope: &Envelope, content: &[u8]) -> bool{
15    let msg_type = content[0];
16    let msg = &content[1..];
17    use threema_client::msg_types::*;
18    match (msg_type, msg.len()) {
19        (TEXT, _) => {
20            println!("{:?} ({}) => {:?}: {}", envelope.sender, envelope.nickname, &envelope.recipient, String::from_utf8_lossy(msg));
21            true
22        }
23        (TYPING_INDICATOR, 1) => {
24            let x = if msg[0] == 1 {"is"} else {"has stopped"};
25            println!("{} ({:?}) {} typing", envelope.nickname, envelope.sender, x);
26            false
27        }
28        (CONTACT_SET_PHOTO, 52) => {
29            let blobref = threema_client::blob_api::BlobRef::from_slice(msg);
30            println!("CONTACT_SET_PHOTO, blob {:?}, {}", blobref, blobref.hex());
31            //let res = blob_api::Client::new().download(&blobref).await;
32            //println!(":) {:?}", res);
33            false
34        }
35        (unknown_type, unknown_length) => {
36            eprintln!("Message with unknown type {} or length {}: {:?}", unknown_type, unknown_length, msg);
37            false
38        }
39    }
40}
examples/connect.rs (line 66)
51    async fn handle_message(&mut self, envelope: &transport::Envelope, content: Vec<u8>) {
52        let msg_type = content[0];
53        let msg = &content[1..];
54        use msg_types::*;
55        match (msg_type, msg.len()) {
56            (TEXT, _) => {
57                println!("{:?} ({}) => {:?}: {}", envelope.sender, envelope.nickname, &envelope.recipient, String::from_utf8_lossy(msg));
58                let _res = self.w.send_download_ack(envelope).await;
59            }
60            (TYPING_INDICATOR, 1) => {
61                let x = if msg[0] == 1 {"is"} else {"has stopped"};
62                println!("{} ({:?}) {} typing", envelope.nickname, envelope.sender, x);
63            }
64            (CONTACT_SET_PHOTO, 52) => {
65                let blobref = blob_api::BlobRef::from_slice(msg);
66                println!("CONTACT_SET_PHOTO, blob {:?}, {}", blobref, blobref.hex());
67                //let res = blob_api::Client::new().download(&blobref).await;
68                //println!(":) {:?}", res);
69                
70            }
71            (unknown_type, unknown_length) => {
72                eprintln!("Message with unknown type {} or length {}: {:?}", unknown_type, unknown_length, msg)
73            }
74        }
75    }

Trait Implementations§

Source§

impl Clone for BlobRef

Source§

fn clone(&self) -> BlobRef

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BlobRef

Source§

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

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,