Library Moduleswift-protobuf 1.28.1SwiftProtobufPluginLibrary
SwiftProtobufPluginLibrary
A reusable framework for building protoc
plugins in Swift.
import SwiftProtobufPluginLibrary
Module information
- Declarations
- 437
- Symbols
- 753
Overview
The protoc-gen-swift
program is run by protoc
to generate Swift code from the parsed proto data. This library encapsulates many of the common elements needed to build such programs. It’s separated out here so that other people can reuse it.
Uncategorized
Protocols
protocol CodeGenerator
A protocol that generator should conform to then get easy support for being a protocol buffer compiler pluign.
protocol CodeGeneratorParameter
The the generator specific parameter that was passed to the protocol compiler invocation. The protocol buffer compiler supports providing parameters via the
--[LANG]_out
or--[LANG]_opt
command line flags. The compiler will relay those through as a parameter string.protocol GeneratorOutputs
Abstract interface for receiving generation outputs.
protocol ProtoCompilerContext
Abstact interface to get information about the protocol buffer compiler being used for generation.
protocol ProvidesDeprecationComment
Protocol that all the Descriptors conform to provide deprecation comments
protocol ProvidesLocationPath
Protocol that all the Descriptors conform to for original .proto file location lookup.
protocol ProvidesSourceCodeLocation
Protocol that all the Descriptors conform to for original .proto file location lookup.
protocol SimpleProvidesDeprecationComment
Protocol that a Descriptor can confirm to when only the Type controls depecation.
protocol TypeOrFileProvidesDeprecationComment
Protocol that a Descriptor can confirm to when the Type or the File controls depecation.
Types
struct CodePrinter
Prints code with automatic indentation based on calls to
indent
andoutdent
.class Descriptor
Describes a type of protocol message, or a particular group within a message.
Descriptor
s are not directly created, instead they are constructed/fetched via theDescriptorSet
or they are directly accessed via amessageType
property onFieldDescriptor
s, etc.class DescriptorSet
The front interface for building/getting descriptors. The objects vended from the here are different from the raw
Google_Protobuf_*Proto
types in that they have all the cross object references resolved or wired up, making for an easier to use object model.class EnumDescriptor
Describes a type of protocol enum.
EnumDescriptor
s are not directly created, instead they are constructed/fetched via theDescriptorSet
or they are directly accessed via aEnumType
property onFieldDescriptor
s, etc.class EnumValueDescriptor
Describes an individual enum constant of a particular type. To get the
EnumValueDescriptor
for a given enum value, first get theEnumDescriptor
for its type.struct ExtractProtoOptions
Options for collected a proto object from a Descriptor.
class FieldDescriptor
Describes a single field of a message. To get the descriptor for a given field, first get the
Descriptor
for the message in which it is defined, then find the field. To get aFieldDescriptor
for an extension, get theDescriptor
orFileDescriptor
for its containing scope, find the extension.class FileDescriptor
Models a .proto file.
FileDescriptor
s are not directly created, instead they are constructed/fetched via theDescriptorSet
or they are directly accessed via afile
property on all the other types of descriptors.struct Google_Protobuf_Compiler_CodeGeneratorRequest
An encoded CodeGeneratorRequest is written to the plugin’s stdin.
struct Google_Protobuf_Compiler_CodeGeneratorResponse
The plugin writes an encoded CodeGeneratorResponse to stdout.
struct Google_Protobuf_Compiler_Version
The version number of protocol compiler.
class MethodDescriptor
Describes an individual service method.
enum NamingUtils
class OneofDescriptor
Describes a oneof defined in a message type.
struct ProtoFileToModuleMappings
Handles the mapping of proto files to the modules they will be compiled into.
class ServiceDescriptor
Describes an RPC service.
enum SwiftProtobufInfo
Helpers about the library.
class SwiftProtobufNamer
struct SwiftProtobuf_GenSwift_ModuleMappings
Configuration used to define the mappings for generated proto files to the Swift module they will be included in.
Globals
let swiftCommonTypes: Set<String>
These are standard Swift types that are heavily used, although they are not technically reserved. Defining fields or structs with these names would break our generated code quite badly:
let swiftKeywordsReservedInParticularContexts: Set<String>
let swiftKeywordsUsedInDeclarations: Set<String>
These lists of keywords are taken directly from the Swift language spec. See:
let swiftKeywordsUsedInExpressionsAndTypes: Set<String>
let swiftKeywordsUsedInStatements: Set<String>
let swiftKeywordsWithNumberSign: Set<String>
let swiftSpecialVariables: Set<String>
Special magic variables defined by the compiler that we don’t really want to interfere with:
func generateCode(request: Google_Protobuf_Compiler_CodeGeneratorRequest, generator: any CodeGenerator
) -> Google_Protobuf_Compiler_CodeGeneratorResponse Uses the given
Google_Protobuf_Compiler_CodeGeneratorRequest
andCodeGenerator
to get code generated and create theGoogle_Protobuf_Compiler_CodeGeneratorResponse
. If there is a failure, the failure will be used in the response to be returned to the protocol buffer compiler to then be reported.func isValidSwiftIdentifier(String, allowQuoted: Bool
) -> Bool Use this to check whether a generated identifier is actually valid for use in generated Swift code.
Other modules
SwiftProtobuf
Support library for Swift code generated by protoc-gen-swift.
SwiftProtobufPluginplugin
protoc-gen-swiftexecutable
Code generation helper for use with Google’s
protoc
command.