转载

[iOS] FlatBuffersSwift:Swift 版 FlatBuffers 实现类库

FlatBuffersSwift

[iOS] FlatBuffersSwift:Swift 版 FlatBuffers 实现类库 [iOS] FlatBuffersSwift:Swift 版 FlatBuffers 实现类库

Motivation

This project brings FlatBuffers (an efficient cross platform serialization library) to Swift.

One minute introduction

There are three simple steps for you to use FlatBuffersSwift

1. Write a schema file

table List {   people : [Person]; }  table Person {   firstName : string;   lastName : string; }  root_type List; 

2. Generate Swift code

java -jar fbsCG.jar -fbs contacts.fbs -out contacts.swift -lang swift

3. Use the generated API

Create objects and write them to file

let p1 = Person(firstName: "Maxim", lastName: "Zaks") let p2 = Person(firstName: "Alex", lastName: "Zaks") let list = List(people: [p1, p2]) let fbData = list.toByteArray NSData(bytes: UnsafePointer<UInt8>(fbData), length: fbData.count).writeToFile("list.bin", atomically: true)

Read data from file very efficiently (no parsing, lazy instantiation)

let lazyList = List.LazyAccess(data: UnsafePointer((NSData(contentsOfFile: "list.bin")?.bytes)!)) let name = lazyList.people[0]?.firstName

Please check outWiki for more information.

原文  https://github.com/mzaks/FlatBuffersSwift
正文到此结束
Loading...