flow_record/
lib.rs

1#![doc = include_str!("../README.md")]
2
3//! # Usage
4//!
5//! ```rust
6//! use binrw::BinReaderExt;
7//! use chrono::prelude::*;
8//! use flow_record::prelude::*;
9//! use flow_record::derive::*;
10//! use std::io::{Cursor,Seek,SeekFrom};
11//! 
12//! #[derive(FlowRecord)]
13//! #[flow_record(version = 1, source = "Sample", classification = "file", skip_meta=true)]
14//! struct SampleStruct {
15//!     int_value: u32,
16//!     str_value: String,
17//!     dtm_value: DateTime<Utc>
18//! }
19//!
20//! let now = Utc::now();
21//! let sample_struct = SampleStruct {
22//!     int_value: 42,
23//!     str_value: "forty two".into(),
24//!     dtm_value: now,
25//! };
26//!
27//! let mut ser = Serializer::new(Vec::new());
28//! ser.serialize(sample_struct).unwrap();
29//!
30//! ```
31//! 
32//! That's basically all. The next steps are only necessary to validate
33//! if all data were written correctly. You can ignore this, if you just want
34//! to export the binary data.
35//! 
36//! ```rust
37//!# use binrw::BinReaderExt;
38//!# use chrono::prelude::*;
39//!# use flow_record::prelude::*;
40//!# use flow_record::derive::FlowRecord;
41//!# use std::io::{Cursor,Seek,SeekFrom};
42//!# #[derive(FlowRecord)]
43//!# #[flow_record(version = 1, source = "Sample", classification = "file", skip_meta=true)]
44//!# struct SampleStruct {
45//!#     int_value: u32,
46//!#     str_value: String,
47//!#     dtm_value: DateTime<Utc>
48//!# }
49//! let now = Utc::now();
50//!# let sample_struct = SampleStruct {
51//!#     int_value: 42,
52//!#     str_value: "forty two".into(),
53//!#     dtm_value: now,
54//!# };
55//!# let mut ser = Serializer::new(Vec::new());
56//!# ser.serialize(sample_struct).unwrap();
57//!# let mut raw_data = Cursor::new(ser.into_inner());
58//! // omit the header
59//! raw_data.seek(SeekFrom::Start((4+2+RECORDSTREAM_MAGIC.len()).try_into().unwrap()));
60//!
61//! let descriptor_record: RawFlowRecord = raw_data.read_be().unwrap();
62//! let data_record: RawFlowRecord = raw_data.read_be().unwrap();
63//!
64//! let descriptor = RecordPack::try_from(Value::from(descriptor_record)).unwrap();
65//! let data = RecordPack::try_from(Value::from(data_record)).unwrap()
66//!                 .inner().clone();
67//!
68//! assert_eq!(data,
69//!        Value::Array(vec![
70//!            1.into(), // record pack type
71//!            Value::Array(vec![
72//!                Value::Array(vec![    // reference to record descriptor
73//!                    "SampleStruct".into(),  // struct name
74//!                    114706890.into()        // struct hash
75//!                ]),
76//!                Value::Array(vec![   // actual data
77//!                    42.into(),
78//!                    "forty two".into(),
79//!                    now.timestamp().into()
80//!                ])
81//!            ])
82//!        ]));
83//! ```
84//! 
85
86pub mod artifacts;
87
88mod raw_flow_record;
89mod record_pack_type;
90mod serializer;
91
92pub use flow_record_common::ToMsgPackValue;
93
94pub mod prelude {
95    pub use super::record_pack_type::*;
96    pub use super::serializer::DfirSerializer as Serializer;
97    
98    pub use super::raw_flow_record::*;
99    pub use flow_record_common::*;
100    pub use super::serializer::RECORDSTREAM_MAGIC;
101
102    pub use sha2;
103    pub use ::rmpv;
104}
105
106pub mod derive {
107    extern crate flow_record_derive;
108    pub use flow_record_derive::FlowRecord;
109}