Skip to content

Commit

Permalink
fix: script and value or container
Browse files Browse the repository at this point in the history
  • Loading branch information
Leeeon233 committed Aug 10, 2024
1 parent 40ac87f commit 13b9117
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 16 deletions.
202 changes: 200 additions & 2 deletions Sources/Loro/LoroFFI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ fileprivate struct FfiConverterData: FfiConverterRustBuffer {



public protocol ContainerIdLike : Any {
public protocol ContainerIdLike: Any {

func asContainerId(ty: ContainerType) -> ContainerId

Expand Down Expand Up @@ -4094,7 +4094,7 @@ public func FfiConverterTypeLoroUnknown_lower(_ value: LoroUnknown) -> UnsafeMut



public protocol LoroValueLike : Any {
public protocol LoroValueLike: Any {

func asLoroValue() -> LoroValue

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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?

Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 7 additions & 7 deletions loro-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion loro-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions loro-rs/src/loro.udl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 6 additions & 6 deletions scripts/refine_trait.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 13b9117

Please sign in to comment.