[Swift] Object API support (#5826)

* Adds Object-api support to swift

* Fixed indentation issues

* Removed indentation within namespaces
This commit is contained in:
mustiikhalil
2020-04-13 19:28:56 +03:00
committed by GitHub
parent 003e164057
commit cb4d0f72e3
14 changed files with 2323 additions and 865 deletions

View File

@@ -53,7 +53,7 @@ public struct FlatBufferBuilder {
/// Returns A sized Buffer from the readable bytes
public var sizedBuffer: ByteBuffer {
assert(finished, "Data shouldn't be called before finish()")
return ByteBuffer(memory: _bb.memory.advanced(by: _bb.reader), count: _bb.reader)
return ByteBuffer(memory: _bb.memory.advanced(by: _bb.reader), count: Int(_bb.size))
}
// MARK: - Init
@@ -276,6 +276,24 @@ public struct FlatBufferBuilder {
return push(element: Int32(len))
}
/// Creates a vector of type Bool in the buffer
/// - Parameter elements: elements to be written into the buffer
/// - returns: Offset of the vector
mutating public func createVector(_ elements: [Bool]) -> Offset<UOffset> {
return createVector(elements, size: elements.count)
}
/// Creates a vector of type Bool in the buffer
/// - Parameter elements: Elements to be written into the buffer
/// - Parameter size: Count of elements
/// - returns: Offset of the vector
mutating public func createVector(_ elements: [Bool], size: Int) -> Offset<UOffset> {
let size = size
startVector(size, elementSize: MemoryLayout<Bool>.size)
_bb.push(elements: elements)
return Offset(offset: endVector(len: size))
}
/// Creates a vector of type Scalar in the buffer
/// - Parameter elements: elements to be written into the buffer
/// - returns: Offset of the vector