croc_sidecar/event.rs
1use crate::croc::Relay;
2
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6/// Represents progress of an ongoing operation.
7#[derive(Debug, Clone)]
8#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9pub struct Progress {
10 /// The name of the file being processed.
11 pub file_name: String,
12 /// The current progress percentage (0-100).
13 pub percentage: u8,
14 /// The number of bytes transferred so far, if available.
15 pub bytes_sent: Option<u64>,
16 /// The total number of bytes to transfer, if available.
17 pub bytes_total: Option<u64>,
18 /// The current transfer speed in bytes per second, if available.
19 pub speed: Option<f64>,
20}
21
22/// Represents information about a file being transferred.
23#[derive(Debug, Clone)]
24#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
25pub struct FileInfo {
26 /// The name of the file.
27 pub name: String,
28 /// The size of the file in bytes.
29 pub size: u64,
30}
31
32/// A collection representing an event that happened in the running `croc` application.
33#[derive(Debug, Clone)]
34#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
35pub enum CrocEvent {
36 /// A hashing operation is in progress.
37 Hashing(Progress),
38 /// Information about a file being sent.
39 SendingInfo(FileInfo),
40 /// Information about a file being received.
41 ReceivingInfo(FileInfo),
42 /// The connection code has been generated.
43 CodeGenerated(String),
44 /// The transfer is sending data to the specified relay/IP.
45 SendingTo(Relay),
46 /// The transfer is receiving data from the specified relay/IP.
47 ReceivingFrom(Relay),
48 /// A file is currently being sent.
49 Sending(Progress),
50 /// A file is currently being received.
51 Receiving(Progress),
52 /// The transfer has completed successfully.
53 Done,
54 /// An unknown line for the parser has been received.
55 Unknown(String),
56 /// The process has reached EOF.
57 EOF,
58}