An implementation of Protocol Buffers in Swift.
Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. This project is based on an implementation of Protocol Buffers from Google. See the Google protobuf project for more information.
####Required Protocol Buffers 2.6
1.ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.brew install automake
3.brew install libtool
4.brew instal protobuf
5.git clone git@github.com:alexeyxo/protobuf-swift.git
6../scripts/build.sh
7.Add ./src/ProtocolBuffers/ProtocolBuffers.xcodeproj
in your project.
protoc person.proto --swift_out="./"
message Person {
required int32 id = 1;
required string name = 2;
optional string email = 3;
}
let personBuilder = Person.builder()
personBuilder.id = 123
personBuilder.name = "Bob"
personBuilder.email = "bob@example.com"
let person = personBuilder.build()
println("\(person)")
person.data() //return [Byte]
person.getNSData() //Return NSData
message SubMessage {
optional string str = 1;
}
message SampleMessage {
oneof test_oneof {
string name = 4;
int32 id = 5;
SubMessage mes = 6;
}
}
var sm = SampleMessage.builder()
sm.name = "Alex"
sm.id = 123
println(ss.build()) //-> id: 123
message SearchResponse {
message Result {
required string url = 1;
optional string title = 2;
repeated string snippets = 3;
}
repeated Result result = 1;
}
var builderResult = SearchResponse.Result.builder()
builderResult.url = "http://protobuf.axo.io"
builderResult.title = "Protocol Bufers Apple Swift"
var searchRespons = SearchResponse.builder()
searchRespons.result += [builderResult.build()]
println(searchRespons.build())
Developer
- Alexey Khokhlov
Google Protocol Buffers
- Cyrus Najmabadi, Sergey Martynov, Kenton Varda, Sanjay Ghemawat, Jeff Dean, and others