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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use std::fmt;
use serde::Deserialize;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Deserialize)]
pub enum AttachmentType {
#[serde(rename = "event.attachment")]
Attachment,
#[serde(rename = "event.minidump")]
Minidump,
#[serde(rename = "event.applecrashreport")]
AppleCrashReport,
#[serde(rename = "unreal.context")]
UnrealContext,
#[serde(rename = "unreal.logs")]
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, Default)]
pub struct Attachment {
pub buffer: Vec<u8>,
pub filename: String,
pub content_type: Option<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}","content_type":"{ct}"}}"#,
filename = self.filename,
length = self.buffer.len(),
at = self.ty.unwrap_or_default().as_str(),
ct = self
.content_type
.as_ref()
.unwrap_or(&"application/octet-stream".to_string())
)?;
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("content_type", &self.content_type)
.field("type", &self.ty)
.finish()
}
}