diff --git a/README.md b/README.md index d841ee1e35..8848da0005 100644 --- a/README.md +++ b/README.md @@ -551,7 +551,6 @@ Swift is a pragmatic and expressive programming language with rich support for v Here's how we used Swift to model Protocol Buffers messages: * Messages are structs that conform to `Equatable`, `Codable` and `Sendable`. All Messages have value semantics. - * Messages have a memberwise initializer to populate fields. * Fields are generated as properties. * The nullability of each field's type depends on its label: `required`, `repeated` and `map` fields get non-nullable types, whereas `optional` fields are of nullable types. @@ -576,12 +575,22 @@ public struct Dinosaur { /** * URLs with images of this dinosaur. */ - public var picture_urls: [String] + public var picture_urls: [String] = [] public var length_meters: Double? public var mass_kilograms: Double? public var period: Period? - public var unknownFields: Data = .init() + public var unknownFields: Foundation.Data = .init() + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension Dinosaur { + + @_disfavoredOverload public init( name: String? = nil, picture_urls: [String] = [], @@ -597,6 +606,7 @@ public struct Dinosaur { } } +#endif #if !WIRE_REMOVE_EQUATABLE extension Dinosaur : Equatable { @@ -614,12 +624,15 @@ extension Dinosaur : Sendable { #endif extension Dinosaur : ProtoMessage { + public static func protoMessageTypeURL() -> String { return "type.googleapis.com/squareup.dinosaurs.Dinosaur" } + } extension Dinosaur : Proto2Codable { + public init(from reader: ProtoReader) throws { var name: String? = nil var picture_urls: [String] = [] @@ -655,10 +668,12 @@ extension Dinosaur : Proto2Codable { try writer.encode(tag: 5, value: self.period) try writer.writeUnknownFields(unknownFields) } + } #if !WIRE_REMOVE_CODABLE extension Dinosaur : Codable { + public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: StringLiteralCodingKeys.self) self.name = try container.decodeIfPresent(String.self, forKey: "name") @@ -681,6 +696,7 @@ extension Dinosaur : Codable { try container.encodeIfPresent(self.mass_kilograms, forKey: preferCamelCase ? "massKilograms" : "mass_kilograms") try container.encodeIfPresent(self.period, forKey: "period") } + } #endif ``` @@ -688,10 +704,10 @@ extension Dinosaur : Codable { Creating and accessing proto models is easy: ```swift -let stegosaurus = Dinosaur( - name: "Stegosaurus", - period: .JURASSIC -) +let stegosaurus = Dinosaur { + $0.name = "Stegosaurus" + $0.period = .JURASSIC +} print("My favorite dinosaur existed in the \(stegosaurus.period) period.") ``` diff --git a/wire-runtime-swift/src/test/swift/CodableTests.swift b/wire-runtime-swift/src/test/swift/CodableTests.swift index 23f8739282..02c797f18f 100644 --- a/wire-runtime-swift/src/test/swift/CodableTests.swift +++ b/wire-runtime-swift/src/test/swift/CodableTests.swift @@ -44,20 +44,20 @@ extension CodableTests { } """ - let expected = SimpleOptional2( - opt_int32: 1, - opt_int64: 2, - opt_uint32: 3, - opt_uint64: 4, - opt_float: 5, - opt_double: 6, - opt_bytes: Foundation.Data(hexEncoded: "0123456"), - opt_string: "foo", - opt_enum: .UNKNOWN, - repeated_int32: [1, 2, 3], - repeated_string: ["foo", "bar", "baz"], - map_int32_string: [1: "foo", 2: "bar"] - ) + let expected = SimpleOptional2 { + $0.opt_int32 = 1 + $0.opt_int64 = 2 + $0.opt_uint32 = 3 + $0.opt_uint64 = 4 + $0.opt_float = 5 + $0.opt_double = 6 + $0.opt_bytes = Foundation.Data(hexEncoded: "0123456") + $0.opt_string = "foo" + $0.opt_enum = .UNKNOWN + $0.repeated_int32 = [1, 2, 3] + $0.repeated_string = ["foo", "bar", "baz"] + $0.map_int32_string = [1: "foo", 2: "bar"] + } try assertDecode(json: json, expected: expected) } @@ -92,11 +92,12 @@ extension CodableTests { req_double: 6, req_bytes: Foundation.Data(hexEncoded: "0123456")!, req_string: "foo", - req_enum: .UNKNOWN, - repeated_int32: [1, 2, 3], - repeated_string: ["foo", "bar", "baz"], - map_int32_string: [1: "foo", 2: "bar"] - ) + req_enum: .UNKNOWN + ) { + $0.repeated_int32 = [1, 2, 3] + $0.repeated_string = ["foo", "bar", "baz"] + $0.map_int32_string = [1: "foo", 2: "bar"] + } try assertDecode(json: json, expected: expected) } @@ -107,20 +108,20 @@ extension CodableTests { extension CodableTests { func testEncodeOptional() throws { // Only include one value in maps until https://bugs.swift.org/browse/SR-13414 is fixed. - let proto = SimpleOptional2( - opt_int32: 1, - opt_int64: 2, - opt_uint32: 3, - opt_uint64: 4, - opt_float: 5, - opt_double: 6, - opt_bytes: Foundation.Data(hexEncoded: "0123456"), - opt_string: "foo", - opt_enum: .UNKNOWN, - repeated_int32: [1, 2, 3], - repeated_string: ["foo", "bar", "baz"], - map_int32_string: [1: "foo"] - ) + let proto = SimpleOptional2 { + $0.opt_int32 = 1 + $0.opt_int64 = 2 + $0.opt_uint32 = 3 + $0.opt_uint64 = 4 + $0.opt_float = 5 + $0.opt_double = 6 + $0.opt_bytes = Foundation.Data(hexEncoded: "0123456") + $0.opt_string = "foo" + $0.opt_enum = .UNKNOWN + $0.repeated_int32 = [1, 2, 3] + $0.repeated_string = ["foo", "bar", "baz"] + $0.map_int32_string = [1: "foo"] + } let expected = """ { @@ -155,11 +156,12 @@ extension CodableTests { req_double: 6, req_bytes: Foundation.Data(hexEncoded: "0123456")!, req_string: "foo", - req_enum: .UNKNOWN, - repeated_int32: [1, 2, 3], - repeated_string: ["foo", "bar", "baz"], - map_int32_string: [1: "foo"] - ) + req_enum: .UNKNOWN + ) { + $0.repeated_int32 = [1, 2, 3] + $0.repeated_string = ["foo", "bar", "baz"] + $0.map_int32_string = [1: "foo"] + } let expected = """ { @@ -244,12 +246,12 @@ extension CodableTests { } """ - let proto = SimpleOptional2( - opt_double: 6, - opt_enum: .A, - repeated_string: ["B"], - map_int32_string: [1 : "foo"] - ) + let proto = SimpleOptional2 { + $0.opt_double = 6 + $0.opt_enum = .A + $0.repeated_string = ["B"] + $0.map_int32_string = [1 : "foo"] + } try assertEncode(proto: proto, expected: json) } @@ -269,13 +271,13 @@ extension CodableTests { } """ - let proto = SimpleOptional2( - opt_int64: 5, - opt_double: 6, - opt_enum: .A, - repeated_string: ["B"], - map_int32_string: [1 : "foo"] - ) + let proto = SimpleOptional2 { + $0.opt_int64 = 5 + $0.opt_double = 6 + $0.opt_enum = .A + $0.repeated_string = ["B"] + $0.map_int32_string = [1 : "foo"] + } try assertDecode(json: json, expected: proto) } @@ -285,7 +287,10 @@ extension CodableTests { extension CodableTests { func testHeapRoundtrip() throws { - let proto = SwiftStackOverflow(value3: "hello") + let proto = SwiftStackOverflow { + $0.value3 = "hello" + } + let json = """ { "value3":"hello" diff --git a/wire-runtime-swift/src/test/swift/DefaultedTests.swift b/wire-runtime-swift/src/test/swift/DefaultedTests.swift index ddc2f42904..c628c3479c 100644 --- a/wire-runtime-swift/src/test/swift/DefaultedTests.swift +++ b/wire-runtime-swift/src/test/swift/DefaultedTests.swift @@ -25,13 +25,17 @@ final class DefaultedTests: XCTestCase { } func testProjectedValueIsWrappedValue() throws { - let phoneNumber = Person.PhoneNumber(number: "1234567890", type: Person.PhoneType.WORK) + let phoneNumber = Person.PhoneNumber(number: "1234567890") { + $0.type = .WORK + } XCTAssertEqual(phoneNumber.type, Person.PhoneType.WORK) XCTAssertEqual(phoneNumber.$type, Person.PhoneType.WORK) } func testProjectedValueWhenResettingWrappedValue() throws { - var phoneNumber = Person.PhoneNumber(number: "1234567890", type: Person.PhoneType.WORK) + var phoneNumber = Person.PhoneNumber(number: "1234567890") { + $0.type = .WORK + } XCTAssertEqual(phoneNumber.type, Person.PhoneType.WORK) XCTAssertEqual(phoneNumber.$type, Person.PhoneType.WORK) phoneNumber.type = nil diff --git a/wire-runtime-swift/src/test/swift/ProtoReaderTests.swift b/wire-runtime-swift/src/test/swift/ProtoReaderTests.swift index 5f1185f6d8..48437e76fe 100644 --- a/wire-runtime-swift/src/test/swift/ProtoReaderTests.swift +++ b/wire-runtime-swift/src/test/swift/ProtoReaderTests.swift @@ -159,7 +159,10 @@ final class ProtoReaderTests: XCTestCase { 00 // Length 0 """)! try test(data: data) { reader in - let expected = Parent(name: "Bob", child: .init()) + let expected = Parent { + $0.name = "Bob" + $0.child = .init() + } XCTAssertEqual(try reader.decode(Parent.self), expected) } } @@ -327,7 +330,10 @@ final class ProtoReaderTests: XCTestCase { 01 // Value 1 """)! try test(data: data, enumStrategy: .returnNil) { reader in - let message = OneOfs(standalone_enum: OneOfs.NestedEnum.A, choice: OneOfs.Choice.similar_enum_option(OneOfs.NestedEnum.A)) + let message = OneOfs { + $0.standalone_enum = .A + $0.choice = .similar_enum_option(.A) + } XCTAssertEqual(try reader.decode(OneOfs.self), message) } } @@ -340,7 +346,9 @@ final class ProtoReaderTests: XCTestCase { 02 // Value 2 """)! try test(data: data, enumStrategy: .returnNil) { reader in - let message = OneOfs(standalone_enum: OneOfs.NestedEnum.A, choice: nil) + let message = OneOfs { + $0.standalone_enum = .A + } XCTAssertEqual(try reader.decode(OneOfs.self), message) } } diff --git a/wire-runtime-swift/src/test/swift/ProtoWriterTests.swift b/wire-runtime-swift/src/test/swift/ProtoWriterTests.swift index a86644e7c8..677375ad5b 100644 --- a/wire-runtime-swift/src/test/swift/ProtoWriterTests.swift +++ b/wire-runtime-swift/src/test/swift/ProtoWriterTests.swift @@ -123,20 +123,20 @@ final class ProtoWriterTests: XCTestCase { func testEncodeDefaultProto2Values() throws { let writer = ProtoWriter() - let proto = SimpleOptional2( - opt_int32: 0, - opt_int64: 0, - opt_uint32: 0, - opt_uint64: 0, - opt_float: 0, - opt_double: 0, - opt_bytes: .init(), - opt_string: "", - opt_enum: .UNKNOWN, - repeated_int32: [], - repeated_string: [], - map_int32_string: [:] - ) + let proto = SimpleOptional2 { + $0.opt_int32 = 0 + $0.opt_int64 = 0 + $0.opt_uint32 = 0 + $0.opt_uint64 = 0 + $0.opt_float = 0 + $0.opt_double = 0 + $0.opt_bytes = .init() + $0.opt_string = "" + $0.opt_enum = .UNKNOWN + $0.repeated_int32 = [] + $0.repeated_string = [] + $0.map_int32_string = [:] + } try writer.encode(tag: 1, value: proto) // All values are encoded in proto2, including defaults. @@ -191,11 +191,12 @@ final class ProtoWriterTests: XCTestCase { req_double: 0, req_bytes: .init(), req_string: "", - req_enum: .UNKNOWN, - repeated_int32: [], - repeated_string: [], - map_int32_string: [:] - ) + req_enum: .UNKNOWN + ) { + $0.repeated_int32 = [] + $0.repeated_string = [] + $0.map_int32_string = [:] + } try writer.encode(tag: 1, value: proto) // No data should be encoded. Just the top-level message tag with a length of zero. @@ -551,7 +552,10 @@ final class ProtoWriterTests: XCTestCase { func testEncodePackedRepeatedProto2Default() throws { let writer = ProtoWriter() let data = Data(json_data: "12") - let person = Person(name: "name", id: 1, email: "email", ids: [1, 2, 3], data: data) + let person = Person(name: "name", id: 1, data: data) { + $0.email = "email" + $0.ids = [1, 2, 3] + } try writer.encode(tag: 1, value: person) // Proto2 should used "packed: false" by default. @@ -583,7 +587,10 @@ final class ProtoWriterTests: XCTestCase { func testEncodePackedRepeatedProto3Default() throws { let writer = ProtoWriter() - let person = Person3(name: "name", id: 1, email: "email", ids: [1, 2, 3]) + let person = Person3(name: "name", id: 1) { + $0.email = "email" + $0.ids = [1, 2, 3] + } try writer.encode(tag: 1, value: person) // Proto3 should used "packed: true" by default. diff --git a/wire-runtime-swift/src/test/swift/RedactableTests.swift b/wire-runtime-swift/src/test/swift/RedactableTests.swift index dc0ee2a397..fa788db356 100644 --- a/wire-runtime-swift/src/test/swift/RedactableTests.swift +++ b/wire-runtime-swift/src/test/swift/RedactableTests.swift @@ -28,12 +28,16 @@ final class RedactableTests: XCTestCase { } func testRedactedOneOf() { - let redacted1 = Redacted(name: "Foo", choice: .yes("yes")) + let redacted1 = Redacted(name: "Foo") { + $0.choice = .yes("yes") + } XCTAssertEqual( redacted1.description, "Redacted(name: , nested: nil, choice: Optional(Choice(yes: \"yes\")), unknownFields: 0 bytes)" ) - let redacted2 = Redacted(name: "Foo", choice: .no("no")) + let redacted2 = Redacted(name: "Foo") { + $0.choice = .no("no") + } XCTAssertEqual( redacted2.description, "Redacted(name: , nested: nil, choice: Optional(Choice(no: )), unknownFields: 0 bytes)" @@ -51,13 +55,11 @@ final class RedactableTests: XCTestCase { } func testNestedRedactedField() { - let redacted = Redacted2( - name: "foo", - partially_redacted: .init( - name: "bar", - enabled: true - ) - ) + let redacted = Redacted2(name: "foo") { + $0.partially_redacted = Redacted3(name: "bar") { + $0.enabled = true + } + } XCTAssertEqual( redacted.description, "Redacted2(name: \"foo\", fully_redacted: nil, partially_redacted: Optional(Redacted3(name: \"bar\", enabled: , unknownFields: 0 bytes)), unknownFields: 0 bytes)" diff --git a/wire-runtime-swift/src/test/swift/RoundTripTests.swift b/wire-runtime-swift/src/test/swift/RoundTripTests.swift index 18afee0823..892e723127 100644 --- a/wire-runtime-swift/src/test/swift/RoundTripTests.swift +++ b/wire-runtime-swift/src/test/swift/RoundTripTests.swift @@ -21,14 +21,13 @@ final class RoundTripTests: XCTestCase { func testPersonEncodeDecode() throws { let personData = Data(json_data: "") - let person = Person( - name: "Luke Skywalker", - id: 42, - email: "luke@skywalker.net", - phone: [.init(number: "800-555-1234", type: .WORK)], - aliases: ["Nerfherder"], - data: personData - ) + let person = Person(name: "Luke Skywalker", id: 42, data: personData) { + $0.email = "luke@skywalker.net" + $0.phone = [ + Person.PhoneNumber(number: "800-555-1234") { $0.type = .WORK }, + ] + $0.aliases = ["Nerfherder"] + } let encoder = ProtoEncoder() let data = try encoder.encode(person) @@ -46,11 +45,12 @@ final class RoundTripTests: XCTestCase { string_value: "", bytes_value: Foundation.Data(), bool_value: false, - enum_value: .UNKNOWN, - message_value: nil, - repeated_value: [], - map_value: [:] - ) + enum_value: .UNKNOWN + ) { + $0.message_value = nil + $0.repeated_value = [] + $0.map_value = [:] + } let encoder = ProtoEncoder() let data = try encoder.encode(empty) diff --git a/wire-runtime-swift/src/test/swift/sample/Dinosaur.swift b/wire-runtime-swift/src/test/swift/sample/Dinosaur.swift index e42fe05147..9502d06acf 100644 --- a/wire-runtime-swift/src/test/swift/sample/Dinosaur.swift +++ b/wire-runtime-swift/src/test/swift/sample/Dinosaur.swift @@ -12,17 +12,28 @@ public struct Dinosaur { /** * URLs with images of this dinosaur. */ - public var picture_urls: [String] + public var picture_urls: [String] = [] public var length_meters: Double? public var mass_kilograms: Double? public var period: Period? public var unknownFields: Foundation.Data = .init() + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension Dinosaur { + + @_disfavoredOverload + @available(*, deprecated) public init( - name: String? = nil, - picture_urls: [String] = [], - length_meters: Double? = nil, - mass_kilograms: Double? = nil, + name: Swift.String? = nil, + picture_urls: [Swift.String] = [], + length_meters: Swift.Double? = nil, + mass_kilograms: Swift.Double? = nil, period: Period? = nil ) { self.name = name @@ -33,6 +44,7 @@ public struct Dinosaur { } } +#endif #if !WIRE_REMOVE_EQUATABLE extension Dinosaur : Equatable { diff --git a/wire-swift-generator/src/main/java/com/squareup/wire/swift/SwiftGenerator.kt b/wire-swift-generator/src/main/java/com/squareup/wire/swift/SwiftGenerator.kt index 0d74ee065c..832fef9c00 100644 --- a/wire-swift-generator/src/main/java/com/squareup/wire/swift/SwiftGenerator.kt +++ b/wire-swift-generator/src/main/java/com/squareup/wire/swift/SwiftGenerator.kt @@ -46,6 +46,7 @@ import io.outfoxx.swiftpoet.FileMemberSpec import io.outfoxx.swiftpoet.FileSpec import io.outfoxx.swiftpoet.FunctionSignatureSpec import io.outfoxx.swiftpoet.FunctionSpec +import io.outfoxx.swiftpoet.FunctionTypeName import io.outfoxx.swiftpoet.INT import io.outfoxx.swiftpoet.INT32 import io.outfoxx.swiftpoet.INT64 @@ -65,9 +66,9 @@ import io.outfoxx.swiftpoet.TypeSpec import io.outfoxx.swiftpoet.TypeVariableName import io.outfoxx.swiftpoet.UINT32 import io.outfoxx.swiftpoet.UINT64 +import io.outfoxx.swiftpoet.VOID import io.outfoxx.swiftpoet.joinToCode import io.outfoxx.swiftpoet.parameterizedBy -import java.util.Locale.US import okio.ByteString.Companion.encode class SwiftGenerator private constructor( @@ -137,6 +138,9 @@ class SwiftGenerator private constructor( internal val Field.valueType: ProtoType get() = type!!.valueType!! + private val Field.isRequiredParameter: Boolean + get() = !isOptional && !isRepeated && !isMap + private val Field.isCollection: Boolean get() = when (typeName.makeNonOptional()) { DATA, STRING -> true @@ -255,7 +259,7 @@ class SwiftGenerator private constructor( fileMembers: MutableList, ): List { val structType = type.typeName - val oneOfEnumNames = type.oneOfs.associateWith { structType.nestedType(it.name.capitalize(US)) } + val oneOfEnumNames = type.oneOfs.associateWith { structType.nestedType(it.name.replaceFirstChar(Char::uppercase)) } // TODO use a NameAllocator val propertyNames = type.fields.map { it.name } + type.oneOfs.map { it.name } @@ -286,28 +290,7 @@ class SwiftGenerator private constructor( ) generateMessageStoragePropertyDelegates(type, storageName, storageType) - - addFunction( - FunctionSpec.constructorBuilder() - .addModifiers(PUBLIC) - .addParameters(type, oneOfEnumNames, includeDefaults = true) - .apply { - val storageParams = mutableListOf() - type.fields.forEach { field -> - storageParams += CodeBlock.of("%1N: %1N", field.name) - } - type.oneOfs.forEach { oneOf -> - storageParams += CodeBlock.of("%1N: %1N", oneOf.name) - } - addStatement( - "self.%N = %T(%L)", - storageName, - storageType, - storageParams.joinToCode(separator = ",%W"), - ) - } - .build(), - ) + generateMessageStorageDelegateConstructor(type, storageName, structType, storageType, oneOfEnumNames, fileMembers) addFunction( FunctionSpec.builder("copyStorage") @@ -319,7 +302,7 @@ class SwiftGenerator private constructor( ) } else { generateMessageProperties(type, oneOfEnumNames) - generateMessageConstructor(type, oneOfEnumNames) + generateMessageConstructor(type, structType, oneOfEnumNames, fileMembers) } generateMessageOneOfs(type, oneOfEnumNames, fileMembers) @@ -386,7 +369,7 @@ class SwiftGenerator private constructor( .addModifiers(PUBLIC) .apply { generateMessageProperties(type, oneOfEnumNames, forStorageType = true) - generateMessageConstructor(type, oneOfEnumNames, includeDefaults = false) + generateMessageConstructor(type, storageType, oneOfEnumNames, fileMembers, includeMemberwiseDefaults = false) } .build(), ) @@ -953,8 +936,10 @@ class SwiftGenerator private constructor( type: MessageType, oneOfEnumNames: Map, includeDefaults: Boolean = true, + includeOneOfs: Boolean = true, + fieldsFilter: (Field) -> Boolean = { true }, ) = apply { - type.fields.forEach { field -> + type.fields.filter(fieldsFilter).forEach { field -> addParameter( ParameterSpec.builder(field.name, field.typeName) .apply { @@ -965,38 +950,185 @@ class SwiftGenerator private constructor( .build(), ) } - type.oneOfs.forEach { oneOf -> - val enumName = oneOfEnumNames.getValue(oneOf).makeOptional() - addParameter( - ParameterSpec.builder(oneOf.name, enumName) - .defaultValue("nil") + if (includeOneOfs) { + type.oneOfs.forEach { oneOf -> + val enumName = oneOfEnumNames.getValue(oneOf).makeOptional() + addParameter( + ParameterSpec.builder(oneOf.name, enumName) + .defaultValue("nil") + .build(), + ) + } + } + } + + private fun TypeSpec.Builder.generateMessageStorageDelegateConstructor( + type: MessageType, + storageName: String, + structType: DeclaredTypeName, + storageType: DeclaredTypeName, + oneOfEnumNames: Map, + fileMembers: MutableList, + ) { + val needsConfigure = type.fields.any { !it.isRequiredParameter } || type.oneOfs.isNotEmpty() + + addFunction( + FunctionSpec.constructorBuilder() + .addModifiers(PUBLIC) + .addParameters( + type, + oneOfEnumNames, + includeDefaults = false, + includeOneOfs = false, + fieldsFilter = { it.isRequiredParameter }, + ) + .apply { + if (needsConfigure) { + val closureType = FunctionTypeName.get( + TypeVariableName.typeVariable("inout Self.${storageType.simpleName}"), + returnType = VOID, + ) + + addParameter( + ParameterSpec.builder("configure", closureType) + .defaultValue("{ _ in }") + .build(), + ) + } + } + .apply { + val storageParams = mutableListOf() + type.fields.filter { it.isRequiredParameter }.forEach { field -> + storageParams += CodeBlock.of("%1N: %1N", field.name) + } + + if (needsConfigure) { + storageParams += CodeBlock.of("%1N: %1N", "configure") + } + + addStatement( + "self.%N = %T(\n%L\n)", + storageName, + storageType, + storageParams.joinToCode(separator = ",\n"), + ) + } + .build(), + ) + + if (!needsConfigure) { + return + } + + // These will be removed in November 2023 + val memberwiseExtension = ExtensionSpec.builder(structType) + .addFunction( + FunctionSpec.constructorBuilder() + .addModifiers(PUBLIC) + .addParameters(type, oneOfEnumNames, includeDefaults = true) + .addAttribute(AttributeSpec.builder("_disfavoredOverload").build()) + .addAttribute(deprecated) + .apply { + val storageParams = mutableListOf() + type.fields.forEach { field -> + storageParams += CodeBlock.of("%1N: %1N", field.name) + } + type.oneOfs.forEach { oneOf -> + storageParams += CodeBlock.of("%1N: %1N", oneOf.name) + } + addStatement( + "self.%N = %T(\n%L\n)", + storageName, + storageType, + storageParams.joinToCode(separator = ",\n"), + ) + } .build(), ) - } + .build() + + fileMembers += FileMemberSpec.builder(memberwiseExtension) + .addGuard("$FLAG_INCLUDE_MEMBERWISE_INITIALIZER") + .build() } private fun TypeSpec.Builder.generateMessageConstructor( type: MessageType, + structType: DeclaredTypeName, oneOfEnumNames: Map, - includeDefaults: Boolean = true, + fileMembers: MutableList, + includeMemberwiseDefaults: Boolean = true, ) { + val needsConfigure = type.fields.any { !it.isRequiredParameter } || type.oneOfs.isNotEmpty() + addFunction( FunctionSpec.constructorBuilder() .addModifiers(PUBLIC) - .addParameters(type, oneOfEnumNames, includeDefaults) + .addParameters( + type, + oneOfEnumNames, + includeDefaults = false, + includeOneOfs = false, + fieldsFilter = { it.isRequiredParameter }, + ) .apply { - type.fields.forEach { field -> + if (needsConfigure) { + val closureType = FunctionTypeName.get( + TypeVariableName.typeVariable("inout Self"), + returnType = VOID, + ) + + addParameter( + ParameterSpec.builder("configure", closureType) + .defaultValue("{ _ in }") + .build(), + ) + } + } + .apply { + type.fields.filter { it.isRequiredParameter }.forEach { field -> addStatement( if (field.default != null) "_%1N.wrappedValue = %1N" else { "self.%1N = %1N" }, field.name, ) } - type.oneOfs.forEach { oneOf -> - addStatement("self.%1N = %1N", oneOf.name) + if (needsConfigure) { + addStatement("configure(&self)") } } .build(), ) + + if (!needsConfigure) { + return + } + + // These will be removed in November 2023 + val memberwiseExtension = ExtensionSpec.builder(structType) + .addFunction( + FunctionSpec.constructorBuilder() + .addModifiers(PUBLIC) + .addParameters(type, oneOfEnumNames, includeDefaults = includeMemberwiseDefaults) + .addAttribute(AttributeSpec.builder("_disfavoredOverload").build()) + .addAttribute(deprecated) + .apply { + type.fields.forEach { field -> + addStatement( + if (field.default != null) "_%1N.wrappedValue = %1N" else { "self.%1N = %1N" }, + field.name, + ) + } + type.oneOfs.forEach { oneOf -> + addStatement("self.%1N = %1N", oneOf.name) + } + } + .build(), + ) + .build() + + fileMembers += FileMemberSpec.builder(memberwiseExtension) + .addGuard("$FLAG_INCLUDE_MEMBERWISE_INITIALIZER") + .build() } private fun TypeSpec.Builder.generateMessageProperties( @@ -1021,6 +1153,12 @@ class SwiftGenerator private constructor( property.addAttribute(AttributeSpec.builder(defaulted).addArgument("defaultValue: $defaultValue").build()) } + if (field.isMap) { + property.initializer("[:]") + } else if (field.isRepeated) { + property.initializer("[]") + } + addProperty(property.build()) } @@ -1390,6 +1528,7 @@ class SwiftGenerator private constructor( private const val FLAG_REMOVE_EQUATABLE = "WIRE_REMOVE_EQUATABLE" private const val FLAG_REMOVE_HASHABLE = "WIRE_REMOVE_HASHABLE" private const val FLAG_REMOVE_REDACTABLE = "WIRE_REMOVE_REDACTABLE" + private const val FLAG_INCLUDE_MEMBERWISE_INITIALIZER = "WIRE_INCLUDE_MEMBERWISE_INITIALIZER" private val NEEDS_CUSTOM_CODABLE = setOf("Duration", "Timestamp") diff --git a/wire-tests-proto3-swift/src/main/swift/ContainsDuration.swift b/wire-tests-proto3-swift/src/main/swift/ContainsDuration.swift index 73b9426198..c6c229d170 100644 --- a/wire-tests-proto3-swift/src/main/swift/ContainsDuration.swift +++ b/wire-tests-proto3-swift/src/main/swift/ContainsDuration.swift @@ -8,11 +8,23 @@ public struct ContainsDuration { public var duration: Duration? public var unknownFields: Foundation.Data = .init() + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension ContainsDuration { + + @_disfavoredOverload + @available(*, deprecated) public init(duration: Duration? = nil) { self.duration = duration } } +#endif #if !WIRE_REMOVE_EQUATABLE extension ContainsDuration : Equatable { diff --git a/wire-tests-proto3-swift/src/main/swift/ContainsTimestamp.swift b/wire-tests-proto3-swift/src/main/swift/ContainsTimestamp.swift index d11e8f64a7..9485261df4 100644 --- a/wire-tests-proto3-swift/src/main/swift/ContainsTimestamp.swift +++ b/wire-tests-proto3-swift/src/main/swift/ContainsTimestamp.swift @@ -8,11 +8,23 @@ public struct ContainsTimestamp { public var timestamp: Timestamp? public var unknownFields: Foundation.Data = .init() + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension ContainsTimestamp { + + @_disfavoredOverload + @available(*, deprecated) public init(timestamp: Timestamp? = nil) { self.timestamp = timestamp } } +#endif #if !WIRE_REMOVE_EQUATABLE extension ContainsTimestamp : Equatable { diff --git a/wire-tests-swift/src/main/swift/AllTypes.swift b/wire-tests-swift/src/main/swift/AllTypes.swift index 79b36fc077..bc4bdd4af4 100644 --- a/wire-tests-swift/src/main/swift/AllTypes.swift +++ b/wire-tests-swift/src/main/swift/AllTypes.swift @@ -19,23 +19,6 @@ public struct AllTypes { } public init( - opt_int32: Int32? = nil, - opt_uint32: UInt32? = nil, - opt_sint32: Int32? = nil, - opt_fixed32: UInt32? = nil, - opt_sfixed32: Int32? = nil, - opt_int64: Int64? = nil, - opt_uint64: UInt64? = nil, - opt_sint64: Int64? = nil, - opt_fixed64: UInt64? = nil, - opt_sfixed64: Int64? = nil, - opt_bool: Bool? = nil, - opt_float: Float? = nil, - opt_double: Double? = nil, - opt_string: String? = nil, - opt_bytes: Foundation.Data? = nil, - opt_nested_enum: AllTypes.NestedEnum? = nil, - opt_nested_message: AllTypes.NestedMessage? = nil, req_int32: Int32, req_uint32: UInt32, req_sint32: Int32, @@ -53,182 +36,28 @@ public struct AllTypes { req_bytes: Foundation.Data, req_nested_enum: AllTypes.NestedEnum, req_nested_message: AllTypes.NestedMessage, - rep_int32: [Int32] = [], - rep_uint32: [UInt32] = [], - rep_sint32: [Int32] = [], - rep_fixed32: [UInt32] = [], - rep_sfixed32: [Int32] = [], - rep_int64: [Int64] = [], - rep_uint64: [UInt64] = [], - rep_sint64: [Int64] = [], - rep_fixed64: [UInt64] = [], - rep_sfixed64: [Int64] = [], - rep_bool: [Bool] = [], - rep_float: [Float] = [], - rep_double: [Double] = [], - rep_string: [String] = [], - rep_bytes: [Foundation.Data] = [], - rep_nested_enum: [AllTypes.NestedEnum] = [], - rep_nested_message: [AllTypes.NestedMessage] = [], - pack_int32: [Int32] = [], - pack_uint32: [UInt32] = [], - pack_sint32: [Int32] = [], - pack_fixed32: [UInt32] = [], - pack_sfixed32: [Int32] = [], - pack_int64: [Int64] = [], - pack_uint64: [UInt64] = [], - pack_sint64: [Int64] = [], - pack_fixed64: [UInt64] = [], - pack_sfixed64: [Int64] = [], - pack_bool: [Bool] = [], - pack_float: [Float] = [], - pack_double: [Double] = [], - pack_nested_enum: [AllTypes.NestedEnum] = [], - default_int32: Int32? = nil, - default_uint32: UInt32? = nil, - default_sint32: Int32? = nil, - default_fixed32: UInt32? = nil, - default_sfixed32: Int32? = nil, - default_int64: Int64? = nil, - default_uint64: UInt64? = nil, - default_sint64: Int64? = nil, - default_fixed64: UInt64? = nil, - default_sfixed64: Int64? = nil, - default_bool: Bool? = nil, - default_float: Float? = nil, - default_double: Double? = nil, - default_string: String? = nil, - default_bytes: Foundation.Data? = nil, - default_nested_enum: AllTypes.NestedEnum? = nil, - map_int32_int32: [Int32 : Int32] = [:], - map_string_string: [String : String] = [:], - map_string_message: [String : AllTypes.NestedMessage] = [:], - map_string_enum: [String : AllTypes.NestedEnum] = [:], - array_int32: [Int32] = [], - array_uint32: [UInt32] = [], - array_sint32: [Int32] = [], - array_fixed32: [UInt32] = [], - array_sfixed32: [Int32] = [], - array_int64: [Int64] = [], - array_uint64: [UInt64] = [], - array_sint64: [Int64] = [], - array_fixed64: [UInt64] = [], - array_sfixed64: [Int64] = [], - array_float: [Float] = [], - array_double: [Double] = [], - ext_opt_int32: Int32? = nil, - ext_opt_uint32: UInt32? = nil, - ext_opt_sint32: Int32? = nil, - ext_opt_fixed32: UInt32? = nil, - ext_opt_sfixed32: Int32? = nil, - ext_opt_int64: Int64? = nil, - ext_opt_uint64: UInt64? = nil, - ext_opt_sint64: Int64? = nil, - ext_opt_fixed64: UInt64? = nil, - ext_opt_sfixed64: Int64? = nil, - ext_opt_bool: Bool? = nil, - ext_opt_float: Float? = nil, - ext_opt_double: Double? = nil, - ext_opt_string: String? = nil, - ext_opt_bytes: Foundation.Data? = nil, - ext_opt_nested_enum: AllTypes.NestedEnum? = nil, - ext_opt_nested_message: AllTypes.NestedMessage? = nil, - ext_rep_int32: [Int32] = [], - ext_rep_uint32: [UInt32] = [], - ext_rep_sint32: [Int32] = [], - ext_rep_fixed32: [UInt32] = [], - ext_rep_sfixed32: [Int32] = [], - ext_rep_int64: [Int64] = [], - ext_rep_uint64: [UInt64] = [], - ext_rep_sint64: [Int64] = [], - ext_rep_fixed64: [UInt64] = [], - ext_rep_sfixed64: [Int64] = [], - ext_rep_bool: [Bool] = [], - ext_rep_float: [Float] = [], - ext_rep_double: [Double] = [], - ext_rep_string: [String] = [], - ext_rep_bytes: [Foundation.Data] = [], - ext_rep_nested_enum: [AllTypes.NestedEnum] = [], - ext_rep_nested_message: [AllTypes.NestedMessage] = [], - ext_pack_int32: [Int32] = [], - ext_pack_uint32: [UInt32] = [], - ext_pack_sint32: [Int32] = [], - ext_pack_fixed32: [UInt32] = [], - ext_pack_sfixed32: [Int32] = [], - ext_pack_int64: [Int64] = [], - ext_pack_uint64: [UInt64] = [], - ext_pack_sint64: [Int64] = [], - ext_pack_fixed64: [UInt64] = [], - ext_pack_sfixed64: [Int64] = [], - ext_pack_bool: [Bool] = [], - ext_pack_float: [Float] = [], - ext_pack_double: [Double] = [], - ext_pack_nested_enum: [AllTypes.NestedEnum] = [] + configure: (inout Self.Storage) -> Void = { _ in } ) { - self.storage = AllTypes.Storage(opt_int32: opt_int32, opt_uint32: opt_uint32, - opt_sint32: opt_sint32, opt_fixed32: opt_fixed32, opt_sfixed32: opt_sfixed32, - opt_int64: opt_int64, opt_uint64: opt_uint64, opt_sint64: opt_sint64, - opt_fixed64: opt_fixed64, opt_sfixed64: opt_sfixed64, opt_bool: opt_bool, - opt_float: opt_float, opt_double: opt_double, opt_string: opt_string, - opt_bytes: opt_bytes, opt_nested_enum: opt_nested_enum, - opt_nested_message: opt_nested_message, req_int32: req_int32, - req_uint32: req_uint32, req_sint32: req_sint32, req_fixed32: req_fixed32, - req_sfixed32: req_sfixed32, req_int64: req_int64, req_uint64: req_uint64, - req_sint64: req_sint64, req_fixed64: req_fixed64, req_sfixed64: req_sfixed64, - req_bool: req_bool, req_float: req_float, req_double: req_double, - req_string: req_string, req_bytes: req_bytes, req_nested_enum: req_nested_enum, - req_nested_message: req_nested_message, rep_int32: rep_int32, - rep_uint32: rep_uint32, rep_sint32: rep_sint32, rep_fixed32: rep_fixed32, - rep_sfixed32: rep_sfixed32, rep_int64: rep_int64, rep_uint64: rep_uint64, - rep_sint64: rep_sint64, rep_fixed64: rep_fixed64, rep_sfixed64: rep_sfixed64, - rep_bool: rep_bool, rep_float: rep_float, rep_double: rep_double, - rep_string: rep_string, rep_bytes: rep_bytes, rep_nested_enum: rep_nested_enum, - rep_nested_message: rep_nested_message, pack_int32: pack_int32, - pack_uint32: pack_uint32, pack_sint32: pack_sint32, pack_fixed32: pack_fixed32, - pack_sfixed32: pack_sfixed32, pack_int64: pack_int64, pack_uint64: pack_uint64, - pack_sint64: pack_sint64, pack_fixed64: pack_fixed64, pack_sfixed64: pack_sfixed64, - pack_bool: pack_bool, pack_float: pack_float, pack_double: pack_double, - pack_nested_enum: pack_nested_enum, default_int32: default_int32, - default_uint32: default_uint32, default_sint32: default_sint32, - default_fixed32: default_fixed32, default_sfixed32: default_sfixed32, - default_int64: default_int64, default_uint64: default_uint64, - default_sint64: default_sint64, default_fixed64: default_fixed64, - default_sfixed64: default_sfixed64, default_bool: default_bool, - default_float: default_float, default_double: default_double, - default_string: default_string, default_bytes: default_bytes, - default_nested_enum: default_nested_enum, map_int32_int32: map_int32_int32, - map_string_string: map_string_string, map_string_message: map_string_message, - map_string_enum: map_string_enum, array_int32: array_int32, - array_uint32: array_uint32, array_sint32: array_sint32, - array_fixed32: array_fixed32, array_sfixed32: array_sfixed32, - array_int64: array_int64, array_uint64: array_uint64, array_sint64: array_sint64, - array_fixed64: array_fixed64, array_sfixed64: array_sfixed64, - array_float: array_float, array_double: array_double, ext_opt_int32: ext_opt_int32, - ext_opt_uint32: ext_opt_uint32, ext_opt_sint32: ext_opt_sint32, - ext_opt_fixed32: ext_opt_fixed32, ext_opt_sfixed32: ext_opt_sfixed32, - ext_opt_int64: ext_opt_int64, ext_opt_uint64: ext_opt_uint64, - ext_opt_sint64: ext_opt_sint64, ext_opt_fixed64: ext_opt_fixed64, - ext_opt_sfixed64: ext_opt_sfixed64, ext_opt_bool: ext_opt_bool, - ext_opt_float: ext_opt_float, ext_opt_double: ext_opt_double, - ext_opt_string: ext_opt_string, ext_opt_bytes: ext_opt_bytes, - ext_opt_nested_enum: ext_opt_nested_enum, - ext_opt_nested_message: ext_opt_nested_message, ext_rep_int32: ext_rep_int32, - ext_rep_uint32: ext_rep_uint32, ext_rep_sint32: ext_rep_sint32, - ext_rep_fixed32: ext_rep_fixed32, ext_rep_sfixed32: ext_rep_sfixed32, - ext_rep_int64: ext_rep_int64, ext_rep_uint64: ext_rep_uint64, - ext_rep_sint64: ext_rep_sint64, ext_rep_fixed64: ext_rep_fixed64, - ext_rep_sfixed64: ext_rep_sfixed64, ext_rep_bool: ext_rep_bool, - ext_rep_float: ext_rep_float, ext_rep_double: ext_rep_double, - ext_rep_string: ext_rep_string, ext_rep_bytes: ext_rep_bytes, - ext_rep_nested_enum: ext_rep_nested_enum, - ext_rep_nested_message: ext_rep_nested_message, ext_pack_int32: ext_pack_int32, - ext_pack_uint32: ext_pack_uint32, ext_pack_sint32: ext_pack_sint32, - ext_pack_fixed32: ext_pack_fixed32, ext_pack_sfixed32: ext_pack_sfixed32, - ext_pack_int64: ext_pack_int64, ext_pack_uint64: ext_pack_uint64, - ext_pack_sint64: ext_pack_sint64, ext_pack_fixed64: ext_pack_fixed64, - ext_pack_sfixed64: ext_pack_sfixed64, ext_pack_bool: ext_pack_bool, - ext_pack_float: ext_pack_float, ext_pack_double: ext_pack_double, - ext_pack_nested_enum: ext_pack_nested_enum) + self.storage = AllTypes.Storage( + req_int32: req_int32, + req_uint32: req_uint32, + req_sint32: req_sint32, + req_fixed32: req_fixed32, + req_sfixed32: req_sfixed32, + req_int64: req_int64, + req_uint64: req_uint64, + req_sint64: req_sint64, + req_fixed64: req_fixed64, + req_sfixed64: req_sfixed64, + req_bool: req_bool, + req_float: req_float, + req_double: req_double, + req_string: req_string, + req_bytes: req_bytes, + req_nested_enum: req_nested_enum, + req_nested_message: req_nested_message, + configure: configure + ) } private mutating func copyStorage() { @@ -256,19 +85,335 @@ public struct AllTypes { public var a: Int32? public var unknownFields: Foundation.Data = .init() - public init(a: Int32? = nil) { - self.a = a + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) } } } +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension AllTypes { + + @_disfavoredOverload + @available(*, deprecated) + public init( + opt_int32: Swift.Int32? = nil, + opt_uint32: Swift.UInt32? = nil, + opt_sint32: Swift.Int32? = nil, + opt_fixed32: Swift.UInt32? = nil, + opt_sfixed32: Swift.Int32? = nil, + opt_int64: Swift.Int64? = nil, + opt_uint64: Swift.UInt64? = nil, + opt_sint64: Swift.Int64? = nil, + opt_fixed64: Swift.UInt64? = nil, + opt_sfixed64: Swift.Int64? = nil, + opt_bool: Swift.Bool? = nil, + opt_float: Swift.Float? = nil, + opt_double: Swift.Double? = nil, + opt_string: Swift.String? = nil, + opt_bytes: Foundation.Data? = nil, + opt_nested_enum: AllTypes.NestedEnum? = nil, + opt_nested_message: AllTypes.NestedMessage? = nil, + req_int32: Swift.Int32, + req_uint32: Swift.UInt32, + req_sint32: Swift.Int32, + req_fixed32: Swift.UInt32, + req_sfixed32: Swift.Int32, + req_int64: Swift.Int64, + req_uint64: Swift.UInt64, + req_sint64: Swift.Int64, + req_fixed64: Swift.UInt64, + req_sfixed64: Swift.Int64, + req_bool: Swift.Bool, + req_float: Swift.Float, + req_double: Swift.Double, + req_string: Swift.String, + req_bytes: Foundation.Data, + req_nested_enum: AllTypes.NestedEnum, + req_nested_message: AllTypes.NestedMessage, + rep_int32: [Swift.Int32] = [], + rep_uint32: [Swift.UInt32] = [], + rep_sint32: [Swift.Int32] = [], + rep_fixed32: [Swift.UInt32] = [], + rep_sfixed32: [Swift.Int32] = [], + rep_int64: [Swift.Int64] = [], + rep_uint64: [Swift.UInt64] = [], + rep_sint64: [Swift.Int64] = [], + rep_fixed64: [Swift.UInt64] = [], + rep_sfixed64: [Swift.Int64] = [], + rep_bool: [Swift.Bool] = [], + rep_float: [Swift.Float] = [], + rep_double: [Swift.Double] = [], + rep_string: [Swift.String] = [], + rep_bytes: [Foundation.Data] = [], + rep_nested_enum: [AllTypes.NestedEnum] = [], + rep_nested_message: [AllTypes.NestedMessage] = [], + pack_int32: [Swift.Int32] = [], + pack_uint32: [Swift.UInt32] = [], + pack_sint32: [Swift.Int32] = [], + pack_fixed32: [Swift.UInt32] = [], + pack_sfixed32: [Swift.Int32] = [], + pack_int64: [Swift.Int64] = [], + pack_uint64: [Swift.UInt64] = [], + pack_sint64: [Swift.Int64] = [], + pack_fixed64: [Swift.UInt64] = [], + pack_sfixed64: [Swift.Int64] = [], + pack_bool: [Swift.Bool] = [], + pack_float: [Swift.Float] = [], + pack_double: [Swift.Double] = [], + pack_nested_enum: [AllTypes.NestedEnum] = [], + default_int32: Swift.Int32? = nil, + default_uint32: Swift.UInt32? = nil, + default_sint32: Swift.Int32? = nil, + default_fixed32: Swift.UInt32? = nil, + default_sfixed32: Swift.Int32? = nil, + default_int64: Swift.Int64? = nil, + default_uint64: Swift.UInt64? = nil, + default_sint64: Swift.Int64? = nil, + default_fixed64: Swift.UInt64? = nil, + default_sfixed64: Swift.Int64? = nil, + default_bool: Swift.Bool? = nil, + default_float: Swift.Float? = nil, + default_double: Swift.Double? = nil, + default_string: Swift.String? = nil, + default_bytes: Foundation.Data? = nil, + default_nested_enum: AllTypes.NestedEnum? = nil, + map_int32_int32: [Swift.Int32 : Swift.Int32] = [:], + map_string_string: [Swift.String : Swift.String] = [:], + map_string_message: [Swift.String : AllTypes.NestedMessage] = [:], + map_string_enum: [Swift.String : AllTypes.NestedEnum] = [:], + array_int32: [Swift.Int32] = [], + array_uint32: [Swift.UInt32] = [], + array_sint32: [Swift.Int32] = [], + array_fixed32: [Swift.UInt32] = [], + array_sfixed32: [Swift.Int32] = [], + array_int64: [Swift.Int64] = [], + array_uint64: [Swift.UInt64] = [], + array_sint64: [Swift.Int64] = [], + array_fixed64: [Swift.UInt64] = [], + array_sfixed64: [Swift.Int64] = [], + array_float: [Swift.Float] = [], + array_double: [Swift.Double] = [], + ext_opt_int32: Swift.Int32? = nil, + ext_opt_uint32: Swift.UInt32? = nil, + ext_opt_sint32: Swift.Int32? = nil, + ext_opt_fixed32: Swift.UInt32? = nil, + ext_opt_sfixed32: Swift.Int32? = nil, + ext_opt_int64: Swift.Int64? = nil, + ext_opt_uint64: Swift.UInt64? = nil, + ext_opt_sint64: Swift.Int64? = nil, + ext_opt_fixed64: Swift.UInt64? = nil, + ext_opt_sfixed64: Swift.Int64? = nil, + ext_opt_bool: Swift.Bool? = nil, + ext_opt_float: Swift.Float? = nil, + ext_opt_double: Swift.Double? = nil, + ext_opt_string: Swift.String? = nil, + ext_opt_bytes: Foundation.Data? = nil, + ext_opt_nested_enum: AllTypes.NestedEnum? = nil, + ext_opt_nested_message: AllTypes.NestedMessage? = nil, + ext_rep_int32: [Swift.Int32] = [], + ext_rep_uint32: [Swift.UInt32] = [], + ext_rep_sint32: [Swift.Int32] = [], + ext_rep_fixed32: [Swift.UInt32] = [], + ext_rep_sfixed32: [Swift.Int32] = [], + ext_rep_int64: [Swift.Int64] = [], + ext_rep_uint64: [Swift.UInt64] = [], + ext_rep_sint64: [Swift.Int64] = [], + ext_rep_fixed64: [Swift.UInt64] = [], + ext_rep_sfixed64: [Swift.Int64] = [], + ext_rep_bool: [Swift.Bool] = [], + ext_rep_float: [Swift.Float] = [], + ext_rep_double: [Swift.Double] = [], + ext_rep_string: [Swift.String] = [], + ext_rep_bytes: [Foundation.Data] = [], + ext_rep_nested_enum: [AllTypes.NestedEnum] = [], + ext_rep_nested_message: [AllTypes.NestedMessage] = [], + ext_pack_int32: [Swift.Int32] = [], + ext_pack_uint32: [Swift.UInt32] = [], + ext_pack_sint32: [Swift.Int32] = [], + ext_pack_fixed32: [Swift.UInt32] = [], + ext_pack_sfixed32: [Swift.Int32] = [], + ext_pack_int64: [Swift.Int64] = [], + ext_pack_uint64: [Swift.UInt64] = [], + ext_pack_sint64: [Swift.Int64] = [], + ext_pack_fixed64: [Swift.UInt64] = [], + ext_pack_sfixed64: [Swift.Int64] = [], + ext_pack_bool: [Swift.Bool] = [], + ext_pack_float: [Swift.Float] = [], + ext_pack_double: [Swift.Double] = [], + ext_pack_nested_enum: [AllTypes.NestedEnum] = [] + ) { + self.storage = Storage( + opt_int32: opt_int32, + opt_uint32: opt_uint32, + opt_sint32: opt_sint32, + opt_fixed32: opt_fixed32, + opt_sfixed32: opt_sfixed32, + opt_int64: opt_int64, + opt_uint64: opt_uint64, + opt_sint64: opt_sint64, + opt_fixed64: opt_fixed64, + opt_sfixed64: opt_sfixed64, + opt_bool: opt_bool, + opt_float: opt_float, + opt_double: opt_double, + opt_string: opt_string, + opt_bytes: opt_bytes, + opt_nested_enum: opt_nested_enum, + opt_nested_message: opt_nested_message, + req_int32: req_int32, + req_uint32: req_uint32, + req_sint32: req_sint32, + req_fixed32: req_fixed32, + req_sfixed32: req_sfixed32, + req_int64: req_int64, + req_uint64: req_uint64, + req_sint64: req_sint64, + req_fixed64: req_fixed64, + req_sfixed64: req_sfixed64, + req_bool: req_bool, + req_float: req_float, + req_double: req_double, + req_string: req_string, + req_bytes: req_bytes, + req_nested_enum: req_nested_enum, + req_nested_message: req_nested_message, + rep_int32: rep_int32, + rep_uint32: rep_uint32, + rep_sint32: rep_sint32, + rep_fixed32: rep_fixed32, + rep_sfixed32: rep_sfixed32, + rep_int64: rep_int64, + rep_uint64: rep_uint64, + rep_sint64: rep_sint64, + rep_fixed64: rep_fixed64, + rep_sfixed64: rep_sfixed64, + rep_bool: rep_bool, + rep_float: rep_float, + rep_double: rep_double, + rep_string: rep_string, + rep_bytes: rep_bytes, + rep_nested_enum: rep_nested_enum, + rep_nested_message: rep_nested_message, + pack_int32: pack_int32, + pack_uint32: pack_uint32, + pack_sint32: pack_sint32, + pack_fixed32: pack_fixed32, + pack_sfixed32: pack_sfixed32, + pack_int64: pack_int64, + pack_uint64: pack_uint64, + pack_sint64: pack_sint64, + pack_fixed64: pack_fixed64, + pack_sfixed64: pack_sfixed64, + pack_bool: pack_bool, + pack_float: pack_float, + pack_double: pack_double, + pack_nested_enum: pack_nested_enum, + default_int32: default_int32, + default_uint32: default_uint32, + default_sint32: default_sint32, + default_fixed32: default_fixed32, + default_sfixed32: default_sfixed32, + default_int64: default_int64, + default_uint64: default_uint64, + default_sint64: default_sint64, + default_fixed64: default_fixed64, + default_sfixed64: default_sfixed64, + default_bool: default_bool, + default_float: default_float, + default_double: default_double, + default_string: default_string, + default_bytes: default_bytes, + default_nested_enum: default_nested_enum, + map_int32_int32: map_int32_int32, + map_string_string: map_string_string, + map_string_message: map_string_message, + map_string_enum: map_string_enum, + array_int32: array_int32, + array_uint32: array_uint32, + array_sint32: array_sint32, + array_fixed32: array_fixed32, + array_sfixed32: array_sfixed32, + array_int64: array_int64, + array_uint64: array_uint64, + array_sint64: array_sint64, + array_fixed64: array_fixed64, + array_sfixed64: array_sfixed64, + array_float: array_float, + array_double: array_double, + ext_opt_int32: ext_opt_int32, + ext_opt_uint32: ext_opt_uint32, + ext_opt_sint32: ext_opt_sint32, + ext_opt_fixed32: ext_opt_fixed32, + ext_opt_sfixed32: ext_opt_sfixed32, + ext_opt_int64: ext_opt_int64, + ext_opt_uint64: ext_opt_uint64, + ext_opt_sint64: ext_opt_sint64, + ext_opt_fixed64: ext_opt_fixed64, + ext_opt_sfixed64: ext_opt_sfixed64, + ext_opt_bool: ext_opt_bool, + ext_opt_float: ext_opt_float, + ext_opt_double: ext_opt_double, + ext_opt_string: ext_opt_string, + ext_opt_bytes: ext_opt_bytes, + ext_opt_nested_enum: ext_opt_nested_enum, + ext_opt_nested_message: ext_opt_nested_message, + ext_rep_int32: ext_rep_int32, + ext_rep_uint32: ext_rep_uint32, + ext_rep_sint32: ext_rep_sint32, + ext_rep_fixed32: ext_rep_fixed32, + ext_rep_sfixed32: ext_rep_sfixed32, + ext_rep_int64: ext_rep_int64, + ext_rep_uint64: ext_rep_uint64, + ext_rep_sint64: ext_rep_sint64, + ext_rep_fixed64: ext_rep_fixed64, + ext_rep_sfixed64: ext_rep_sfixed64, + ext_rep_bool: ext_rep_bool, + ext_rep_float: ext_rep_float, + ext_rep_double: ext_rep_double, + ext_rep_string: ext_rep_string, + ext_rep_bytes: ext_rep_bytes, + ext_rep_nested_enum: ext_rep_nested_enum, + ext_rep_nested_message: ext_rep_nested_message, + ext_pack_int32: ext_pack_int32, + ext_pack_uint32: ext_pack_uint32, + ext_pack_sint32: ext_pack_sint32, + ext_pack_fixed32: ext_pack_fixed32, + ext_pack_sfixed32: ext_pack_sfixed32, + ext_pack_int64: ext_pack_int64, + ext_pack_uint64: ext_pack_uint64, + ext_pack_sint64: ext_pack_sint64, + ext_pack_fixed64: ext_pack_fixed64, + ext_pack_sfixed64: ext_pack_sfixed64, + ext_pack_bool: ext_pack_bool, + ext_pack_float: ext_pack_float, + ext_pack_double: ext_pack_double, + ext_pack_nested_enum: ext_pack_nested_enum + ) + } + +} +#endif + #if swift(>=5.5) extension AllTypes.NestedEnum : Sendable { } #endif +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension AllTypes.NestedMessage { + + @_disfavoredOverload + @available(*, deprecated) + public init(a: Swift.Int32? = nil) { + self.a = a + } + +} +#endif + #if !WIRE_REMOVE_EQUATABLE extension AllTypes.NestedMessage : Equatable { } @@ -348,6 +493,308 @@ extension AllTypes : @unchecked Sendable { } #endif +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension AllTypes.Storage { + + @_disfavoredOverload + @available(*, deprecated) + public init( + opt_int32: Swift.Int32?, + opt_uint32: Swift.UInt32?, + opt_sint32: Swift.Int32?, + opt_fixed32: Swift.UInt32?, + opt_sfixed32: Swift.Int32?, + opt_int64: Swift.Int64?, + opt_uint64: Swift.UInt64?, + opt_sint64: Swift.Int64?, + opt_fixed64: Swift.UInt64?, + opt_sfixed64: Swift.Int64?, + opt_bool: Swift.Bool?, + opt_float: Swift.Float?, + opt_double: Swift.Double?, + opt_string: Swift.String?, + opt_bytes: Foundation.Data?, + opt_nested_enum: AllTypes.NestedEnum?, + opt_nested_message: AllTypes.NestedMessage?, + req_int32: Swift.Int32, + req_uint32: Swift.UInt32, + req_sint32: Swift.Int32, + req_fixed32: Swift.UInt32, + req_sfixed32: Swift.Int32, + req_int64: Swift.Int64, + req_uint64: Swift.UInt64, + req_sint64: Swift.Int64, + req_fixed64: Swift.UInt64, + req_sfixed64: Swift.Int64, + req_bool: Swift.Bool, + req_float: Swift.Float, + req_double: Swift.Double, + req_string: Swift.String, + req_bytes: Foundation.Data, + req_nested_enum: AllTypes.NestedEnum, + req_nested_message: AllTypes.NestedMessage, + rep_int32: [Swift.Int32], + rep_uint32: [Swift.UInt32], + rep_sint32: [Swift.Int32], + rep_fixed32: [Swift.UInt32], + rep_sfixed32: [Swift.Int32], + rep_int64: [Swift.Int64], + rep_uint64: [Swift.UInt64], + rep_sint64: [Swift.Int64], + rep_fixed64: [Swift.UInt64], + rep_sfixed64: [Swift.Int64], + rep_bool: [Swift.Bool], + rep_float: [Swift.Float], + rep_double: [Swift.Double], + rep_string: [Swift.String], + rep_bytes: [Foundation.Data], + rep_nested_enum: [AllTypes.NestedEnum], + rep_nested_message: [AllTypes.NestedMessage], + pack_int32: [Swift.Int32], + pack_uint32: [Swift.UInt32], + pack_sint32: [Swift.Int32], + pack_fixed32: [Swift.UInt32], + pack_sfixed32: [Swift.Int32], + pack_int64: [Swift.Int64], + pack_uint64: [Swift.UInt64], + pack_sint64: [Swift.Int64], + pack_fixed64: [Swift.UInt64], + pack_sfixed64: [Swift.Int64], + pack_bool: [Swift.Bool], + pack_float: [Swift.Float], + pack_double: [Swift.Double], + pack_nested_enum: [AllTypes.NestedEnum], + default_int32: Swift.Int32?, + default_uint32: Swift.UInt32?, + default_sint32: Swift.Int32?, + default_fixed32: Swift.UInt32?, + default_sfixed32: Swift.Int32?, + default_int64: Swift.Int64?, + default_uint64: Swift.UInt64?, + default_sint64: Swift.Int64?, + default_fixed64: Swift.UInt64?, + default_sfixed64: Swift.Int64?, + default_bool: Swift.Bool?, + default_float: Swift.Float?, + default_double: Swift.Double?, + default_string: Swift.String?, + default_bytes: Foundation.Data?, + default_nested_enum: AllTypes.NestedEnum?, + map_int32_int32: [Swift.Int32 : Swift.Int32], + map_string_string: [Swift.String : Swift.String], + map_string_message: [Swift.String : AllTypes.NestedMessage], + map_string_enum: [Swift.String : AllTypes.NestedEnum], + array_int32: [Swift.Int32], + array_uint32: [Swift.UInt32], + array_sint32: [Swift.Int32], + array_fixed32: [Swift.UInt32], + array_sfixed32: [Swift.Int32], + array_int64: [Swift.Int64], + array_uint64: [Swift.UInt64], + array_sint64: [Swift.Int64], + array_fixed64: [Swift.UInt64], + array_sfixed64: [Swift.Int64], + array_float: [Swift.Float], + array_double: [Swift.Double], + ext_opt_int32: Swift.Int32?, + ext_opt_uint32: Swift.UInt32?, + ext_opt_sint32: Swift.Int32?, + ext_opt_fixed32: Swift.UInt32?, + ext_opt_sfixed32: Swift.Int32?, + ext_opt_int64: Swift.Int64?, + ext_opt_uint64: Swift.UInt64?, + ext_opt_sint64: Swift.Int64?, + ext_opt_fixed64: Swift.UInt64?, + ext_opt_sfixed64: Swift.Int64?, + ext_opt_bool: Swift.Bool?, + ext_opt_float: Swift.Float?, + ext_opt_double: Swift.Double?, + ext_opt_string: Swift.String?, + ext_opt_bytes: Foundation.Data?, + ext_opt_nested_enum: AllTypes.NestedEnum?, + ext_opt_nested_message: AllTypes.NestedMessage?, + ext_rep_int32: [Swift.Int32], + ext_rep_uint32: [Swift.UInt32], + ext_rep_sint32: [Swift.Int32], + ext_rep_fixed32: [Swift.UInt32], + ext_rep_sfixed32: [Swift.Int32], + ext_rep_int64: [Swift.Int64], + ext_rep_uint64: [Swift.UInt64], + ext_rep_sint64: [Swift.Int64], + ext_rep_fixed64: [Swift.UInt64], + ext_rep_sfixed64: [Swift.Int64], + ext_rep_bool: [Swift.Bool], + ext_rep_float: [Swift.Float], + ext_rep_double: [Swift.Double], + ext_rep_string: [Swift.String], + ext_rep_bytes: [Foundation.Data], + ext_rep_nested_enum: [AllTypes.NestedEnum], + ext_rep_nested_message: [AllTypes.NestedMessage], + ext_pack_int32: [Swift.Int32], + ext_pack_uint32: [Swift.UInt32], + ext_pack_sint32: [Swift.Int32], + ext_pack_fixed32: [Swift.UInt32], + ext_pack_sfixed32: [Swift.Int32], + ext_pack_int64: [Swift.Int64], + ext_pack_uint64: [Swift.UInt64], + ext_pack_sint64: [Swift.Int64], + ext_pack_fixed64: [Swift.UInt64], + ext_pack_sfixed64: [Swift.Int64], + ext_pack_bool: [Swift.Bool], + ext_pack_float: [Swift.Float], + ext_pack_double: [Swift.Double], + ext_pack_nested_enum: [AllTypes.NestedEnum] + ) { + self.opt_int32 = opt_int32 + self.opt_uint32 = opt_uint32 + self.opt_sint32 = opt_sint32 + self.opt_fixed32 = opt_fixed32 + self.opt_sfixed32 = opt_sfixed32 + self.opt_int64 = opt_int64 + self.opt_uint64 = opt_uint64 + self.opt_sint64 = opt_sint64 + self.opt_fixed64 = opt_fixed64 + self.opt_sfixed64 = opt_sfixed64 + self.opt_bool = opt_bool + self.opt_float = opt_float + self.opt_double = opt_double + self.opt_string = opt_string + self.opt_bytes = opt_bytes + self.opt_nested_enum = opt_nested_enum + self.opt_nested_message = opt_nested_message + self.req_int32 = req_int32 + self.req_uint32 = req_uint32 + self.req_sint32 = req_sint32 + self.req_fixed32 = req_fixed32 + self.req_sfixed32 = req_sfixed32 + self.req_int64 = req_int64 + self.req_uint64 = req_uint64 + self.req_sint64 = req_sint64 + self.req_fixed64 = req_fixed64 + self.req_sfixed64 = req_sfixed64 + self.req_bool = req_bool + self.req_float = req_float + self.req_double = req_double + self.req_string = req_string + self.req_bytes = req_bytes + self.req_nested_enum = req_nested_enum + self.req_nested_message = req_nested_message + self.rep_int32 = rep_int32 + self.rep_uint32 = rep_uint32 + self.rep_sint32 = rep_sint32 + self.rep_fixed32 = rep_fixed32 + self.rep_sfixed32 = rep_sfixed32 + self.rep_int64 = rep_int64 + self.rep_uint64 = rep_uint64 + self.rep_sint64 = rep_sint64 + self.rep_fixed64 = rep_fixed64 + self.rep_sfixed64 = rep_sfixed64 + self.rep_bool = rep_bool + self.rep_float = rep_float + self.rep_double = rep_double + self.rep_string = rep_string + self.rep_bytes = rep_bytes + self.rep_nested_enum = rep_nested_enum + self.rep_nested_message = rep_nested_message + self.pack_int32 = pack_int32 + self.pack_uint32 = pack_uint32 + self.pack_sint32 = pack_sint32 + self.pack_fixed32 = pack_fixed32 + self.pack_sfixed32 = pack_sfixed32 + self.pack_int64 = pack_int64 + self.pack_uint64 = pack_uint64 + self.pack_sint64 = pack_sint64 + self.pack_fixed64 = pack_fixed64 + self.pack_sfixed64 = pack_sfixed64 + self.pack_bool = pack_bool + self.pack_float = pack_float + self.pack_double = pack_double + self.pack_nested_enum = pack_nested_enum + _default_int32.wrappedValue = default_int32 + _default_uint32.wrappedValue = default_uint32 + _default_sint32.wrappedValue = default_sint32 + _default_fixed32.wrappedValue = default_fixed32 + _default_sfixed32.wrappedValue = default_sfixed32 + _default_int64.wrappedValue = default_int64 + _default_uint64.wrappedValue = default_uint64 + _default_sint64.wrappedValue = default_sint64 + _default_fixed64.wrappedValue = default_fixed64 + _default_sfixed64.wrappedValue = default_sfixed64 + _default_bool.wrappedValue = default_bool + _default_float.wrappedValue = default_float + _default_double.wrappedValue = default_double + _default_string.wrappedValue = default_string + _default_bytes.wrappedValue = default_bytes + _default_nested_enum.wrappedValue = default_nested_enum + self.map_int32_int32 = map_int32_int32 + self.map_string_string = map_string_string + self.map_string_message = map_string_message + self.map_string_enum = map_string_enum + self.array_int32 = array_int32 + self.array_uint32 = array_uint32 + self.array_sint32 = array_sint32 + self.array_fixed32 = array_fixed32 + self.array_sfixed32 = array_sfixed32 + self.array_int64 = array_int64 + self.array_uint64 = array_uint64 + self.array_sint64 = array_sint64 + self.array_fixed64 = array_fixed64 + self.array_sfixed64 = array_sfixed64 + self.array_float = array_float + self.array_double = array_double + self.ext_opt_int32 = ext_opt_int32 + self.ext_opt_uint32 = ext_opt_uint32 + self.ext_opt_sint32 = ext_opt_sint32 + self.ext_opt_fixed32 = ext_opt_fixed32 + self.ext_opt_sfixed32 = ext_opt_sfixed32 + self.ext_opt_int64 = ext_opt_int64 + self.ext_opt_uint64 = ext_opt_uint64 + self.ext_opt_sint64 = ext_opt_sint64 + self.ext_opt_fixed64 = ext_opt_fixed64 + self.ext_opt_sfixed64 = ext_opt_sfixed64 + self.ext_opt_bool = ext_opt_bool + self.ext_opt_float = ext_opt_float + self.ext_opt_double = ext_opt_double + self.ext_opt_string = ext_opt_string + self.ext_opt_bytes = ext_opt_bytes + self.ext_opt_nested_enum = ext_opt_nested_enum + self.ext_opt_nested_message = ext_opt_nested_message + self.ext_rep_int32 = ext_rep_int32 + self.ext_rep_uint32 = ext_rep_uint32 + self.ext_rep_sint32 = ext_rep_sint32 + self.ext_rep_fixed32 = ext_rep_fixed32 + self.ext_rep_sfixed32 = ext_rep_sfixed32 + self.ext_rep_int64 = ext_rep_int64 + self.ext_rep_uint64 = ext_rep_uint64 + self.ext_rep_sint64 = ext_rep_sint64 + self.ext_rep_fixed64 = ext_rep_fixed64 + self.ext_rep_sfixed64 = ext_rep_sfixed64 + self.ext_rep_bool = ext_rep_bool + self.ext_rep_float = ext_rep_float + self.ext_rep_double = ext_rep_double + self.ext_rep_string = ext_rep_string + self.ext_rep_bytes = ext_rep_bytes + self.ext_rep_nested_enum = ext_rep_nested_enum + self.ext_rep_nested_message = ext_rep_nested_message + self.ext_pack_int32 = ext_pack_int32 + self.ext_pack_uint32 = ext_pack_uint32 + self.ext_pack_sint32 = ext_pack_sint32 + self.ext_pack_fixed32 = ext_pack_fixed32 + self.ext_pack_sfixed32 = ext_pack_sfixed32 + self.ext_pack_int64 = ext_pack_int64 + self.ext_pack_uint64 = ext_pack_uint64 + self.ext_pack_sint64 = ext_pack_sint64 + self.ext_pack_fixed64 = ext_pack_fixed64 + self.ext_pack_sfixed64 = ext_pack_sfixed64 + self.ext_pack_bool = ext_pack_bool + self.ext_pack_float = ext_pack_float + self.ext_pack_double = ext_pack_double + self.ext_pack_nested_enum = ext_pack_nested_enum + } + +} +#endif + extension AllTypes { public struct Storage { @@ -386,37 +833,37 @@ extension AllTypes { public var req_bytes: Foundation.Data public var req_nested_enum: AllTypes.NestedEnum public var req_nested_message: AllTypes.NestedMessage - public var rep_int32: [Swift.Int32] - public var rep_uint32: [Swift.UInt32] - public var rep_sint32: [Swift.Int32] - public var rep_fixed32: [Swift.UInt32] - public var rep_sfixed32: [Swift.Int32] - public var rep_int64: [Swift.Int64] - public var rep_uint64: [Swift.UInt64] - public var rep_sint64: [Swift.Int64] - public var rep_fixed64: [Swift.UInt64] - public var rep_sfixed64: [Swift.Int64] - public var rep_bool: [Swift.Bool] - public var rep_float: [Swift.Float] - public var rep_double: [Swift.Double] - public var rep_string: [Swift.String] - public var rep_bytes: [Foundation.Data] - public var rep_nested_enum: [AllTypes.NestedEnum] - public var rep_nested_message: [AllTypes.NestedMessage] - public var pack_int32: [Swift.Int32] - public var pack_uint32: [Swift.UInt32] - public var pack_sint32: [Swift.Int32] - public var pack_fixed32: [Swift.UInt32] - public var pack_sfixed32: [Swift.Int32] - public var pack_int64: [Swift.Int64] - public var pack_uint64: [Swift.UInt64] - public var pack_sint64: [Swift.Int64] - public var pack_fixed64: [Swift.UInt64] - public var pack_sfixed64: [Swift.Int64] - public var pack_bool: [Swift.Bool] - public var pack_float: [Swift.Float] - public var pack_double: [Swift.Double] - public var pack_nested_enum: [AllTypes.NestedEnum] + public var rep_int32: [Swift.Int32] = [] + public var rep_uint32: [Swift.UInt32] = [] + public var rep_sint32: [Swift.Int32] = [] + public var rep_fixed32: [Swift.UInt32] = [] + public var rep_sfixed32: [Swift.Int32] = [] + public var rep_int64: [Swift.Int64] = [] + public var rep_uint64: [Swift.UInt64] = [] + public var rep_sint64: [Swift.Int64] = [] + public var rep_fixed64: [Swift.UInt64] = [] + public var rep_sfixed64: [Swift.Int64] = [] + public var rep_bool: [Swift.Bool] = [] + public var rep_float: [Swift.Float] = [] + public var rep_double: [Swift.Double] = [] + public var rep_string: [Swift.String] = [] + public var rep_bytes: [Foundation.Data] = [] + public var rep_nested_enum: [AllTypes.NestedEnum] = [] + public var rep_nested_message: [AllTypes.NestedMessage] = [] + public var pack_int32: [Swift.Int32] = [] + public var pack_uint32: [Swift.UInt32] = [] + public var pack_sint32: [Swift.Int32] = [] + public var pack_fixed32: [Swift.UInt32] = [] + public var pack_sfixed32: [Swift.Int32] = [] + public var pack_int64: [Swift.Int64] = [] + public var pack_uint64: [Swift.UInt64] = [] + public var pack_sint64: [Swift.Int64] = [] + public var pack_fixed64: [Swift.UInt64] = [] + public var pack_sfixed64: [Swift.Int64] = [] + public var pack_bool: [Swift.Bool] = [] + public var pack_float: [Swift.Float] = [] + public var pack_double: [Swift.Double] = [] + public var pack_nested_enum: [AllTypes.NestedEnum] = [] @Wire.Defaulted(defaultValue: Swift.Int32.max) public var default_int32: Swift.Int32? @Wire.Defaulted(defaultValue: Swift.UInt32.max) @@ -449,22 +896,22 @@ extension AllTypes { public var default_bytes: Foundation.Data? @Wire.Defaulted(defaultValue: AllTypes.NestedEnum.A) public var default_nested_enum: AllTypes.NestedEnum? - public var map_int32_int32: [Swift.Int32 : Swift.Int32] - public var map_string_string: [Swift.String : Swift.String] - public var map_string_message: [Swift.String : AllTypes.NestedMessage] - public var map_string_enum: [Swift.String : AllTypes.NestedEnum] - public var array_int32: [Swift.Int32] - public var array_uint32: [Swift.UInt32] - public var array_sint32: [Swift.Int32] - public var array_fixed32: [Swift.UInt32] - public var array_sfixed32: [Swift.Int32] - public var array_int64: [Swift.Int64] - public var array_uint64: [Swift.UInt64] - public var array_sint64: [Swift.Int64] - public var array_fixed64: [Swift.UInt64] - public var array_sfixed64: [Swift.Int64] - public var array_float: [Swift.Float] - public var array_double: [Swift.Double] + public var map_int32_int32: [Swift.Int32 : Swift.Int32] = [:] + public var map_string_string: [Swift.String : Swift.String] = [:] + public var map_string_message: [Swift.String : AllTypes.NestedMessage] = [:] + public var map_string_enum: [Swift.String : AllTypes.NestedEnum] = [:] + public var array_int32: [Swift.Int32] = [] + public var array_uint32: [Swift.UInt32] = [] + public var array_sint32: [Swift.Int32] = [] + public var array_fixed32: [Swift.UInt32] = [] + public var array_sfixed32: [Swift.Int32] = [] + public var array_int64: [Swift.Int64] = [] + public var array_uint64: [Swift.UInt64] = [] + public var array_sint64: [Swift.Int64] = [] + public var array_fixed64: [Swift.UInt64] = [] + public var array_sfixed64: [Swift.Int64] = [] + public var array_float: [Swift.Float] = [] + public var array_double: [Swift.Double] = [] public var ext_opt_int32: Swift.Int32? public var ext_opt_uint32: Swift.UInt32? public var ext_opt_sint32: Swift.Int32? @@ -482,57 +929,40 @@ extension AllTypes { public var ext_opt_bytes: Foundation.Data? public var ext_opt_nested_enum: AllTypes.NestedEnum? public var ext_opt_nested_message: AllTypes.NestedMessage? - public var ext_rep_int32: [Swift.Int32] - public var ext_rep_uint32: [Swift.UInt32] - public var ext_rep_sint32: [Swift.Int32] - public var ext_rep_fixed32: [Swift.UInt32] - public var ext_rep_sfixed32: [Swift.Int32] - public var ext_rep_int64: [Swift.Int64] - public var ext_rep_uint64: [Swift.UInt64] - public var ext_rep_sint64: [Swift.Int64] - public var ext_rep_fixed64: [Swift.UInt64] - public var ext_rep_sfixed64: [Swift.Int64] - public var ext_rep_bool: [Swift.Bool] - public var ext_rep_float: [Swift.Float] - public var ext_rep_double: [Swift.Double] - public var ext_rep_string: [Swift.String] - public var ext_rep_bytes: [Foundation.Data] - public var ext_rep_nested_enum: [AllTypes.NestedEnum] - public var ext_rep_nested_message: [AllTypes.NestedMessage] - public var ext_pack_int32: [Swift.Int32] - public var ext_pack_uint32: [Swift.UInt32] - public var ext_pack_sint32: [Swift.Int32] - public var ext_pack_fixed32: [Swift.UInt32] - public var ext_pack_sfixed32: [Swift.Int32] - public var ext_pack_int64: [Swift.Int64] - public var ext_pack_uint64: [Swift.UInt64] - public var ext_pack_sint64: [Swift.Int64] - public var ext_pack_fixed64: [Swift.UInt64] - public var ext_pack_sfixed64: [Swift.Int64] - public var ext_pack_bool: [Swift.Bool] - public var ext_pack_float: [Swift.Float] - public var ext_pack_double: [Swift.Double] - public var ext_pack_nested_enum: [AllTypes.NestedEnum] + public var ext_rep_int32: [Swift.Int32] = [] + public var ext_rep_uint32: [Swift.UInt32] = [] + public var ext_rep_sint32: [Swift.Int32] = [] + public var ext_rep_fixed32: [Swift.UInt32] = [] + public var ext_rep_sfixed32: [Swift.Int32] = [] + public var ext_rep_int64: [Swift.Int64] = [] + public var ext_rep_uint64: [Swift.UInt64] = [] + public var ext_rep_sint64: [Swift.Int64] = [] + public var ext_rep_fixed64: [Swift.UInt64] = [] + public var ext_rep_sfixed64: [Swift.Int64] = [] + public var ext_rep_bool: [Swift.Bool] = [] + public var ext_rep_float: [Swift.Float] = [] + public var ext_rep_double: [Swift.Double] = [] + public var ext_rep_string: [Swift.String] = [] + public var ext_rep_bytes: [Foundation.Data] = [] + public var ext_rep_nested_enum: [AllTypes.NestedEnum] = [] + public var ext_rep_nested_message: [AllTypes.NestedMessage] = [] + public var ext_pack_int32: [Swift.Int32] = [] + public var ext_pack_uint32: [Swift.UInt32] = [] + public var ext_pack_sint32: [Swift.Int32] = [] + public var ext_pack_fixed32: [Swift.UInt32] = [] + public var ext_pack_sfixed32: [Swift.Int32] = [] + public var ext_pack_int64: [Swift.Int64] = [] + public var ext_pack_uint64: [Swift.UInt64] = [] + public var ext_pack_sint64: [Swift.Int64] = [] + public var ext_pack_fixed64: [Swift.UInt64] = [] + public var ext_pack_sfixed64: [Swift.Int64] = [] + public var ext_pack_bool: [Swift.Bool] = [] + public var ext_pack_float: [Swift.Float] = [] + public var ext_pack_double: [Swift.Double] = [] + public var ext_pack_nested_enum: [AllTypes.NestedEnum] = [] public var unknownFields: Foundation.Data = .init() public init( - opt_int32: Swift.Int32?, - opt_uint32: Swift.UInt32?, - opt_sint32: Swift.Int32?, - opt_fixed32: Swift.UInt32?, - opt_sfixed32: Swift.Int32?, - opt_int64: Swift.Int64?, - opt_uint64: Swift.UInt64?, - opt_sint64: Swift.Int64?, - opt_fixed64: Swift.UInt64?, - opt_sfixed64: Swift.Int64?, - opt_bool: Swift.Bool?, - opt_float: Swift.Float?, - opt_double: Swift.Double?, - opt_string: Swift.String?, - opt_bytes: Foundation.Data?, - opt_nested_enum: AllTypes.NestedEnum?, - opt_nested_message: AllTypes.NestedMessage?, req_int32: Swift.Int32, req_uint32: Swift.UInt32, req_sint32: Swift.Int32, @@ -550,135 +980,8 @@ extension AllTypes { req_bytes: Foundation.Data, req_nested_enum: AllTypes.NestedEnum, req_nested_message: AllTypes.NestedMessage, - rep_int32: [Swift.Int32], - rep_uint32: [Swift.UInt32], - rep_sint32: [Swift.Int32], - rep_fixed32: [Swift.UInt32], - rep_sfixed32: [Swift.Int32], - rep_int64: [Swift.Int64], - rep_uint64: [Swift.UInt64], - rep_sint64: [Swift.Int64], - rep_fixed64: [Swift.UInt64], - rep_sfixed64: [Swift.Int64], - rep_bool: [Swift.Bool], - rep_float: [Swift.Float], - rep_double: [Swift.Double], - rep_string: [Swift.String], - rep_bytes: [Foundation.Data], - rep_nested_enum: [AllTypes.NestedEnum], - rep_nested_message: [AllTypes.NestedMessage], - pack_int32: [Swift.Int32], - pack_uint32: [Swift.UInt32], - pack_sint32: [Swift.Int32], - pack_fixed32: [Swift.UInt32], - pack_sfixed32: [Swift.Int32], - pack_int64: [Swift.Int64], - pack_uint64: [Swift.UInt64], - pack_sint64: [Swift.Int64], - pack_fixed64: [Swift.UInt64], - pack_sfixed64: [Swift.Int64], - pack_bool: [Swift.Bool], - pack_float: [Swift.Float], - pack_double: [Swift.Double], - pack_nested_enum: [AllTypes.NestedEnum], - default_int32: Swift.Int32?, - default_uint32: Swift.UInt32?, - default_sint32: Swift.Int32?, - default_fixed32: Swift.UInt32?, - default_sfixed32: Swift.Int32?, - default_int64: Swift.Int64?, - default_uint64: Swift.UInt64?, - default_sint64: Swift.Int64?, - default_fixed64: Swift.UInt64?, - default_sfixed64: Swift.Int64?, - default_bool: Swift.Bool?, - default_float: Swift.Float?, - default_double: Swift.Double?, - default_string: Swift.String?, - default_bytes: Foundation.Data?, - default_nested_enum: AllTypes.NestedEnum?, - map_int32_int32: [Swift.Int32 : Swift.Int32], - map_string_string: [Swift.String : Swift.String], - map_string_message: [Swift.String : AllTypes.NestedMessage], - map_string_enum: [Swift.String : AllTypes.NestedEnum], - array_int32: [Swift.Int32], - array_uint32: [Swift.UInt32], - array_sint32: [Swift.Int32], - array_fixed32: [Swift.UInt32], - array_sfixed32: [Swift.Int32], - array_int64: [Swift.Int64], - array_uint64: [Swift.UInt64], - array_sint64: [Swift.Int64], - array_fixed64: [Swift.UInt64], - array_sfixed64: [Swift.Int64], - array_float: [Swift.Float], - array_double: [Swift.Double], - ext_opt_int32: Swift.Int32?, - ext_opt_uint32: Swift.UInt32?, - ext_opt_sint32: Swift.Int32?, - ext_opt_fixed32: Swift.UInt32?, - ext_opt_sfixed32: Swift.Int32?, - ext_opt_int64: Swift.Int64?, - ext_opt_uint64: Swift.UInt64?, - ext_opt_sint64: Swift.Int64?, - ext_opt_fixed64: Swift.UInt64?, - ext_opt_sfixed64: Swift.Int64?, - ext_opt_bool: Swift.Bool?, - ext_opt_float: Swift.Float?, - ext_opt_double: Swift.Double?, - ext_opt_string: Swift.String?, - ext_opt_bytes: Foundation.Data?, - ext_opt_nested_enum: AllTypes.NestedEnum?, - ext_opt_nested_message: AllTypes.NestedMessage?, - ext_rep_int32: [Swift.Int32], - ext_rep_uint32: [Swift.UInt32], - ext_rep_sint32: [Swift.Int32], - ext_rep_fixed32: [Swift.UInt32], - ext_rep_sfixed32: [Swift.Int32], - ext_rep_int64: [Swift.Int64], - ext_rep_uint64: [Swift.UInt64], - ext_rep_sint64: [Swift.Int64], - ext_rep_fixed64: [Swift.UInt64], - ext_rep_sfixed64: [Swift.Int64], - ext_rep_bool: [Swift.Bool], - ext_rep_float: [Swift.Float], - ext_rep_double: [Swift.Double], - ext_rep_string: [Swift.String], - ext_rep_bytes: [Foundation.Data], - ext_rep_nested_enum: [AllTypes.NestedEnum], - ext_rep_nested_message: [AllTypes.NestedMessage], - ext_pack_int32: [Swift.Int32], - ext_pack_uint32: [Swift.UInt32], - ext_pack_sint32: [Swift.Int32], - ext_pack_fixed32: [Swift.UInt32], - ext_pack_sfixed32: [Swift.Int32], - ext_pack_int64: [Swift.Int64], - ext_pack_uint64: [Swift.UInt64], - ext_pack_sint64: [Swift.Int64], - ext_pack_fixed64: [Swift.UInt64], - ext_pack_sfixed64: [Swift.Int64], - ext_pack_bool: [Swift.Bool], - ext_pack_float: [Swift.Float], - ext_pack_double: [Swift.Double], - ext_pack_nested_enum: [AllTypes.NestedEnum] + configure: (inout Self) -> Swift.Void = { _ in } ) { - self.opt_int32 = opt_int32 - self.opt_uint32 = opt_uint32 - self.opt_sint32 = opt_sint32 - self.opt_fixed32 = opt_fixed32 - self.opt_sfixed32 = opt_sfixed32 - self.opt_int64 = opt_int64 - self.opt_uint64 = opt_uint64 - self.opt_sint64 = opt_sint64 - self.opt_fixed64 = opt_fixed64 - self.opt_sfixed64 = opt_sfixed64 - self.opt_bool = opt_bool - self.opt_float = opt_float - self.opt_double = opt_double - self.opt_string = opt_string - self.opt_bytes = opt_bytes - self.opt_nested_enum = opt_nested_enum - self.opt_nested_message = opt_nested_message self.req_int32 = req_int32 self.req_uint32 = req_uint32 self.req_sint32 = req_sint32 @@ -696,117 +999,7 @@ extension AllTypes { self.req_bytes = req_bytes self.req_nested_enum = req_nested_enum self.req_nested_message = req_nested_message - self.rep_int32 = rep_int32 - self.rep_uint32 = rep_uint32 - self.rep_sint32 = rep_sint32 - self.rep_fixed32 = rep_fixed32 - self.rep_sfixed32 = rep_sfixed32 - self.rep_int64 = rep_int64 - self.rep_uint64 = rep_uint64 - self.rep_sint64 = rep_sint64 - self.rep_fixed64 = rep_fixed64 - self.rep_sfixed64 = rep_sfixed64 - self.rep_bool = rep_bool - self.rep_float = rep_float - self.rep_double = rep_double - self.rep_string = rep_string - self.rep_bytes = rep_bytes - self.rep_nested_enum = rep_nested_enum - self.rep_nested_message = rep_nested_message - self.pack_int32 = pack_int32 - self.pack_uint32 = pack_uint32 - self.pack_sint32 = pack_sint32 - self.pack_fixed32 = pack_fixed32 - self.pack_sfixed32 = pack_sfixed32 - self.pack_int64 = pack_int64 - self.pack_uint64 = pack_uint64 - self.pack_sint64 = pack_sint64 - self.pack_fixed64 = pack_fixed64 - self.pack_sfixed64 = pack_sfixed64 - self.pack_bool = pack_bool - self.pack_float = pack_float - self.pack_double = pack_double - self.pack_nested_enum = pack_nested_enum - _default_int32.wrappedValue = default_int32 - _default_uint32.wrappedValue = default_uint32 - _default_sint32.wrappedValue = default_sint32 - _default_fixed32.wrappedValue = default_fixed32 - _default_sfixed32.wrappedValue = default_sfixed32 - _default_int64.wrappedValue = default_int64 - _default_uint64.wrappedValue = default_uint64 - _default_sint64.wrappedValue = default_sint64 - _default_fixed64.wrappedValue = default_fixed64 - _default_sfixed64.wrappedValue = default_sfixed64 - _default_bool.wrappedValue = default_bool - _default_float.wrappedValue = default_float - _default_double.wrappedValue = default_double - _default_string.wrappedValue = default_string - _default_bytes.wrappedValue = default_bytes - _default_nested_enum.wrappedValue = default_nested_enum - self.map_int32_int32 = map_int32_int32 - self.map_string_string = map_string_string - self.map_string_message = map_string_message - self.map_string_enum = map_string_enum - self.array_int32 = array_int32 - self.array_uint32 = array_uint32 - self.array_sint32 = array_sint32 - self.array_fixed32 = array_fixed32 - self.array_sfixed32 = array_sfixed32 - self.array_int64 = array_int64 - self.array_uint64 = array_uint64 - self.array_sint64 = array_sint64 - self.array_fixed64 = array_fixed64 - self.array_sfixed64 = array_sfixed64 - self.array_float = array_float - self.array_double = array_double - self.ext_opt_int32 = ext_opt_int32 - self.ext_opt_uint32 = ext_opt_uint32 - self.ext_opt_sint32 = ext_opt_sint32 - self.ext_opt_fixed32 = ext_opt_fixed32 - self.ext_opt_sfixed32 = ext_opt_sfixed32 - self.ext_opt_int64 = ext_opt_int64 - self.ext_opt_uint64 = ext_opt_uint64 - self.ext_opt_sint64 = ext_opt_sint64 - self.ext_opt_fixed64 = ext_opt_fixed64 - self.ext_opt_sfixed64 = ext_opt_sfixed64 - self.ext_opt_bool = ext_opt_bool - self.ext_opt_float = ext_opt_float - self.ext_opt_double = ext_opt_double - self.ext_opt_string = ext_opt_string - self.ext_opt_bytes = ext_opt_bytes - self.ext_opt_nested_enum = ext_opt_nested_enum - self.ext_opt_nested_message = ext_opt_nested_message - self.ext_rep_int32 = ext_rep_int32 - self.ext_rep_uint32 = ext_rep_uint32 - self.ext_rep_sint32 = ext_rep_sint32 - self.ext_rep_fixed32 = ext_rep_fixed32 - self.ext_rep_sfixed32 = ext_rep_sfixed32 - self.ext_rep_int64 = ext_rep_int64 - self.ext_rep_uint64 = ext_rep_uint64 - self.ext_rep_sint64 = ext_rep_sint64 - self.ext_rep_fixed64 = ext_rep_fixed64 - self.ext_rep_sfixed64 = ext_rep_sfixed64 - self.ext_rep_bool = ext_rep_bool - self.ext_rep_float = ext_rep_float - self.ext_rep_double = ext_rep_double - self.ext_rep_string = ext_rep_string - self.ext_rep_bytes = ext_rep_bytes - self.ext_rep_nested_enum = ext_rep_nested_enum - self.ext_rep_nested_message = ext_rep_nested_message - self.ext_pack_int32 = ext_pack_int32 - self.ext_pack_uint32 = ext_pack_uint32 - self.ext_pack_sint32 = ext_pack_sint32 - self.ext_pack_fixed32 = ext_pack_fixed32 - self.ext_pack_sfixed32 = ext_pack_sfixed32 - self.ext_pack_int64 = ext_pack_int64 - self.ext_pack_uint64 = ext_pack_uint64 - self.ext_pack_sint64 = ext_pack_sint64 - self.ext_pack_fixed64 = ext_pack_fixed64 - self.ext_pack_sfixed64 = ext_pack_sfixed64 - self.ext_pack_bool = ext_pack_bool - self.ext_pack_float = ext_pack_float - self.ext_pack_double = ext_pack_double - self.ext_pack_nested_enum = ext_pack_nested_enum + configure(&self) } } diff --git a/wire-tests-swift/src/main/swift/DeprecatedProto.swift b/wire-tests-swift/src/main/swift/DeprecatedProto.swift index 73cfe54d74..bebe746285 100644 --- a/wire-tests-swift/src/main/swift/DeprecatedProto.swift +++ b/wire-tests-swift/src/main/swift/DeprecatedProto.swift @@ -9,11 +9,23 @@ public struct DeprecatedProto { public var foo: String? public var unknownFields: Foundation.Data = .init() - public init(foo: String? = nil) { + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension DeprecatedProto { + + @_disfavoredOverload + @available(*, deprecated) + public init(foo: Swift.String? = nil) { self.foo = foo } } +#endif #if !WIRE_REMOVE_EQUATABLE extension DeprecatedProto : Equatable { diff --git a/wire-tests-swift/src/main/swift/EmbeddedMessage.swift b/wire-tests-swift/src/main/swift/EmbeddedMessage.swift index ebd0dcda8e..fdae982b8f 100644 --- a/wire-tests-swift/src/main/swift/EmbeddedMessage.swift +++ b/wire-tests-swift/src/main/swift/EmbeddedMessage.swift @@ -5,16 +5,28 @@ import Wire public struct EmbeddedMessage { - public var inner_repeated_number: [Int32] + public var inner_repeated_number: [Int32] = [] public var inner_number_after: Int32? public var unknownFields: Foundation.Data = .init() - public init(inner_repeated_number: [Int32] = [], inner_number_after: Int32? = nil) { + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension EmbeddedMessage { + + @_disfavoredOverload + @available(*, deprecated) + public init(inner_repeated_number: [Swift.Int32] = [], inner_number_after: Swift.Int32? = nil) { self.inner_repeated_number = inner_repeated_number self.inner_number_after = inner_number_after } } +#endif #if !WIRE_REMOVE_EQUATABLE extension EmbeddedMessage : Equatable { diff --git a/wire-tests-swift/src/main/swift/ExternalMessage.swift b/wire-tests-swift/src/main/swift/ExternalMessage.swift index dfbdea2400..d8f32a2857 100644 --- a/wire-tests-swift/src/main/swift/ExternalMessage.swift +++ b/wire-tests-swift/src/main/swift/ExternalMessage.swift @@ -9,11 +9,23 @@ public struct ExternalMessage { public var f: Float? public var unknownFields: Foundation.Data = .init() - public init(f: Float? = nil) { + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension ExternalMessage { + + @_disfavoredOverload + @available(*, deprecated) + public init(f: Swift.Float? = nil) { _f.wrappedValue = f } } +#endif #if !WIRE_REMOVE_EQUATABLE extension ExternalMessage : Equatable { diff --git a/wire-tests-swift/src/main/swift/FooBar.swift b/wire-tests-swift/src/main/swift/FooBar.swift index ece497cb82..0a2fe93fab 100644 --- a/wire-tests-swift/src/main/swift/FooBar.swift +++ b/wire-tests-swift/src/main/swift/FooBar.swift @@ -9,36 +9,16 @@ public struct FooBar { public var bar: String? public var baz: FooBar.Nested? public var qux: UInt64? - public var fred: [Float] + public var fred: [Float] = [] public var daisy: Double? - public var nested: [FooBar] + public var nested: [FooBar] = [] public var ext: FooBar.FooBarBazEnum? - public var rep: [FooBar.FooBarBazEnum] + public var rep: [FooBar.FooBarBazEnum] = [] public var more_string: String? public var unknownFields: Foundation.Data = .init() - public init( - foo: Int32? = nil, - bar: String? = nil, - baz: FooBar.Nested? = nil, - qux: UInt64? = nil, - fred: [Float] = [], - daisy: Double? = nil, - nested: [FooBar] = [], - ext: FooBar.FooBarBazEnum? = nil, - rep: [FooBar.FooBarBazEnum] = [], - more_string: String? = nil - ) { - self.foo = foo - self.bar = bar - self.baz = baz - self.qux = qux - self.fred = fred - self.daisy = daisy - self.nested = nested - self.ext = ext - self.rep = rep - self.more_string = more_string + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) } public struct Nested { @@ -46,19 +26,19 @@ public struct FooBar { public var value: FooBar.FooBarBazEnum? public var unknownFields: Foundation.Data = .init() - public init(value: FooBar.FooBarBazEnum? = nil) { - self.value = value + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) } } public struct More { - public var serial: [Int32] + public var serial: [Int32] = [] public var unknownFields: Foundation.Data = .init() - public init(serial: [Int32] = []) { - self.serial = serial + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) } } @@ -81,6 +61,50 @@ public struct FooBar { } +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension FooBar { + + @_disfavoredOverload + @available(*, deprecated) + public init( + foo: Swift.Int32? = nil, + bar: Swift.String? = nil, + baz: FooBar.Nested? = nil, + qux: Swift.UInt64? = nil, + fred: [Swift.Float] = [], + daisy: Swift.Double? = nil, + nested: [FooBar] = [], + ext: FooBar.FooBarBazEnum? = nil, + rep: [FooBar.FooBarBazEnum] = [], + more_string: Swift.String? = nil + ) { + self.foo = foo + self.bar = bar + self.baz = baz + self.qux = qux + self.fred = fred + self.daisy = daisy + self.nested = nested + self.ext = ext + self.rep = rep + self.more_string = more_string + } + +} +#endif + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension FooBar.Nested { + + @_disfavoredOverload + @available(*, deprecated) + public init(value: FooBar.FooBarBazEnum? = nil) { + self.value = value + } + +} +#endif + #if !WIRE_REMOVE_EQUATABLE extension FooBar.Nested : Equatable { } @@ -145,6 +169,18 @@ extension FooBar.Nested : Codable { } #endif +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension FooBar.More { + + @_disfavoredOverload + @available(*, deprecated) + public init(serial: [Swift.Int32] = []) { + self.serial = serial + } + +} +#endif + #if !WIRE_REMOVE_EQUATABLE extension FooBar.More : Equatable { } diff --git a/wire-tests-swift/src/main/swift/ForeignMessage.swift b/wire-tests-swift/src/main/swift/ForeignMessage.swift index f25034ca3e..f0ef281b2e 100644 --- a/wire-tests-swift/src/main/swift/ForeignMessage.swift +++ b/wire-tests-swift/src/main/swift/ForeignMessage.swift @@ -8,11 +8,23 @@ public struct ForeignMessage { public var i: Int32? public var unknownFields: Foundation.Data = .init() - public init(i: Int32? = nil) { + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension ForeignMessage { + + @_disfavoredOverload + @available(*, deprecated) + public init(i: Swift.Int32? = nil) { self.i = i } } +#endif #if !WIRE_REMOVE_EQUATABLE extension ForeignMessage : Equatable { diff --git a/wire-tests-swift/src/main/swift/Form.swift b/wire-tests-swift/src/main/swift/Form.swift index 3cbed2916c..96efc8f95e 100644 --- a/wire-tests-swift/src/main/swift/Form.swift +++ b/wire-tests-swift/src/main/swift/Form.swift @@ -9,9 +9,8 @@ public struct Form { public var decision: Decision? public var unknownFields: Foundation.Data = .init() - public init(choice: Choice? = nil, decision: Decision? = nil) { - self.choice = choice - self.decision = decision + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) } public enum Choice { @@ -125,8 +124,8 @@ public struct Form { public var text: String? public var unknownFields: Foundation.Data = .init() - public init(text: String? = nil) { - self.text = text + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) } } @@ -187,6 +186,19 @@ public struct Form { } +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension Form { + + @_disfavoredOverload + @available(*, deprecated) + public init(choice: Choice? = nil, decision: Decision? = nil) { + self.choice = choice + self.decision = decision + } + +} +#endif + #if !WIRE_REMOVE_EQUATABLE extension Form.Choice : Equatable { } @@ -484,6 +496,18 @@ extension Form.SpacerElement : Codable { } #endif +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension Form.TextElement { + + @_disfavoredOverload + @available(*, deprecated) + public init(text: Swift.String? = nil) { + self.text = text + } + +} +#endif + #if !WIRE_REMOVE_EQUATABLE extension Form.TextElement : Equatable { } diff --git a/wire-tests-swift/src/main/swift/Mappy.swift b/wire-tests-swift/src/main/swift/Mappy.swift index d9662b3ae4..260c302623 100644 --- a/wire-tests-swift/src/main/swift/Mappy.swift +++ b/wire-tests-swift/src/main/swift/Mappy.swift @@ -5,14 +5,26 @@ import Wire public struct Mappy { - public var things: [String : Thing] + public var things: [String : Thing] = [:] public var unknownFields: Foundation.Data = .init() - public init(things: [String : Thing] = [:]) { + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension Mappy { + + @_disfavoredOverload + @available(*, deprecated) + public init(things: [Swift.String : Thing] = [:]) { self.things = things } } +#endif #if !WIRE_REMOVE_EQUATABLE extension Mappy : Equatable { diff --git a/wire-tests-swift/src/main/swift/MappyTwo.swift b/wire-tests-swift/src/main/swift/MappyTwo.swift index ef9dc04f08..05abd21582 100644 --- a/wire-tests-swift/src/main/swift/MappyTwo.swift +++ b/wire-tests-swift/src/main/swift/MappyTwo.swift @@ -5,22 +5,14 @@ import Wire public struct MappyTwo { - public var string_enums: [String : MappyTwo.ValueEnum] - public var int_things: [Int64 : Thing] - public var string_ints: [String : Int64] - public var int_things_two: [Int32 : Thing] + public var string_enums: [String : MappyTwo.ValueEnum] = [:] + public var int_things: [Int64 : Thing] = [:] + public var string_ints: [String : Int64] = [:] + public var int_things_two: [Int32 : Thing] = [:] public var unknownFields: Foundation.Data = .init() - public init( - string_enums: [String : MappyTwo.ValueEnum] = [:], - int_things: [Int64 : Thing] = [:], - string_ints: [String : Int64] = [:], - int_things_two: [Int32 : Thing] = [:] - ) { - self.string_enums = string_enums - self.int_things = int_things - self.string_ints = string_ints - self.int_things_two = int_things_two + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) } public enum ValueEnum : UInt32, CaseIterable, ProtoEnum { @@ -41,6 +33,26 @@ public struct MappyTwo { } +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension MappyTwo { + + @_disfavoredOverload + @available(*, deprecated) + public init( + string_enums: [Swift.String : MappyTwo.ValueEnum] = [:], + int_things: [Swift.Int64 : Thing] = [:], + string_ints: [Swift.String : Swift.Int64] = [:], + int_things_two: [Swift.Int32 : Thing] = [:] + ) { + self.string_enums = string_enums + self.int_things = int_things + self.string_ints = string_ints + self.int_things_two = int_things_two + } + +} +#endif + #if swift(>=5.5) extension MappyTwo.ValueEnum : Sendable { } diff --git a/wire-tests-swift/src/main/swift/MessageUsingMultipleEnums.swift b/wire-tests-swift/src/main/swift/MessageUsingMultipleEnums.swift index 5e894f127b..3c166c9c95 100644 --- a/wire-tests-swift/src/main/swift/MessageUsingMultipleEnums.swift +++ b/wire-tests-swift/src/main/swift/MessageUsingMultipleEnums.swift @@ -12,12 +12,24 @@ public struct MessageUsingMultipleEnums { public var b: OtherMessageWithStatus.Status? public var unknownFields: Foundation.Data = .init() + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension MessageUsingMultipleEnums { + + @_disfavoredOverload + @available(*, deprecated) public init(a: MessageWithStatus.Status? = nil, b: OtherMessageWithStatus.Status? = nil) { self.a = a self.b = b } } +#endif #if !WIRE_REMOVE_EQUATABLE extension MessageUsingMultipleEnums : Equatable { diff --git a/wire-tests-swift/src/main/swift/ModelEvaluation.swift b/wire-tests-swift/src/main/swift/ModelEvaluation.swift index 696625cbd8..c94877532e 100644 --- a/wire-tests-swift/src/main/swift/ModelEvaluation.swift +++ b/wire-tests-swift/src/main/swift/ModelEvaluation.swift @@ -22,13 +22,24 @@ public struct ModelEvaluation { public var name: String? public var score: Double? - public var models: [String : ModelEvaluation] + public var models: [String : ModelEvaluation] = [:] public var unknownFields: Foundation.Data = .init() + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension ModelEvaluation { + + @_disfavoredOverload + @available(*, deprecated) public init( - name: String? = nil, - score: Double? = nil, - models: [String : ModelEvaluation] = [:] + name: Swift.String? = nil, + score: Swift.Double? = nil, + models: [Swift.String : ModelEvaluation] = [:] ) { self.name = name self.score = score @@ -36,6 +47,7 @@ public struct ModelEvaluation { } } +#endif #if !WIRE_REMOVE_EQUATABLE extension ModelEvaluation : Equatable { diff --git a/wire-tests-swift/src/main/swift/NestedVersionOne.swift b/wire-tests-swift/src/main/swift/NestedVersionOne.swift index 201ca466e9..31e1f1537e 100644 --- a/wire-tests-swift/src/main/swift/NestedVersionOne.swift +++ b/wire-tests-swift/src/main/swift/NestedVersionOne.swift @@ -8,11 +8,23 @@ public struct NestedVersionOne { public var i: Int32? public var unknownFields: Foundation.Data = .init() - public init(i: Int32? = nil) { + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension NestedVersionOne { + + @_disfavoredOverload + @available(*, deprecated) + public init(i: Swift.Int32? = nil) { self.i = i } } +#endif #if !WIRE_REMOVE_EQUATABLE extension NestedVersionOne : Equatable { diff --git a/wire-tests-swift/src/main/swift/NestedVersionTwo.swift b/wire-tests-swift/src/main/swift/NestedVersionTwo.swift index 61c62b62f5..37425df8c1 100644 --- a/wire-tests-swift/src/main/swift/NestedVersionTwo.swift +++ b/wire-tests-swift/src/main/swift/NestedVersionTwo.swift @@ -10,16 +10,27 @@ public struct NestedVersionTwo { public var v2_s: String? public var v2_f32: UInt32? public var v2_f64: UInt64? - public var v2_rs: [String] + public var v2_rs: [String] = [] public var unknownFields: Foundation.Data = .init() + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension NestedVersionTwo { + + @_disfavoredOverload + @available(*, deprecated) public init( - i: Int32? = nil, - v2_i: Int32? = nil, - v2_s: String? = nil, - v2_f32: UInt32? = nil, - v2_f64: UInt64? = nil, - v2_rs: [String] = [] + i: Swift.Int32? = nil, + v2_i: Swift.Int32? = nil, + v2_s: Swift.String? = nil, + v2_f32: Swift.UInt32? = nil, + v2_f64: Swift.UInt64? = nil, + v2_rs: [Swift.String] = [] ) { self.i = i self.v2_i = v2_i @@ -30,6 +41,7 @@ public struct NestedVersionTwo { } } +#endif #if !WIRE_REMOVE_EQUATABLE extension NestedVersionTwo : Equatable { diff --git a/wire-tests-swift/src/main/swift/OneOfMessage.swift b/wire-tests-swift/src/main/swift/OneOfMessage.swift index 98bf621407..bcd5b43880 100644 --- a/wire-tests-swift/src/main/swift/OneOfMessage.swift +++ b/wire-tests-swift/src/main/swift/OneOfMessage.swift @@ -14,8 +14,8 @@ public struct OneOfMessage { public var choice: Choice? public var unknownFields: Foundation.Data = .init() - public init(choice: Choice? = nil) { - self.choice = choice + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) } public enum Choice { @@ -45,6 +45,18 @@ public struct OneOfMessage { } +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension OneOfMessage { + + @_disfavoredOverload + @available(*, deprecated) + public init(choice: Choice? = nil) { + self.choice = choice + } + +} +#endif + #if !WIRE_REMOVE_EQUATABLE extension OneOfMessage.Choice : Equatable { } diff --git a/wire-tests-swift/src/main/swift/OptionalEnumUser.swift b/wire-tests-swift/src/main/swift/OptionalEnumUser.swift index f175e673e0..388808ae82 100644 --- a/wire-tests-swift/src/main/swift/OptionalEnumUser.swift +++ b/wire-tests-swift/src/main/swift/OptionalEnumUser.swift @@ -8,8 +8,8 @@ public struct OptionalEnumUser { public var optional_enum: OptionalEnumUser.OptionalEnum? public var unknownFields: Foundation.Data = .init() - public init(optional_enum: OptionalEnumUser.OptionalEnum? = nil) { - self.optional_enum = optional_enum + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) } public enum OptionalEnum : UInt32, CaseIterable, ProtoEnum { @@ -28,6 +28,18 @@ public struct OptionalEnumUser { } +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension OptionalEnumUser { + + @_disfavoredOverload + @available(*, deprecated) + public init(optional_enum: OptionalEnumUser.OptionalEnum? = nil) { + self.optional_enum = optional_enum + } + +} +#endif + #if swift(>=5.5) extension OptionalEnumUser.OptionalEnum : Sendable { } diff --git a/wire-tests-swift/src/main/swift/OuterMessage.swift b/wire-tests-swift/src/main/swift/OuterMessage.swift index 53192661fe..1de6729ac9 100644 --- a/wire-tests-swift/src/main/swift/OuterMessage.swift +++ b/wire-tests-swift/src/main/swift/OuterMessage.swift @@ -9,12 +9,24 @@ public struct OuterMessage { public var embedded_message: EmbeddedMessage? public var unknownFields: Foundation.Data = .init() - public init(outer_number_before: Int32? = nil, embedded_message: EmbeddedMessage? = nil) { + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension OuterMessage { + + @_disfavoredOverload + @available(*, deprecated) + public init(outer_number_before: Swift.Int32? = nil, embedded_message: EmbeddedMessage? = nil) { self.outer_number_before = outer_number_before self.embedded_message = embedded_message } } +#endif #if !WIRE_REMOVE_EQUATABLE extension OuterMessage : Equatable { diff --git a/wire-tests-swift/src/main/swift/Percents.swift b/wire-tests-swift/src/main/swift/Percents.swift index 083e2b9ed7..dd4e8f8664 100644 --- a/wire-tests-swift/src/main/swift/Percents.swift +++ b/wire-tests-swift/src/main/swift/Percents.swift @@ -11,11 +11,23 @@ public struct Percents { public var text: String? public var unknownFields: Foundation.Data = .init() - public init(text: String? = nil) { + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension Percents { + + @_disfavoredOverload + @available(*, deprecated) + public init(text: Swift.String? = nil) { self.text = text } } +#endif #if !WIRE_REMOVE_EQUATABLE extension Percents : Equatable { diff --git a/wire-tests-swift/src/main/swift/Person.swift b/wire-tests-swift/src/main/swift/Person.swift index ec187a9339..f24212712e 100644 --- a/wire-tests-swift/src/main/swift/Person.swift +++ b/wire-tests-swift/src/main/swift/Person.swift @@ -23,22 +23,18 @@ public struct Person { /** * A list of the customer's phone numbers. */ - public var phone: [Person.PhoneNumber] - public var aliases: [String] + public var phone: [Person.PhoneNumber] = [] + public var aliases: [String] = [] public var unknownFields: Foundation.Data = .init() public init( id: Int32, name: String, - email: String? = nil, - phone: [Person.PhoneNumber] = [], - aliases: [String] = [] + configure: (inout Self) -> Void = { _ in } ) { self.id = id self.name = name - self.email = email - self.phone = phone - self.aliases = aliases + configure(&self) } /** @@ -76,20 +72,55 @@ public struct Person { public var type: Person.PhoneType? public var unknownFields: Foundation.Data = .init() - public init(number: String, type: Person.PhoneType? = nil) { + public init(number: String, configure: (inout Self) -> Void = { _ in }) { self.number = number - _type.wrappedValue = type + configure(&self) } } } +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension Person { + + @_disfavoredOverload + @available(*, deprecated) + public init( + id: Swift.Int32, + name: Swift.String, + email: Swift.String? = nil, + phone: [Person.PhoneNumber] = [], + aliases: [Swift.String] = [] + ) { + self.id = id + self.name = name + self.email = email + self.phone = phone + self.aliases = aliases + } + +} +#endif + #if swift(>=5.5) extension Person.PhoneType : Sendable { } #endif +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension Person.PhoneNumber { + + @_disfavoredOverload + @available(*, deprecated) + public init(number: Swift.String, type: Person.PhoneType? = nil) { + self.number = number + _type.wrappedValue = type + } + +} +#endif + #if !WIRE_REMOVE_EQUATABLE extension Person.PhoneNumber : Equatable { } diff --git a/wire-tests-swift/src/main/swift/RedactedOneOf.swift b/wire-tests-swift/src/main/swift/RedactedOneOf.swift index ba1cc22430..2cd0a63254 100644 --- a/wire-tests-swift/src/main/swift/RedactedOneOf.swift +++ b/wire-tests-swift/src/main/swift/RedactedOneOf.swift @@ -8,8 +8,8 @@ public struct RedactedOneOf { public var a: A? public var unknownFields: Foundation.Data = .init() - public init(a: A? = nil) { - self.a = a + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) } public enum A { @@ -28,6 +28,18 @@ public struct RedactedOneOf { } +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension RedactedOneOf { + + @_disfavoredOverload + @available(*, deprecated) + public init(a: A? = nil) { + self.a = a + } + +} +#endif + #if !WIRE_REMOVE_EQUATABLE extension RedactedOneOf.A : Equatable { } diff --git a/wire-tests-swift/src/main/swift/Thing.swift b/wire-tests-swift/src/main/swift/Thing.swift index d4ecaf7f76..f9e7ef5dc6 100644 --- a/wire-tests-swift/src/main/swift/Thing.swift +++ b/wire-tests-swift/src/main/swift/Thing.swift @@ -8,11 +8,23 @@ public struct Thing { public var name: String? public var unknownFields: Foundation.Data = .init() - public init(name: String? = nil) { + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension Thing { + + @_disfavoredOverload + @available(*, deprecated) + public init(name: Swift.String? = nil) { self.name = name } } +#endif #if !WIRE_REMOVE_EQUATABLE extension Thing : Equatable { diff --git a/wire-tests-swift/src/main/swift/VersionOne.swift b/wire-tests-swift/src/main/swift/VersionOne.swift index 08f06a29e3..a48ad994aa 100644 --- a/wire-tests-swift/src/main/swift/VersionOne.swift +++ b/wire-tests-swift/src/main/swift/VersionOne.swift @@ -10,8 +10,19 @@ public struct VersionOne { public var en: EnumVersionOne? public var unknownFields: Foundation.Data = .init() + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension VersionOne { + + @_disfavoredOverload + @available(*, deprecated) public init( - i: Int32? = nil, + i: Swift.Int32? = nil, obj: NestedVersionOne? = nil, en: EnumVersionOne? = nil ) { @@ -21,6 +32,7 @@ public struct VersionOne { } } +#endif #if !WIRE_REMOVE_EQUATABLE extension VersionOne : Equatable { diff --git a/wire-tests-swift/src/main/swift/VersionTwo.swift b/wire-tests-swift/src/main/swift/VersionTwo.swift index 0409f46976..8f41008929 100644 --- a/wire-tests-swift/src/main/swift/VersionTwo.swift +++ b/wire-tests-swift/src/main/swift/VersionTwo.swift @@ -10,18 +10,29 @@ public struct VersionTwo { public var v2_s: String? public var v2_f32: UInt32? public var v2_f64: UInt64? - public var v2_rs: [String] + public var v2_rs: [String] = [] public var obj: NestedVersionTwo? public var en: EnumVersionTwo? public var unknownFields: Foundation.Data = .init() + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension VersionTwo { + + @_disfavoredOverload + @available(*, deprecated) public init( - i: Int32? = nil, - v2_i: Int32? = nil, - v2_s: String? = nil, - v2_f32: UInt32? = nil, - v2_f64: UInt64? = nil, - v2_rs: [String] = [], + i: Swift.Int32? = nil, + v2_i: Swift.Int32? = nil, + v2_s: Swift.String? = nil, + v2_f32: Swift.UInt32? = nil, + v2_f64: Swift.UInt64? = nil, + v2_rs: [Swift.String] = [], obj: NestedVersionTwo? = nil, en: EnumVersionTwo? = nil ) { @@ -36,6 +47,7 @@ public struct VersionTwo { } } +#endif #if !WIRE_REMOVE_EQUATABLE extension VersionTwo : Equatable { diff --git a/wire-tests-swift/src/main/swift/VeryLongProtoNameCausingBrokenLineBreaks.swift b/wire-tests-swift/src/main/swift/VeryLongProtoNameCausingBrokenLineBreaks.swift index 27bde1ce7d..12a915c266 100644 --- a/wire-tests-swift/src/main/swift/VeryLongProtoNameCausingBrokenLineBreaks.swift +++ b/wire-tests-swift/src/main/swift/VeryLongProtoNameCausingBrokenLineBreaks.swift @@ -11,11 +11,23 @@ public struct VeryLongProtoNameCausingBrokenLineBreaks { public var foo: String? public var unknownFields: Foundation.Data = .init() - public init(foo: String? = nil) { + public init(configure: (inout Self) -> Void = { _ in }) { + configure(&self) + } + +} + +#if WIRE_INCLUDE_MEMBERWISE_INITIALIZER +extension VeryLongProtoNameCausingBrokenLineBreaks { + + @_disfavoredOverload + @available(*, deprecated) + public init(foo: Swift.String? = nil) { self.foo = foo } } +#endif #if !WIRE_REMOVE_EQUATABLE extension VeryLongProtoNameCausingBrokenLineBreaks : Equatable { diff --git a/wire-tests-swift/src/test/swift/JsonLitmusTest.swift b/wire-tests-swift/src/test/swift/JsonLitmusTest.swift index febdd089eb..e284b48137 100644 --- a/wire-tests-swift/src/test/swift/JsonLitmusTest.swift +++ b/wire-tests-swift/src/test/swift/JsonLitmusTest.swift @@ -22,11 +22,14 @@ final class JsonLitmusTest : XCTestCase { func testSimpleRoundtrip() { let expectedPerson = Person( id: 42, - name: "Luke Skywalker", - email: "luke@skywalker.net", - phone: [.init(number: "800-555-1234", type: .WORK)], - aliases: ["Nerfherder"] - ) + name: "Luke Skywalker" + ) { + $0.email = "luke@skywalker.net" + $0.phone = [ + Person.PhoneNumber(number: "800-555-1234") { $0.type = .WORK }, + ] + $0.aliases = ["Nerfherder"] + } let expectedJson = """ {\ "email":"luke@skywalker.net",\