Skip to content

Commit 71da5d5

Browse files
committed
Test "option (apple_swift_prefix)", fix it.
There's a bug that extension fields were not correctly handled in nested submessages (the extension set data was not always passed down to generated subdecoders).
1 parent cc4a4ca commit 71da5d5

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

Protos/google/protobuf/map_unittest_proto3.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ option cc_enable_arenas = true;
4040
option csharp_namespace = "Google.Protobuf.TestProtos";
4141

4242
// Disambiguate from map_unittest.proto messages
43-
option swift_prefix = "Proto3";
43+
import "swift-options.proto";
44+
option (apple_swift_prefix) = "Proto3";
4445

4546
import "google/protobuf/unittest_proto3.proto";
4647

Protos/swift-options.proto

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
syntax="proto2";
3+
4+
import "google/protobuf/descriptor.proto";
5+
6+
extend google.protobuf.FileOptions {
7+
optional string apple_swift_prefix = 50138;
8+
}
9+

Sources/Protobuf/ProtobufBinaryDecoding.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,21 @@ private struct ProtobufFieldWireType2: ProtobufBinaryFieldDecoder {
134134

135135
mutating func decodeOptionalMessageField<M: ProtobufMessage>(fieldType: M.Type, value: inout M?) throws -> Bool {
136136
var v = value ?? M()
137-
var subDecoder = ProtobufBinaryDecoder(protobufPointer: buffer)
137+
var subDecoder = ProtobufBinaryDecoder(protobufPointer: buffer, extensions: scanner.extensions)
138138
try subDecoder.decodeFullObject(message: &v)
139139
value = v
140140
return true
141141
}
142142

143143
mutating func decodeRepeatedMessageField<M: ProtobufMessage>(fieldType: M.Type, value: inout [M]) throws -> Bool {
144-
value.append(try M(protobufBuffer: buffer))
144+
value.append(try M(protobufBuffer: buffer, extensions: scanner.extensions))
145145
return true
146146
}
147147

148148
mutating func decodeMapField<KeyType: ProtobufTypeProperties, ValueType: ProtobufMapValueType>(fieldType: ProtobufMap<KeyType, ValueType>.Type, value: inout ProtobufMap<KeyType, ValueType>.BaseType) throws -> Bool where KeyType: ProtobufMapKeyType, KeyType.BaseType: Hashable {
149149
var k: KeyType.BaseType?
150150
var v: ValueType.BaseType?
151-
var subdecoder = ProtobufBinaryDecoder(protobufPointer: buffer)
151+
var subdecoder = ProtobufBinaryDecoder(protobufPointer: buffer, extensions: scanner.extensions)
152152
try subdecoder.decodeFullObject {(decoder: inout ProtobufFieldDecoder, protoFieldNumber: Int) throws -> Bool in
153153
switch protoFieldNumber {
154154
case 1:
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* DO NOT EDIT.
3+
*
4+
* Generated by the protocol buffer compiler.
5+
* Source: swift-options.proto
6+
*
7+
*/
8+
9+
import Foundation
10+
import Protobuf
11+
12+
13+
let Google_Protobuf_FileOptions_appleSwiftPrefix = ProtobufGenericMessageExtension<ProtobufOptionalField<ProtobufString>, Google_Protobuf_FileOptions>(protoFieldNumber: 50138, protoFieldName: "apple_swift_prefix", jsonFieldName: "appleSwiftPrefix", swiftFieldName: "appleSwiftPrefix", defaultValue: nil)
14+
15+
extension Google_Protobuf_FileOptions {
16+
var appleSwiftPrefix: String? {
17+
get {return getExtensionValue(ext: Google_Protobuf_FileOptions_appleSwiftPrefix)}
18+
set {setExtensionValue(ext: Google_Protobuf_FileOptions_appleSwiftPrefix, value: newValue)}
19+
}
20+
}
21+
22+
let SwiftOptions_Extensions: ProtobufExtensionSet = [
23+
Google_Protobuf_FileOptions_appleSwiftPrefix
24+
]

0 commit comments

Comments
 (0)