-
Notifications
You must be signed in to change notification settings - Fork 722
Expand file tree
/
Copy pathoptions.rs
More file actions
158 lines (150 loc) · 5.87 KB
/
options.rs
File metadata and controls
158 lines (150 loc) · 5.87 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
use ::opendal as core;
use opendal::{
options::ReadOptions,
raw::{BytesRange, Timestamp},
Error,
};
use std::{os::raw::c_char, str::FromStr};
/// \brief Options for read operations used by C side.
///
/// \note For detail description of each field, please refer to [`core::ReadOptions`]
#[repr(C)]
#[derive(Clone, Copy)]
pub struct opendal_operator_options_read {
/// Set `range` for this operation.
pub range: *const u64,
/// Set `version` for this operation.
pub version: *const c_char,
/// Set `if_match` for this operation.
pub if_match: *const c_char,
/// Set `if_none_match` for this operation.
pub if_none_match: *const c_char,
/// Set `if_modified_since` for this operation.
///
/// \note The value should be in RFC 3339 format.
pub if_modified_since: *const c_char,
/// Set `if_unmodified_since` for this operation.
///
/// \note The value should be in RFC 3339 format.
pub if_unmodified_since: *const c_char,
/// Set `concurrent` for the operation.
///
/// \note for we do not provide default value in C, so it must be Option in C side.
pub concurrent: *const usize,
/// Set `chunk` for the operation.
pub chunk: *const usize,
/// Controls the optimization strategy for range reads in [`Reader::fetch`].
pub gap: *const usize,
/// Specify the content-type header that should be sent back by the operation.
pub override_content_type: *const c_char,
/// Specify the `cache-control` header that should be sent back by the operation.
pub override_cache_control: *const c_char,
/// Specify the `content-disposition` header that should be sent back by the operation.
pub override_content_disposition: *const c_char,
}
impl opendal_operator_options_read {}
pub fn parse_read_options(
options: *const opendal_operator_options_read,
) -> Result<core::options::ReadOptions, Error> {
// if original opts is blank, we will use the default options
let mut opts = ReadOptions::default();
unsafe {
let options = *options;
if !options.range.is_null() {
// TODO:
// Do we need to make sure it has no more than 2 usize?
let range = std::slice::from_raw_parts(options.range, 2);
opts.range = BytesRange::new(range[0], Some(range[1]));
}
if !options.version.is_null() {
opts.version = Some(
std::ffi::CStr::from_ptr(options.version)
.to_str()
.expect("malformed version")
.to_string(),
);
}
if !options.if_match.is_null() {
opts.if_match = Some(
std::ffi::CStr::from_ptr(options.if_match)
.to_str()
.expect("malformed if_match")
.to_string(),
);
}
if !options.if_none_match.is_null() {
opts.if_none_match = Some(
std::ffi::CStr::from_ptr(options.if_none_match)
.to_str()
.expect("malformed if_none_match")
.to_string(),
);
}
if !options.if_modified_since.is_null() {
let ts_str = std::ffi::CStr::from_ptr(options.if_modified_since)
.to_str()
.expect("malformed if_modified_since")
.to_string();
let ts = Timestamp::from_str(&ts_str)?;
opts.if_modified_since = Some(ts);
}
if !options.if_unmodified_since.is_null() {
let ts_str = std::ffi::CStr::from_ptr(options.if_unmodified_since)
.to_str()
.expect("malformed if_unmodified_since")
.to_string();
let ts = Timestamp::from_str(&ts_str)?;
opts.if_unmodified_since = Some(ts);
}
if !options.concurrent.is_null() {
opts.concurrent = *options.concurrent;
}
if !options.chunk.is_null() {
opts.chunk = Some(*options.chunk);
}
if !options.gap.is_null() {
opts.gap = Some(*options.gap);
}
if !options.override_content_type.is_null() {
opts.override_content_type = Some(
std::ffi::CStr::from_ptr(options.override_content_type)
.to_str()
.expect("malformed override_content_type")
.to_string(),
);
}
if !options.override_cache_control.is_null() {
opts.override_cache_control = Some(
std::ffi::CStr::from_ptr(options.override_cache_control)
.to_str()
.expect("malformed override_cache_control")
.to_string(),
);
}
if !options.override_content_disposition.is_null() {
opts.override_content_disposition = Some(
std::ffi::CStr::from_ptr(options.override_content_disposition)
.to_str()
.expect("malformed override_content_disposition")
.to_string(),
);
}
}
Ok(opts)
}