summaryrefslogtreecommitdiff
path: root/policy/_policies/src/lib.rs.t
blob: 873a4cdf66b2624894b30af223794e706b8e563b (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Auto generated dependencies
// If you find issues with the dependencies, please
//   1. Delete all code after this comment
//   2. Clear the auto generated part in `policy/_policies/Cargo.toml`
//   3. Run `cargo run --bin butckrepo-refresh` in the Butchunker root directory
pub mod error;
pub mod stream_read;

use error::ChunkFailed;
use std::{collections::HashMap, path::Path};

use crate::stream_read::chunk_stream_process;

/// Chunks the specified raw data using the specified chunking policy
///
/// # Parameters
/// - `policy_name`: Chunking policy name, currently supports <<<policy_count>>> policies
/// - `raw_data`: Raw data byte slice
/// - `params`: Hashmap of parameters required by the chunking policy
pub async fn chunk_with(
    policy_name: &str,
    raw_data: &[u8],
    params: &HashMap<&str, &str>,
) -> Result<Vec<u32>, ChunkFailed> {
    match policy_name {
>>>>>>>>>> match_arms
        _ => Err(ChunkFailed::PolicyNotFound),
    }
}

pub async fn chunk_stream_with(
    policy_name: &str,
    size: u32,
    path: &Path,
    params: &HashMap<&str, &str>,
) -> Result<Vec<u32>, ChunkFailed> {
    match policy_name {
>>>>>>>>>> match_arms_stream
        _ => Err(ChunkFailed::PolicyNotFound),
    }
}

pub fn policies() -> Vec<&'static str> {
    vec![
>>>>>>>>>> policy_names
    ]
}

>>>>>>>>>> exports_simple
>>>>>>>>>> exports_stream
>>>>>>>>>> exports_both

@@@ >>> match_arms
        "<<<crate_name>>>" => Ok(<<<crate_name>>>::chunk(raw_data, params).await),
@@@ <<<

@@@ >>> match_arms_stream
        "<<<crate_name>>>" => {
            let mut stream = <<<stream_struct_id>>>::default();
            chunk_stream_process(
                path, &mut stream, size, params,
                async |current_data, len, stream, params| {
                    <<<crate_name>>>::chunk_stream(current_data, len, stream, params).await
                },
            )
            .await
        }
@@@ <<<

@@@ >>> policy_names
        // <<<name>>>
        "<<<name>>>",
@@@ <<<

@@@ >>> exports_simple
pub mod <<<crate_name>>> {
    use std::collections::HashMap;
    pub async fn chunk(raw_data: &[u8], params: &HashMap<&str, &str>) -> Vec<u32> {
        <<<crate_name>>>::<<<matched_func>>>(raw_data, params)<<<has_await>>>
    }
}
@@@ <<<

@@@ >>> exports_stream
pub mod <<<crate_name>>> {
    pub use <<<stream_struct_id>>>;

    pub async fn chunk_stream(
        current_data: &[u8],
        len: u32,
        stream: &mut <<<stream_struct_id>>>,
        params: &std::collections::HashMap<&str, &str>,
    ) -> Option<u32> {
        <<<crate_name>>>::<<<matched_func_stream>>>(current_data, len, stream, params)<<<has_await_stream>>>
    }
}
@@@ <<<

@@@ >>> exports_both
pub mod <<<crate_name>>> {
    pub use <<<stream_struct_id>>>;
    use std::collections::HashMap;

    pub async fn chunk(raw_data: &[u8], params: &HashMap<&str, &str>) -> Vec<u32> {
        <<<crate_name>>>::<<<matched_func>>>(raw_data, params)<<<has_await>>>
    }

    pub async fn chunk_stream(
        current_data: &[u8],
        len: u32,
        stream: &mut <<<stream_struct_id>>>,
        params: &HashMap<&str, &str>,
    ) -> Option<u32> {
        <<<crate_name>>>::<<<matched_func_stream>>>(current_data, len, stream, params)<<<has_await_stream>>>
    }
}
@@@ <<<