$ show apple/swift-protobuf
This is the official Swift implementation of Protocol Buffers from Apple. It produces a runtime library (`SwiftProtobuf`) for serializing/deserializing protobuf messages in binary, JSON, and text format, and a `protoc` plugin (`protoc-gen-swift`) that generates Swift source code from `.proto` files. The architecture is a set of Swift packages (SwiftProtobuf runtime, SwiftProtobufPluginLibrary, protoc-gen-swift) plus a vendored C++ protobuf implementation and Abseil for the plugin's host tool. Key entry points include the `Message` protocol and its extensions for encoding/decoding, the `BinaryDecoder`/`BinaryEncoder` for wire format handling, and the plugin's `CodeGenerator` implementation. External dependencies are `protoc` (the protobuf compiler) for code generation and the vendored protobuf/abseil C++ sources for the custom `protoc` binary. The repository also includes comprehensive test suites, fuzz testing harnesses, and conformance test runner, ensuring robust compatibility across languages.
The LLM identified 3 files worth highlighting for reuse:
Defines the `CodeGenerator` protocol and `CodeGeneratorRequest`/`CodeGeneratorResponse` handling for protoc plugins. This is a clean, reusable abstraction for building code generators in Swift. It uses the visitor pattern internally and handles the entire plugin lifecycle (request parsing, response generation). A developer could extract this to build a custom protoc plugin with minimal modification.
Implements the binary protobuf wire format decoder with support for varint, fixed-size, length-delimited, and group types. It uses an internal buffer pointer and provides both sequential and skip operations. The decoder is independent of message types and can be reused in any Swift project needing protobuf binary parsing, including streaming via `BinaryDelimited`.
Parses double values from UTF-8 bytes without relying on the system locale, avoiding common pitfalls with strtod. It implements a fast, branch-heavy parser that handles NaN, inf, hex floats, and many decimal forms. This is a self-contained utility that can be extracted for securely parsing doubles from wire data.