Skip to content

Commit f157da7

Browse files
authored
Merge pull request apple#340 from thomasvl/expose_unknown_data
Expose UnknownStorage.data as a r/o Data.
2 parents b951f96 + d04b6a9 commit f157da7

File tree

2 files changed

+2
-51
lines changed

2 files changed

+2
-51
lines changed

Sources/SwiftProtobuf/UnknownStorage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import Foundation
1818

1919
public struct UnknownStorage: Equatable {
20-
internal var data = Data()
20+
public private(set) var data = Data()
2121

2222
public static func ==(lhs: UnknownStorage, rhs: UnknownStorage) -> Bool {
2323
return lhs.data == rhs.data

Tests/SwiftProtobufTests/Test_Unknown_proto2.swift

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,7 @@ class Test_Unknown_proto2: XCTestCase, PBTestHelpers {
128128

129129

130130
func assertUnknownFields(_ message: Proto2Message, _ bytes: [UInt8], line: UInt = #line) {
131-
var collector = UnknownCollector()
132-
do {
133-
try message.unknownFields.traverse(visitor: &collector)
134-
} catch let e {
135-
XCTFail("Throw why walking unknowns: \(e)", line: line)
136-
}
137-
XCTAssertEqual(collector.collected, [Data(bytes: bytes)], line: line)
131+
XCTAssertEqual(message.unknownFields.data, Data(bytes: bytes), line: line)
138132
}
139133

140134
func test_MessageNoStorageClass() throws {
@@ -181,46 +175,3 @@ class Test_Unknown_proto2: XCTestCase, PBTestHelpers {
181175
assertUnknownFields(msg1, [24, 1, 61, 7, 0, 0, 0])
182176
}
183177
}
184-
185-
// Helper visitor class that ignores everything, but collects the
186-
// things passed to visitUnknown.
187-
struct UnknownCollector: Visitor {
188-
var collected: [Data] = []
189-
190-
mutating func visitUnknown(bytes: Data) {
191-
collected.append(bytes)
192-
}
193-
194-
mutating func visitSingularDoubleField(value: Double, fieldNumber: Int) throws {}
195-
196-
mutating func visitSingularInt64Field(value: Int64, fieldNumber: Int) throws {}
197-
198-
mutating func visitSingularUInt64Field(value: UInt64, fieldNumber: Int) throws {}
199-
200-
mutating func visitSingularBoolField(value: Bool, fieldNumber: Int) throws {}
201-
202-
mutating func visitSingularStringField(value: String, fieldNumber: Int) throws {}
203-
204-
mutating func visitSingularBytesField(value: Data, fieldNumber: Int) throws {}
205-
206-
mutating func visitSingularEnumField<E: Enum>(value: E, fieldNumber: Int) throws {}
207-
208-
mutating func visitSingularMessageField<M: Message>(value: M, fieldNumber: Int) throws {}
209-
210-
mutating func visitMapField<KeyType: MapKeyType, ValueType: MapValueType>(
211-
fieldType: _ProtobufMap<KeyType, ValueType>.Type,
212-
value: _ProtobufMap<KeyType, ValueType>.BaseType,
213-
fieldNumber: Int) throws where KeyType.BaseType: Hashable {}
214-
215-
mutating func visitMapField<KeyType: MapKeyType, ValueType: Enum>(
216-
fieldType: _ProtobufEnumMap<KeyType, ValueType>.Type,
217-
value: _ProtobufEnumMap<KeyType, ValueType>.BaseType,
218-
fieldNumber: Int) throws where KeyType.BaseType: Hashable, ValueType.RawValue == Int {}
219-
220-
mutating func visitMapField<KeyType: MapKeyType, ValueType: Message>(
221-
fieldType: _ProtobufMessageMap<KeyType, ValueType>.Type,
222-
value: _ProtobufMessageMap<KeyType, ValueType>.BaseType,
223-
fieldNumber: Int) throws where KeyType.BaseType: Hashable {}
224-
225-
mutating func visitExtensionFields(fields: ExtensionFieldValueSet, start: Int, end: Int) throws {}
226-
}

0 commit comments

Comments
 (0)