Swift FlatBufferBuilder.sizedByteArray to ByteBuffer.toArray() (#7093)

* Moved code from FlatBufferBuilder.sizedByteArray to ByteBuffer.toArray() in Swift

* ByteBuffer.toArray() to  ByteBuffer.underlyingBytes
This commit is contained in:
Matt Grippaldi
2022-02-11 16:26:16 -05:00
committed by GitHub
parent 48befb6bef
commit a94132a45f
2 changed files with 11 additions and 6 deletions

View File

@@ -80,12 +80,7 @@ public struct FlatBufferBuilder {
/// Should only be used after ``finish(offset:addPrefix:)`` is called
public var sizedByteArray: [UInt8] {
assert(finished, "Data shouldn't be called before finish()")
let cp = _bb.capacity &- _bb.writerIndex
let start = _bb.memory.advanced(by: _bb.writerIndex)
.bindMemory(to: UInt8.self, capacity: cp)
let ptr = UnsafeBufferPointer(start: start, count: cp)
return Array(ptr)
return _bb.underlyingBytes
}
/// Returns the original ``ByteBuffer``