Skip to content

Commit 9fb49e3

Browse files
authored
SWIFT-971 Rename BSONEncoder.encode which returns a BSON (#34)
1 parent c834c91 commit 9fb49e3

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

Sources/BSON/BSONEncoder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public class BSONEncoder {
139139
* - Throws: `EncodingError` if any value throws an error during encoding.
140140
*/
141141
public func encode<T: Encodable>(_ value: T) throws -> BSONDocument {
142-
let encodedBSON: BSON = try self.encode(value)
142+
let encodedBSON: BSON = try self.encodeFragment(value)
143143
switch encodedBSON {
144144
case let .document(doc):
145145
return doc
@@ -201,7 +201,7 @@ public class BSONEncoder {
201201
* - Returns: A new `BSON` containing the encoded BSON data.
202202
* - Throws: `EncodingError` if any value throws an error during encoding.
203203
*/
204-
internal func encode<T: Encodable>(_ value: T) throws -> BSON {
204+
internal func encodeFragment<T: Encodable>(_ value: T) throws -> BSON {
205205
let encoder = _BSONEncoder(options: self.options)
206206

207207
do {

Sources/BSON/ExtendedJSONEncoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class ExtendedJSONEncoder {
4040
// The `JSON` is then passed through a `JSONEncoder` and outputted as `Data`.
4141
let encoder = BSONEncoder()
4242
encoder.userInfo = self.userInfo
43-
let bson: BSON = try encoder.encode(value)
43+
let bson: BSON = try encoder.encodeFragment(value)
4444

4545
let json: JSON
4646
switch self.mode {

Tests/BSONTests/BSONCorpusTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ final class BSONCorpusTests: BSONTestCase {
108108
"OK2",
109109
// TODO: SWIFT-965
110110
"[decq438] clamped zeros... (Clamped)",
111-
"[decq418] clamped zeros... (Clamped)"
111+
"[decq418] clamped zeros... (Clamped)",
112+
// TODO: SWIFT-972
113+
"Special - Negative NaN"
112114
],
113115
"Array":
114116
[

Tests/BSONTests/CodecTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ final class CodecTests: BSONTestCase {
5353
expect(try decoder.decode(Array.self, fromBSON: [BSON.int32(1), BSON.int32(2)]))
5454
.to(equal([1, 2]))
5555

56-
expect(try encoder.encode(oid)).to(equal(BSON.objectID(oid)))
57-
expect(try encoder.encode([Int32(1), Int32(2)])).to(equal([BSON.int32(1), BSON.int32(2)]))
56+
expect(try encoder.encodeFragment(oid)).to(equal(BSON.objectID(oid)))
57+
expect(try encoder.encodeFragment([Int32(1), Int32(2)])).to(equal([BSON.int32(1), BSON.int32(2)]))
5858
}
5959

6060
/// Test encoding/decoding a variety of structs containing simple types that have

0 commit comments

Comments
 (0)