From 13b911791de33e402b8800a63f732e43f505df64 Mon Sep 17 00:00:00 2001 From: leeeon233 Date: Sat, 10 Aug 2024 22:24:39 +0800 Subject: [PATCH] fix: script and value or container --- Sources/Loro/LoroFFI.swift | 202 ++++++++++++++++++++++++++++++++++++- loro-rs/Cargo.lock | 14 +-- loro-rs/Cargo.toml | 2 +- loro-rs/src/loro.udl | 6 ++ scripts/refine_trait.sh | 12 +-- 5 files changed, 220 insertions(+), 16 deletions(-) diff --git a/Sources/Loro/LoroFFI.swift b/Sources/Loro/LoroFFI.swift index 29bf582..ba95e3b 100644 --- a/Sources/Loro/LoroFFI.swift +++ b/Sources/Loro/LoroFFI.swift @@ -537,7 +537,7 @@ fileprivate struct FfiConverterData: FfiConverterRustBuffer { -public protocol ContainerIdLike : Any { +public protocol ContainerIdLike: Any { func asContainerId(ty: ContainerType) -> ContainerId @@ -4094,7 +4094,7 @@ public func FfiConverterTypeLoroUnknown_lower(_ value: LoroUnknown) -> UnsafeMut -public protocol LoroValueLike : Any { +public protocol LoroValueLike: Any { func asLoroValue() -> LoroValue @@ -4968,6 +4968,18 @@ public protocol ValueOrContainerProtocol : AnyObject { func asContainer() -> ContainerId? + func asLoroCounter() -> LoroCounter? + + func asLoroList() -> LoroList? + + func asLoroMap() -> LoroMap? + + func asLoroMovableList() -> LoroMovableList? + + func asLoroText() -> LoroText? + + func asLoroTree() -> LoroTree? + func asValue() -> LoroValue? func isContainer() -> Bool @@ -5024,6 +5036,48 @@ open func asContainer() -> ContainerId? { }) } +open func asLoroCounter() -> LoroCounter? { + return try! FfiConverterOptionTypeLoroCounter.lift(try! rustCall() { + uniffi_loro_fn_method_valueorcontainer_as_loro_counter(self.uniffiClonePointer(),$0 + ) +}) +} + +open func asLoroList() -> LoroList? { + return try! FfiConverterOptionTypeLoroList.lift(try! rustCall() { + uniffi_loro_fn_method_valueorcontainer_as_loro_list(self.uniffiClonePointer(),$0 + ) +}) +} + +open func asLoroMap() -> LoroMap? { + return try! FfiConverterOptionTypeLoroMap.lift(try! rustCall() { + uniffi_loro_fn_method_valueorcontainer_as_loro_map(self.uniffiClonePointer(),$0 + ) +}) +} + +open func asLoroMovableList() -> LoroMovableList? { + return try! FfiConverterOptionTypeLoroMovableList.lift(try! rustCall() { + uniffi_loro_fn_method_valueorcontainer_as_loro_movable_list(self.uniffiClonePointer(),$0 + ) +}) +} + +open func asLoroText() -> LoroText? { + return try! FfiConverterOptionTypeLoroText.lift(try! rustCall() { + uniffi_loro_fn_method_valueorcontainer_as_loro_text(self.uniffiClonePointer(),$0 + ) +}) +} + +open func asLoroTree() -> LoroTree? { + return try! FfiConverterOptionTypeLoroTree.lift(try! rustCall() { + uniffi_loro_fn_method_valueorcontainer_as_loro_tree(self.uniffiClonePointer(),$0 + ) +}) +} + open func asValue() -> LoroValue? { return try! FfiConverterOptionTypeLoroValue.lift(try! rustCall() { uniffi_loro_fn_method_valueorcontainer_as_value(self.uniffiClonePointer(),$0 @@ -7112,6 +7166,132 @@ fileprivate struct FfiConverterOptionTypeCursor: FfiConverterRustBuffer { } } +fileprivate struct FfiConverterOptionTypeLoroCounter: FfiConverterRustBuffer { + typealias SwiftType = LoroCounter? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterTypeLoroCounter.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeLoroCounter.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +fileprivate struct FfiConverterOptionTypeLoroList: FfiConverterRustBuffer { + typealias SwiftType = LoroList? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterTypeLoroList.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeLoroList.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +fileprivate struct FfiConverterOptionTypeLoroMap: FfiConverterRustBuffer { + typealias SwiftType = LoroMap? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterTypeLoroMap.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeLoroMap.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +fileprivate struct FfiConverterOptionTypeLoroMovableList: FfiConverterRustBuffer { + typealias SwiftType = LoroMovableList? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterTypeLoroMovableList.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeLoroMovableList.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +fileprivate struct FfiConverterOptionTypeLoroText: FfiConverterRustBuffer { + typealias SwiftType = LoroText? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterTypeLoroText.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeLoroText.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +fileprivate struct FfiConverterOptionTypeLoroTree: FfiConverterRustBuffer { + typealias SwiftType = LoroTree? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterTypeLoroTree.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeLoroTree.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + fileprivate struct FfiConverterOptionTypeOnPop: FfiConverterRustBuffer { typealias SwiftType = OnPop? @@ -8137,6 +8317,24 @@ private var initializationResult: InitializationResult = { if (uniffi_loro_checksum_method_valueorcontainer_as_container() != 61163) { return InitializationResult.apiChecksumMismatch } + if (uniffi_loro_checksum_method_valueorcontainer_as_loro_counter() != 51072) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_loro_checksum_method_valueorcontainer_as_loro_list() != 16144) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_loro_checksum_method_valueorcontainer_as_loro_map() != 62391) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_loro_checksum_method_valueorcontainer_as_loro_movable_list() != 49359) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_loro_checksum_method_valueorcontainer_as_loro_text() != 8015) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_loro_checksum_method_valueorcontainer_as_loro_tree() != 39545) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_loro_checksum_method_valueorcontainer_as_value() != 9638) { return InitializationResult.apiChecksumMismatch } diff --git a/loro-rs/Cargo.lock b/loro-rs/Cargo.lock index ebc3353..8831aca 100644 --- a/loro-rs/Cargo.lock +++ b/loro-rs/Cargo.lock @@ -604,7 +604,7 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "loro" version = "0.16.2" -source = "git+https://github.com/loro-dev/loro.git?rev=832bc6581b21efc2e6c7b46d2e3c78f85a128257#832bc6581b21efc2e6c7b46d2e3c78f85a128257" +source = "git+https://github.com/loro-dev/loro.git?rev=a9f669d173807b80dde7ffef7f467c8a57fc5b1f#a9f669d173807b80dde7ffef7f467c8a57fc5b1f" dependencies = [ "enum-as-inner 0.6.0", "generic-btree", @@ -616,7 +616,7 @@ dependencies = [ [[package]] name = "loro-common" version = "0.16.2" -source = "git+https://github.com/loro-dev/loro.git?rev=832bc6581b21efc2e6c7b46d2e3c78f85a128257#832bc6581b21efc2e6c7b46d2e3c78f85a128257" +source = "git+https://github.com/loro-dev/loro.git?rev=a9f669d173807b80dde7ffef7f467c8a57fc5b1f#a9f669d173807b80dde7ffef7f467c8a57fc5b1f" dependencies = [ "arbitrary", "enum-as-inner 0.6.0", @@ -632,7 +632,7 @@ dependencies = [ [[package]] name = "loro-delta" version = "0.16.2" -source = "git+https://github.com/loro-dev/loro.git?rev=832bc6581b21efc2e6c7b46d2e3c78f85a128257#832bc6581b21efc2e6c7b46d2e3c78f85a128257" +source = "git+https://github.com/loro-dev/loro.git?rev=a9f669d173807b80dde7ffef7f467c8a57fc5b1f#a9f669d173807b80dde7ffef7f467c8a57fc5b1f" dependencies = [ "arrayvec", "enum-as-inner 0.5.1", @@ -644,7 +644,7 @@ dependencies = [ [[package]] name = "loro-ffi" version = "0.16.2" -source = "git+https://github.com/loro-dev/loro.git?rev=832bc6581b21efc2e6c7b46d2e3c78f85a128257#832bc6581b21efc2e6c7b46d2e3c78f85a128257" +source = "git+https://github.com/loro-dev/loro.git?rev=a9f669d173807b80dde7ffef7f467c8a57fc5b1f#a9f669d173807b80dde7ffef7f467c8a57fc5b1f" dependencies = [ "loro", ] @@ -652,7 +652,7 @@ dependencies = [ [[package]] name = "loro-internal" version = "0.16.2" -source = "git+https://github.com/loro-dev/loro.git?rev=832bc6581b21efc2e6c7b46d2e3c78f85a128257#832bc6581b21efc2e6c7b46d2e3c78f85a128257" +source = "git+https://github.com/loro-dev/loro.git?rev=a9f669d173807b80dde7ffef7f467c8a57fc5b1f#a9f669d173807b80dde7ffef7f467c8a57fc5b1f" dependencies = [ "append-only-bytes", "arref", @@ -687,7 +687,7 @@ dependencies = [ [[package]] name = "loro-rle" version = "0.16.2" -source = "git+https://github.com/loro-dev/loro.git?rev=832bc6581b21efc2e6c7b46d2e3c78f85a128257#832bc6581b21efc2e6c7b46d2e3c78f85a128257" +source = "git+https://github.com/loro-dev/loro.git?rev=a9f669d173807b80dde7ffef7f467c8a57fc5b1f#a9f669d173807b80dde7ffef7f467c8a57fc5b1f" dependencies = [ "append-only-bytes", "arref", @@ -714,7 +714,7 @@ checksum = "3f3d053a135388e6b1df14e8af1212af5064746e9b87a06a345a7a779ee9695a" [[package]] name = "loro_fractional_index" version = "0.16.2" -source = "git+https://github.com/loro-dev/loro.git?rev=832bc6581b21efc2e6c7b46d2e3c78f85a128257#832bc6581b21efc2e6c7b46d2e3c78f85a128257" +source = "git+https://github.com/loro-dev/loro.git?rev=a9f669d173807b80dde7ffef7f467c8a57fc5b1f#a9f669d173807b80dde7ffef7f467c8a57fc5b1f" dependencies = [ "imbl", "rand", diff --git a/loro-rs/Cargo.toml b/loro-rs/Cargo.toml index 1c5d773..e806db7 100644 --- a/loro-rs/Cargo.toml +++ b/loro-rs/Cargo.toml @@ -15,7 +15,7 @@ path = "src/uniffi-bindgen.rs" [dependencies] # loro-ffi = { path = "../../loro/crates/loro-ffi" } -loro-ffi = { git = "https://github.com/loro-dev/loro.git", rev = "832bc6581b21efc2e6c7b46d2e3c78f85a128257" } +loro-ffi = { git = "https://github.com/loro-dev/loro.git", rev = "a9f669d173807b80dde7ffef7f467c8a57fc5b1f" } uniffi = { version = "0.28" } [build-dependencies] diff --git a/loro-rs/src/loro.udl b/loro-rs/src/loro.udl index 6f375c4..f04f0da 100644 --- a/loro-rs/src/loro.udl +++ b/loro-rs/src/loro.udl @@ -10,6 +10,12 @@ interface ValueOrContainer{ boolean is_container(); LoroValue? as_value(); ContainerID? as_container(); + LoroText? as_loro_text(); + LoroList? as_loro_list(); + LoroMap? as_loro_map(); + LoroTree? as_loro_tree(); + LoroCounter? as_loro_counter(); + LoroMovableList? as_loro_movable_list(); }; [Trait, WithForeign] diff --git a/scripts/refine_trait.sh b/scripts/refine_trait.sh index 05242d0..ff22a0d 100644 --- a/scripts/refine_trait.sh +++ b/scripts/refine_trait.sh @@ -5,13 +5,13 @@ THIS_SCRIPT_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" SWIFT_FOLDER="$THIS_SCRIPT_DIR/../gen-swift" file_path="$SWIFT_FOLDER/loro.swift" -search_string="public protocol LoroValueLike : AnyObject {" -replace_string="public protocol LoroValueLike : Any {" +search_string="public protocol LoroValueLike[[:space:]]*:[[:space:]]*AnyObject {" +replace_string="public protocol LoroValueLike: Any {" -sed -i '' "s|$search_string|$replace_string|g" "$file_path" +sed -i '' "s/$search_string/$replace_string/g" "$file_path" -search_string="public protocol ContainerIdLike : AnyObject {" -replace_string="public protocol ContainerIdLike : Any {" +search_string="public protocol ContainerIdLike[[:space:]]*:[[:space:]]*AnyObject {" +replace_string="public protocol ContainerIdLike: Any {" -sed -i '' "s|$search_string|$replace_string|g" "$file_path" +sed -i '' "s/$search_string/$replace_string/g" "$file_path"