@@ -15,6 +15,17 @@ use crate::internal;
1515
1616#[ cxx:: bridge( namespace = "datadog::profiling" ) ]
1717pub mod ffi {
18+ // Shared enums
19+ #[ derive( Debug ) ]
20+ #[ repr( u8 ) ]
21+ enum MimeType {
22+ ApplicationJson ,
23+ ApplicationOctetStream ,
24+ TextCsv ,
25+ TextPlain ,
26+ TextXml ,
27+ }
28+
1829 // Shared structs - CXX-friendly types
1930 struct ValueType < ' a > {
2031 type_ : & ' a str ,
@@ -68,6 +79,7 @@ pub mod ffi {
6879 struct AttachmentFile < ' a > {
6980 name : & ' a str ,
7081 data : & ' a [ u8 ] ,
82+ mime : MimeType ,
7183 }
7284
7385 // Opaque Rust types
@@ -274,12 +286,30 @@ impl<'a> From<&ffi::Label<'a>> for api::Label<'a> {
274286 }
275287}
276288
277- impl < ' a > From < & ffi:: AttachmentFile < ' a > > for exporter:: File < ' a > {
278- fn from ( file : & ffi:: AttachmentFile < ' a > ) -> Self {
279- exporter:: File {
289+ impl TryFrom < ffi:: MimeType > for exporter:: MimeType {
290+ type Error = anyhow:: Error ;
291+
292+ fn try_from ( mime : ffi:: MimeType ) -> Result < Self , Self :: Error > {
293+ match mime {
294+ ffi:: MimeType :: ApplicationJson => Ok ( exporter:: MimeType :: ApplicationJson ) ,
295+ ffi:: MimeType :: ApplicationOctetStream => Ok ( exporter:: MimeType :: ApplicationOctetStream ) ,
296+ ffi:: MimeType :: TextCsv => Ok ( exporter:: MimeType :: TextCsv ) ,
297+ ffi:: MimeType :: TextPlain => Ok ( exporter:: MimeType :: TextPlain ) ,
298+ ffi:: MimeType :: TextXml => Ok ( exporter:: MimeType :: TextXml ) ,
299+ _ => anyhow:: bail!( "Unknown MimeType variant: {:?}" , mime) ,
300+ }
301+ }
302+ }
303+
304+ impl < ' a > TryFrom < & ffi:: AttachmentFile < ' a > > for exporter:: File < ' a > {
305+ type Error = anyhow:: Error ;
306+
307+ fn try_from ( file : & ffi:: AttachmentFile < ' a > ) -> Result < Self , Self :: Error > {
308+ Ok ( exporter:: File {
280309 name : file. name ,
281310 bytes : file. data ,
282- }
311+ mime : file. mime . try_into ( ) ?,
312+ } )
283313 }
284314}
285315
@@ -620,8 +650,10 @@ impl ProfileExporter {
620650 let end_time = Some ( std:: time:: SystemTime :: now ( ) ) ;
621651 let encoded = old_profile. serialize_into_compressed_pprof ( end_time, None ) ?;
622652
623- let files_to_compress_vec: Vec < exporter:: File > =
624- files_to_compress. iter ( ) . map ( Into :: into) . collect ( ) ;
653+ let files_to_compress_vec: Vec < exporter:: File > = files_to_compress
654+ . iter ( )
655+ . map ( TryInto :: try_into)
656+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
625657
626658 let additional_tags_vec: Vec < libdd_common:: tag:: Tag > = additional_tags
627659 . iter ( )
@@ -901,10 +933,16 @@ mod tests {
901933 let file: exporter:: File = ( & ffi:: AttachmentFile {
902934 name : "test.bin" ,
903935 data : & data,
936+ mime : ffi:: MimeType :: ApplicationOctetStream ,
904937 } )
905- . into ( ) ;
938+ . try_into ( )
939+ . expect ( "Failed to convert AttachmentFile" ) ;
906940 assert_eq ! ( file. name, "test.bin" ) ;
907941 assert_eq ! ( file. bytes, data. as_slice( ) ) ;
942+ assert ! ( matches!(
943+ file. mime,
944+ exporter:: MimeType :: ApplicationOctetStream
945+ ) ) ;
908946
909947 // Tag conversion with special characters
910948 let tag: libdd_common:: tag:: Tag = ( & ffi:: Tag {
@@ -996,6 +1034,7 @@ mod tests {
9961034 vec ! [ ffi:: AttachmentFile {
9971035 name: "metadata.json" ,
9981036 data: & attachment_data,
1037+ mime: ffi:: MimeType :: ApplicationJson ,
9991038 } ] ,
10001039 vec ! [
10011040 ffi:: Tag {
0 commit comments