Crate flow_record

source ·
Expand description

§Usage

use serde::Serialize;
use chrono::prelude::*;
use flow_record::{Serializer, Record};
use flow_record_derive::Record;
 
#[derive(Serialize, Record)]
struct SampleStruct {
    int_value: u32,
    str_value: String,
    dtm_value: DateTime<Utc>
}
 
let sample_struct = SampleStruct {
    int_value: 42,
    str_value: "forty two".into(),
    dtm_value: Utc.with_ymd_and_hms(2020, 1, 1, 0, 0, 0).unwrap(),
};
 
let mut ser = Serializer::new(Vec::new());
ser.serialize(&sample_struct).unwrap();
 
let result = ser.into_inner();
assert_eq!(result, vec![
    // header length
    0x0,0x0,0x0,0xf,
     
    // header
    0xc4,0xd,0x52,0x45,0x43,0x4f,0x52,0x44,0x53,0x54,0x52,0x45,0x41,0x4d,0xa,
     
    // length of record descriptor
    0x0,0x0,0x0,0x4c,
 
    0xc7,0x49,0xe,      // ext 8 record of type 0x0e
        0x92,           // array of length 2
            0x2,        // 2 (record desciptor)
            0x92,       // array of length 2
                0xac,   // string of length 12
                // "SampleStruct"
                0x53,0x61,0x6d,0x70,0x6c,0x65,0x53,0x74,0x72,0x75,0x63,0x74,
                0x93,   // array of length 3
                    0x92,   // array of length 2
                        0xa6, // string of length 6
                            0x75,0x69,0x6e,0x74,0x33,0x32, // "uint32"
                        0xa9, // string of length 9
                            0x69,0x6e,0x74,0x5f,0x76,0x61,0x6c,0x75,0x65, // "int_value"
                    0x92,
                        0xa6, // string of length 6
                            0x73,0x74,0x72,0x69,0x6e,0x67,
                        0xa9,0x73,0x74,0x72,0x5f,0x76,0x61,0x6c,0x75,0x65,
                    0x92,
                        0xa8,
                            0x64,0x61,0x74,0x65,0x74,0x69,0x6d,0x65,
                        0xa9,
                            0x64,0x74,0x6d,0x5f,0x76,0x61,0x6c,0x75,0x65,
    0x0,0x0,0x0,0x3a, // length of record
    0xc7,0x37,0xe,
        0x92,
            0x1,
            0x92,
                0x92,
                    0xac,
                        0x53,0x61,0x6d,0x70,0x6c,0x65,0x53,0x74,0x72,0x75,0x63,0x74,
                    0xce, // uint32
                        0x6,0xd6,0x49,0xca,
                    0x93, // array of length 3
                        0x2a,
                        0xa9,   // string of length 9
                            0x66,0x6f,0x72,0x74,0x79,0x20,0x74,0x77,0x6f,
                        0xb4,   // string of length 20
                                // "2020-01-01T00:00:00Z"
                            0x32,0x30,0x32,0x30,0x2d,0x30,0x31,0x2d,0x30,0x31,0x54,0x30,0x30,0x3a,0x30,0x30,0x3a,0x30,0x30,0x5a,]);

Modules§

Structs§

Enums§

Traits§