pub struct BlobRef {
pub id: BlobId,
pub size: u32,
pub key: BlobKey,
}Fields§
§id: BlobId§size: u32§key: BlobKeyImplementations§
Source§impl BlobRef
impl BlobRef
Sourcepub fn from_slice(data: &[u8]) -> Self
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
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 }Sourcepub fn from_hex(data: &str) -> Result<Self, ParseError>
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}pub fn to_slice(&self, out: &mut [u8])
Sourcepub fn hex(&self) -> String
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
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§
Auto Trait Implementations§
impl Freeze for BlobRef
impl RefUnwindSafe for BlobRef
impl Send for BlobRef
impl Sync for BlobRef
impl Unpin for BlobRef
impl UnwindSafe for BlobRef
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
Mutably borrows from an owned value. Read more