[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

@@ -131,6 +131,16 @@ public struct ByteBuffer {
push(value: s, len: MemoryLayout.size(ofValue: s))
}
}
///Adds an array of type Bool to the buffer memory
/// - Parameter elements: An array of Bool
@usableFromInline mutating func push(elements: [Bool]) {
let size = elements.count * MemoryLayout<Bool>.size
ensureSpace(size: UInt32(size))
elements.lazy.reversed().forEach { (s) in
push(value: s ? 1 : 0, len: MemoryLayout.size(ofValue: s))
}
}
/// A custom type of structs that are padded according to the flatbuffer padding,
/// - Parameters:
@@ -174,8 +184,6 @@ public struct ByteBuffer {
/// - len: Size of string
@usableFromInline mutating internal func push(bytes: UnsafeBufferPointer<String.UTF8View.Element>, len: Int) -> Bool {
memcpy(_storage.memory.advanced(by: writerIndex - len), UnsafeRawPointer(bytes.baseAddress!), len)
// _memory.advanced(by: writerIndex - len).copyMemory(from:
// UnsafeRawPointer(bytes.baseAddress!), byteCount: len)
_writerSize += len
return true
}