Skip to content

Commit 1d67ef1

Browse files
committed
Adds back some array helpers to maintain api compat.
Fixes apple#1025
1 parent 4d5fc24 commit 1d67ef1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Sources/SwiftProtobuf/Message+JSONArrayAdditions.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ extension Message {
6565
/// - Parameter jsonString: The JSON-formatted string to decode.
6666
/// - Parameter options: The JSONDecodingOptions to use.
6767
/// - Throws: `JSONDecodingError` if decoding fails.
68+
public static func array(
69+
fromJSONString jsonString: String,
70+
options: JSONDecodingOptions = JSONDecodingOptions()
71+
) throws -> [Self] {
72+
return try self.array(fromJSONString: jsonString,
73+
extensions: SimpleExtensionMap(),
74+
options: options)
75+
}
76+
77+
/// Creates a new array of messages by decoding the given string containing a
78+
/// serialized array of messages in JSON format.
79+
///
80+
/// - Parameter jsonString: The JSON-formatted string to decode.
81+
/// - Parameter extensions: The extension map to use with this decode
82+
/// - Parameter options: The JSONDecodingOptions to use.
83+
/// - Throws: `JSONDecodingError` if decoding fails.
6884
public static func array(
6985
fromJSONString jsonString: String,
7086
extensions: ExtensionMap = SimpleExtensionMap(),
@@ -88,6 +104,24 @@ extension Message {
88104
/// as UTF-8 encoded text.
89105
/// - Parameter options: The JSONDecodingOptions to use.
90106
/// - Throws: `JSONDecodingError` if decoding fails.
107+
public static func array(
108+
fromJSONUTF8Data jsonUTF8Data: Data,
109+
options: JSONDecodingOptions = JSONDecodingOptions()
110+
) throws -> [Self] {
111+
return try self.array(fromJSONUTF8Data: jsonUTF8Data,
112+
extensions: SimpleExtensionMap(),
113+
options: options)
114+
}
115+
116+
/// Creates a new array of messages by decoding the given `Data` containing a
117+
/// serialized array of messages in JSON format, interpreting the data as
118+
/// UTF-8 encoded text.
119+
///
120+
/// - Parameter jsonUTF8Data: The JSON-formatted data to decode, represented
121+
/// as UTF-8 encoded text.
122+
/// - Parameter extensions: The extension map to use with this decode
123+
/// - Parameter options: The JSONDecodingOptions to use.
124+
/// - Throws: `JSONDecodingError` if decoding fails.
91125
public static func array(
92126
fromJSONUTF8Data jsonUTF8Data: Data,
93127
extensions: ExtensionMap = SimpleExtensionMap(),

0 commit comments

Comments
 (0)