apple /swift-protobuf
Plugin and runtime library for using protobuf with Swift
★ 4,972⑂ 550👁 97⑃ 1,678● 553▤ 73
+0
Daily
4,972
stars
550
forks
97
watchers
1,678
prs
553
issues
73
releases
README
Swift Protobuf
Welcome to Swift Protobuf!
Apple's Swift programming language is a perfect
complement to Google's Protocol Buffer
("protobuf") serialization technology.
They both emphasize high performance and programmer safety.
This project provides both the command-line program that adds Swift
code generation to Google's protoc and the runtime library that is
necessary for using the generated code.
After using the protoc plugin to generate Swift code from your .proto
files, you will need to add this library to your project.
Features of SwiftProtobuf
SwiftProtobuf offers many advantages over alternative serialization
systems:
Safety: The protobuf code-generation system avoids the
errors that are common with hand-built serialization code.
Correctness: SwiftProtobuf passes both its own extensive
test suite and Google's full conformance test for protobuf
correctness.
Schema-driven: Defining your data structures in a separate
.proto schema file clearly documents your communications
conventions.
Idiomatic: SwiftProtobuf takes full advantage of the Swift language.
In particular, all generated types provide full Swift copy-on-write
value semantics.
Efficient binary serialization: The .serializedBytes()
method returns a bag of bytes with a compact binary form of your data.
You can deserialize the data using the init(contiguousBytes:)
initializer.
Standard JSON serialization: The .jsonUTF8Bytes() method returns a JSON
form of your data that can be parsed with the init(jsonUTF8Bytes:)
initializer.
Hashable, Equatable: The generated struct can be put into a
Set< or Dictionary<.
Performant: The binary and JSON serializers have been
extensively optimized.
Extensible: You can add your own Swift extensions to any
of the generated types.
Best of all, you can take the same .proto file and generate
Java, C++, Python, or Objective-C for use on other platforms. The
generated code for those languages will use the exact same
serialization and deserialization conventions as SwiftProtobuf, making
it easy to exchange serialized data in binary or JSON forms, with no
additional effort on your part.
Documentation
More information is available in the associated documentation:
Google's protobuf documentation
provides general information about protocol buffers, the protoc compiler,
and how to use protocol buffers with C++, Java, and other languages.
PLUGIN.md documents the protoc-gen-swift
plugin that adds Swift support to the protoc program
API.md documents how to use the generated code.
This is recommended reading for anyone using SwiftProtobuf in their
project.
INTERNALS.md documents the internal structure
of the generated code and the library. This
should only be needed by folks interested in working on SwiftProtobuf
itself.
STYLE_GUIDELINES.md documents the style
guidelines we have adopted in our codebase if you are interested in
contributing
Getting Started
If you've workedTop issues
#861JSON Serialization with default value 60 comments · 2019-04-03#1101Linking against static library that uses SwiftProtobuf causes linker errors44 comments · 2020-12-23#151Support deprecated annotation on messages, fields, enums, enum values.21 comments · 2016-12-01#713Current use of serializedDataSize() in serializedData() causes additional runtime linear in the depth of the proto hierarchy19 comments · 2018-01-18#1014EXC_BAD_ACCESS on NameMap init17 comments · 2020-06-24#731Read access to NameMap mapping.17 comments · 2018-03-23#733_StorageClass makes large arrays of non-trivial messages impractical.15 comments · 2018-04-05#130Provide something for parsing a binary stream of protobuf data15 comments · 2016-10-31
Latest release
1.41.0 Release 1.41.0 2026-11-13What's Changed SemVer Minor reject duplicate singular fields in TextFormat by @mvanhorn in https://github.com/apple/swift-protobuf/pull/2213 Version bump for a relase by @thomasvl in https://github.com/apple/swift-protobuf/pull/2239 SemVer Patch Reconstruct descriptor protos on demand in extractProto() by @thomasvl in https://github.com/apple/swift-protobuf/pull/2233 Fix Any depth budget CoW handling and WKT contentJSON textTraverse limit by @thomasvl in https://github.com/apple/swift-protobuf/pull/2237 Accept JSON Timestamp offsets up to ±23:59 by @0z5a in https://github.com/app