1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use std::fmt;
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum AttachmentType {
Attachment,
Minidump,
AppleCrashReport,
UnrealContext,
UnrealLogs,
}
impl Default for AttachmentType {
fn default() -> Self {
Self::Attachment
}
}
impl AttachmentType {
pub fn as_str(self) -> &'static str {
match self {
Self::Attachment => "event.attachment",
Self::Minidump => "event.minidump",
Self::AppleCrashReport => "event.applecrashreport",
Self::UnrealContext => "unreal.context",
Self::UnrealLogs => "unreal.logs",
}
}
}
#[derive(Clone, PartialEq)]
pub struct Attachment {
pub buffer: Vec<u8>,
pub filename: String,
pub ty: Option<AttachmentType>,
}
impl Attachment {
pub fn to_writer<W>(&self, writer: &mut W) -> std::io::Result<()>
where
W: std::io::Write,
{
writeln!(
writer,
r#"{{"type":"attachment","length":{length},"filename":"{filename}","attachment_type":"{at}"}}"#,
filename = self.filename,
length = self.buffer.len(),
at = self.ty.unwrap_or_default().as_str()
)?;
writer.write_all(&self.buffer)?;
Ok(())
}
}
impl fmt::Debug for Attachment {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Attachment")
.field("buffer", &self.buffer.len())
.field("filename", &self.filename)
.field("type", &self.ty)
.finish()
}
}