Protocol Buffers for Swift
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 3.0
How To Install Protobuf Compiler on Linux(Ubuntu 14.04)
1.wget https://github.com/google/protobuf/archive/v3.2.0.tar.gz
2.tar xzf v3.2.0.tar.gz
3.cd protobuf-3.2.0/
4.sudo apt-get install autoreconf automake libtool make
5../autogen.sh
6../configure CXXFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib
7.sudo make && sudo make install
8.cd .. && wget https://github.com/alexeyxo/protobuf-swift/archive/3.0.9.tar.gz && tar xzf 3.0.9.tar.gz && cd protobuf-swift-3.0.9
9../script/build.sh && swift build
How To Install Protobuf Compiler from Homebrew
1.ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.brew install protobuf-swift
How To Install Protobuf Compiler
1.ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.brew install automake
3.brew install libtool
4.brew install protobuf
5.git clone git@github.com:alexeyxo/protobuf-swift.git
6../scripts/build.sh
Add ./src/ProtocolBuffers/ProtocolBuffers.xcodeproj
in your project.
Cocoapods
Podfile:
Installation via Carthage
Cartfile:
github "alexeyxo/protobuf-swift"
Compile ".proto" files.
Serializing
Chaining
Sub Builders
Maps(ProtocolBuffers 3.0)
JSON(proto3)
Deserializing
Using Oneof
Nested Types
Packages
Custom Options
At now protobuf-swift's compiler is supporting custom options.
- Class Prefix
- Access Control
- Error Types
- Compile for framework
If you have use custom options, you need to add:
in your .proto
files.
Class prefix
This option needs to generate class names with prefix.
Example:
Generated class has a name:
Access control
All generated classes marks as internal
by default. If you want mark as public
, you can use entities_access_control
option.
Generated class and all fields are marked a public
:
Generate enum/message conforming to "Error" protocol
Example
Compile for framework
This option deletes the string import ProtocolBuffers
of the generated files.
If you will need some other options, write me. I will add them.
Utilities (ProtocolBuffers 3.0)
Added well-known type protos (any.proto, empty.proto, timestamp.proto, duration.proto, etc.). Users can import and use these protos just like regular proto files. Addtional runtime support will be added for them in future releases (in the form of utility helper functions, or having them replaced by language specific types in generated code).
Any
API
Duration
Empty
Field Mask
Source context
Struct
Timestamp
Type
Wrappers
Credits
Developer - Alexey Khokhlov
Google Protocol Buffers - Cyrus Najmabadi, Sergey Martynov, Kenton Varda, Sanjay Ghemawat, Jeff Dean, and others