apple /swift-protobuf

Plugin and runtime library for using protobuf with Swift

★ 4,972⑂ 550👁 97⑃ 1,678● 553▤ 73
SwiftApache-2.0Created 2016-09-02
Download: 1.41.0 Release1.41.0 ↓1.41.02026-11-13
+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 worked

Top issues

Latest release

1.41.0 Release 1.41.0 2026-11-13
What'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

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON