神刀安全网

[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.

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » [iOS] FlatBuffersSwift:Swift 版 FlatBuffers 实现类库

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址