Skip to content

Commit

Permalink
fix swift cases
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Oct 8, 2024
1 parent 6e9b244 commit 0b5e86f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions bindings/swift/OpenDAL/Sources/OpenDAL/Data+OpenDAL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ extension Data {
/// The underlying buffer will be freed when the data gets
/// deallocated.
init(openDALBytes: opendal_bytes) {
let address = UnsafeRawPointer(openDALBytes.pointee.data)!
let length = Int(openDALBytes.pointee.len)
let address = UnsafeRawPointer(openDALBytes.data)!
let length = Int(openDALBytes.len)
self.init(
bytesNoCopy: .init(mutating: address),
count: length,
Expand Down
10 changes: 6 additions & 4 deletions bindings/swift/OpenDAL/Sources/OpenDAL/Operator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ public class Operator {
self.nativeOp = UnsafePointer(ret.op)!
}

public func blockingWrite(_ data: Data, to path: String) throws {
let ret = data.withUnsafeBytes { dataPointer in
public func blockingWrite(_ data: inout Data, to path: String) throws {
let ret = data.withUnsafeMutableBytes { dataPointer in
let address = dataPointer.baseAddress!.assumingMemoryBound(to: UInt8.self)
let bytes = opendal_bytes(data: address, len: UInt(dataPointer.count))
return opendal_operator_write(nativeOp, path, bytes)
let bytes = opendal_bytes(data: address, len: UInt(dataPointer.count), capacity: UInt(dataPointer.count))
return withUnsafePointer(to: bytes) { bytesPointer in
opendal_operator_write(nativeOp, path, bytesPointer)
}
}

if let err = ret {
Expand Down
4 changes: 2 additions & 2 deletions bindings/swift/OpenDAL/Tests/OpenDALTests/OpenDALTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ final class OpenDALTests: XCTestCase {
]
)

let testContents = Data([1, 2, 3, 4])
try op.blockingWrite(testContents, to: "test")
var testContents = Data([1, 2, 3, 4])
try op.blockingWrite(&testContents, to: "test")

let readContents = try op.blockingRead("test")

Expand Down

0 comments on commit 0b5e86f

Please sign in to comment.