diff options
Diffstat (limited to 'third_party/rust/uniffi_bindgen/src/bindings/swift/templates/DataHelper.swift')
-rw-r--r-- | third_party/rust/uniffi_bindgen/src/bindings/swift/templates/DataHelper.swift | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/DataHelper.swift b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/DataHelper.swift new file mode 100644 index 0000000000..7db240bf9c --- /dev/null +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/DataHelper.swift @@ -0,0 +1,14 @@ +fileprivate struct FfiConverterData: FfiConverterRustBuffer { + typealias SwiftType = Data + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Data { + let len: Int32 = try readInt(&buf) + return Data(try readBytes(&buf, count: Int(len))) + } + + public static func write(_ value: Data, into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + writeBytes(&buf, value) + } +} |