-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bindings/c): add writer operation for Bindings C and Go (#5141)
* feat(bindings/c): add writer operation Signed-off-by: Hanchin Hsieh <[email protected]> * feat(bindings/go): add writer operation Signed-off-by: Hanchin Hsieh <[email protected]> * ci(bindings/go): test against service-fs Signed-off-by: Hanchin Hsieh <[email protected]> * fix(bindings/go): fix tests Signed-off-by: Hanchin Hsieh <[email protected]> * fix(bindings/c): use BlockWriter instead of StdWriter Signed-off-by: Hanchin Hsieh <[email protected]> --------- Signed-off-by: Hanchin Hsieh <[email protected]>
- Loading branch information
Showing
16 changed files
with
526 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,5 +22,5 @@ build: | |
goos: "linux" | ||
goarch: "amd64" | ||
service: | ||
- "memory" | ||
- "fs" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// 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 super::*; | ||
|
||
/// \brief The result type returned by opendal's writer operation. | ||
/// \note The opendal_writer actually owns a pointer to | ||
/// a opendal::BlockingWriter, which is inside the Rust core code. | ||
#[repr(C)] | ||
pub struct opendal_writer { | ||
inner: *mut core::BlockingWriter, | ||
} | ||
|
||
impl opendal_writer { | ||
pub(crate) fn new(writer: core::BlockingWriter) -> Self { | ||
Self { | ||
inner: Box::into_raw(Box::new(writer)), | ||
} | ||
} | ||
|
||
/// \brief Write data to the writer. | ||
#[no_mangle] | ||
pub unsafe extern "C" fn opendal_writer_write( | ||
writer: *const Self, | ||
bytes: opendal_bytes, | ||
) -> opendal_result_writer_write { | ||
let inner = unsafe { &mut *(*writer).inner }; | ||
let size = bytes.len; | ||
match inner.write(bytes) { | ||
Ok(()) => opendal_result_writer_write { | ||
size, | ||
error: std::ptr::null_mut(), | ||
}, | ||
Err(e) => opendal_result_writer_write { | ||
size: 0, | ||
error: opendal_error::new( | ||
core::Error::new(core::ErrorKind::Unexpected, "write failed from writer") | ||
.set_source(e), | ||
), | ||
}, | ||
} | ||
} | ||
|
||
/// \brief Frees the heap memory used by the opendal_writer. | ||
/// \note This function make sure all data have been stored. | ||
#[no_mangle] | ||
pub unsafe extern "C" fn opendal_writer_free(ptr: *mut opendal_writer) { | ||
if !ptr.is_null() { | ||
let mut w = unsafe { Box::from_raw((*ptr).inner) }; | ||
let _ = w.close(); | ||
let _ = unsafe { Box::from_raw(ptr) }; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.