Debian Codegraph @

third_party/rust/uniffi_bindgen/src/bindings/swift/templates/SequenceTemplate.swift

raw
1 #if swift(>=5.8)
2 @_documentation(visibility: private)
3 #endif
4 fileprivate struct {{ ffi_converter_name }}: FfiConverterRustBuffer {
5 typealias SwiftType = {{ type_name }}
6
7 public static func write(_ value: {{ type_name }}, into buf: inout [UInt8]) {
8 let len = Int32(value.count)
9 writeInt(&buf, len)
10 for item in value {
11 {{ inner_type|write_fn }}(item, into: &buf)
12 }
13 }
14
15 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> {{ type_name }} {
16 let len: Int32 = try readInt(&buf)
17 var seq = {{ type_name }}()
18 seq.reserveCapacity(Int(len))
19 for _ in 0 ..< len {
20 seq.append(try {{ inner_type|read_fn }}(from: &buf))
21 }
22 return seq
23 }
24 }