mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-04 08:51:10 +00:00
[Swift] Implements FlatbuffersVector which confirms to RandomAccessCollection (#8752)
* Implements FlatbuffersVector in swift Implements FlatbuffersVector which confirms to RandomAccessCollection, this would give us semi-native sugary syntax to all the arrays in swift port. This work will also be the foundation of using arrays in swift * Fix failing tests for Swift
This commit is contained in:
@@ -28,20 +28,20 @@ public protocol FlatBufferGRPCMessage {
|
||||
@inline(__always)
|
||||
func withUnsafeReadableBytes<T>(
|
||||
_ body: (UnsafeRawBufferPointer) throws
|
||||
-> T
|
||||
) rethrows -> T
|
||||
-> T) rethrows -> T
|
||||
}
|
||||
|
||||
/// Message is a wrapper around Buffers to to able to send Flatbuffers `Buffers` through the
|
||||
/// GRPC library
|
||||
public struct Message<T: FlatBufferObject>: FlatBufferGRPCMessage {
|
||||
public struct Message<T: FlatBufferTable>: FlatBufferGRPCMessage {
|
||||
internal var buffer: ByteBuffer
|
||||
|
||||
/// Returns the an object of type T that would be read from the buffer
|
||||
public var object: T {
|
||||
T.init(
|
||||
buffer,
|
||||
o: Int32(buffer.read(def: UOffset.self, position: buffer.reader)) &+ Int32(buffer.reader))
|
||||
o: Int32(buffer.read(def: UOffset.self, position: buffer.reader)) &+
|
||||
Int32(buffer.reader))
|
||||
}
|
||||
|
||||
public var size: Int { Int(buffer.size) }
|
||||
@@ -66,8 +66,8 @@ public struct Message<T: FlatBufferObject>: FlatBufferGRPCMessage {
|
||||
@inline(__always)
|
||||
public func withUnsafeReadableBytes<Data>(
|
||||
_ body: (UnsafeRawBufferPointer) throws
|
||||
-> Data
|
||||
) rethrows -> Data {
|
||||
-> Data) rethrows -> Data
|
||||
{
|
||||
return try buffer.readWithUnsafeRawPointer(position: buffer.reader) {
|
||||
try body(UnsafeRawBufferPointer(start: $0, count: size))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user