GithubHelp home page GithubHelp logo

igorcferreira / protobuf-swift Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alexeyxo/protobuf-swift

0.0 1.0 0.0 2.43 MB

ProtocolBuffers for Apple Swift

Home Page: http://protobuf.io/#swift

License: Apache License 2.0

Shell 0.07% C++ 1.63% Swift 98.14% C 0.16%

protobuf-swift's Introduction

#Protocol Buffers for Swift Build Status Platform Release

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

How To Install Protobuf

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 [email protected]:alexeyxo/protobuf-swift.git

6../scripts/build.sh

7.Add ./src/ProtocolBuffers/ProtocolBuffers.xcodeproj in your project.

Compile ".proto" files.

protoc person.proto --swift_out="./"

Serializing

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 = "[email protected]"
let person = personBuilder.build()
println("\(person)")

person.data() //return [Byte]
person.getNSData() //Return NSData

Deserializing

var person = Person.builder().parseFromData(bytes).build() // from [Byte]

Using Oneof

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

Nested Types

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())

Credits

Developer

  • Alexey Khokhlov

Google Protocol Buffers

  • Cyrus Najmabadi, Sergey Martynov, Kenton Varda, Sanjay Ghemawat, Jeff Dean, and others

protobuf-swift's People

Contributors

alexeyxo avatar alecthomas avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.