mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-29 03:40:01 +00:00
[Swift] Renaming protocols (#6469)
* Renaming protocols * Updates Generated code * format code
This commit is contained in:
@@ -26,7 +26,7 @@ public protocol FlatBufferObject {
|
||||
init(_ bb: ByteBuffer, o: Int32)
|
||||
}
|
||||
|
||||
public protocol ObjectAPI {
|
||||
public protocol ObjectAPIPacker {
|
||||
associatedtype T
|
||||
static func pack(_ builder: inout FlatBufferBuilder, obj: inout T) -> Offset<UOffset>
|
||||
mutating func unpack() -> T
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol UnionObject {}
|
||||
public protocol NativeObject {}
|
||||
|
||||
extension UnionObject {
|
||||
extension NativeObject {
|
||||
|
||||
/// Serialize is a helper function that serailizes the data from the Object API to a bytebuffer directly th
|
||||
/// - Parameter type: Type of the Flatbuffer object
|
||||
/// - Returns: returns the encoded sized ByteBuffer
|
||||
public func serialize<T: ObjectAPI>(type: T.Type) -> ByteBuffer where T.T == Self {
|
||||
public func serialize<T: ObjectAPIPacker>(type: T.Type) -> ByteBuffer where T.T == Self {
|
||||
var builder = FlatBufferBuilder(initialSize: 1024)
|
||||
return serialize(builder: &builder, type: type.self)
|
||||
}
|
||||
@@ -36,7 +36,7 @@ extension UnionObject {
|
||||
/// - Returns: returns the encoded sized ByteBuffer
|
||||
/// - Note: The `serialize(builder:type)` can be considered as a function that allows you to create smaller builder instead of the default `1024`.
|
||||
/// It can be considered less expensive in terms of memory allocation
|
||||
public func serialize<T: ObjectAPI>(builder: inout FlatBufferBuilder, type: T.Type) -> ByteBuffer where T.T == Self {
|
||||
public func serialize<T: ObjectAPIPacker>(builder: inout FlatBufferBuilder, type: T.Type) -> ByteBuffer where T.T == Self {
|
||||
var s = self
|
||||
let root = type.pack(&builder, obj: &s)
|
||||
builder.finish(offset: root)
|
||||
Reference in New Issue
Block a user