Consider adding protocols for root class serialization&deserialization
hassila opened this issue · comments
Joakim Hassila commented
To allow generic handling of Flatbuffers compatible entities regardless of which root class they belong to, something like:
public protocol FlatBufferDeserializable {
static func fromByteArray(data : UnsafeBufferPointer<UInt8>, config : BinaryReadConfig) -> Self
static func fromRawMemory(data : UnsafeMutablePointer<UInt8>, count : Int, config : BinaryReadConfig) -> Self
static func fromFlatBufferReader(flatBufferReader : FlatBufferReader) -> Self
}
public protocol FlatBuffersSerializable {
func toByteArray (config : BinaryBuildConfig) -> [UInt8]
func toFlatBufferBuilder (builder : FlatBufferBuilder) -> Void
}
public protocol FlatBuffersCompatible : FlatBuffersSerializable, FlatBufferDeserializable {}
And having the root class (ContactList, FoobarContainer, ...) adopt FlatBuffersCompatible with
public extension FooBarContainer : FlatBuffersCompatible {}
The protocols might be tweaked as the API evolves a bit, but that would be the general idea.
To make it truly useful, it might need a dynamic reflection API - have you thought anything about that?
Thoughts?