Skip to content

Commit 72ee41c

Browse files
authored
SWIFT-411 Make pointer access to bson_ts more explicit (#264)
1 parent 506db1b commit 72ee41c

20 files changed

+191
-206
lines changed

Sources/MongoSwift/BSON/BSONValue.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ extension Array: BSONValue {
219219
try arr.setValue(for: String(i), to: val)
220220
}
221221

222-
guard bson_append_array(storage.pointer, key, Int32(key.utf8.count), arr.data) else {
222+
guard bson_append_array(storage._bson, key, Int32(key.utf8.count), arr._bson) else {
223223
throw bsonTooLargeError(value: self, forKey: key)
224224
}
225225
}
@@ -255,7 +255,7 @@ public struct BSONNull: BSONValue, Codable, Equatable {
255255
}
256256

257257
public func encode(to storage: DocumentStorage, forKey key: String) throws {
258-
guard bson_append_null(storage.pointer, key, Int32(key.utf8.count)) else {
258+
guard bson_append_null(storage._bson, key, Int32(key.utf8.count)) else {
259259
throw bsonTooLargeError(value: self, forKey: key)
260260
}
261261
}
@@ -356,7 +356,7 @@ public struct Binary: BSONValue, Equatable, Codable {
356356
let subtype = bson_subtype_t(UInt32(self.subtype))
357357
let length = self.data.count
358358
let byteArray = [UInt8](self.data)
359-
guard bson_append_binary(storage.pointer, key, Int32(key.utf8.count), subtype, byteArray, UInt32(length)) else {
359+
guard bson_append_binary(storage._bson, key, Int32(key.utf8.count), subtype, byteArray, UInt32(length)) else {
360360
throw bsonTooLargeError(value: self, forKey: key)
361361
}
362362
}
@@ -392,7 +392,7 @@ extension Bool: BSONValue {
392392
public var bsonType: BSONType { return .boolean }
393393

394394
public func encode(to storage: DocumentStorage, forKey key: String) throws {
395-
guard bson_append_bool(storage.pointer, key, Int32(key.utf8.count), self) else {
395+
guard bson_append_bool(storage._bson, key, Int32(key.utf8.count), self) else {
396396
throw bsonTooLargeError(value: self, forKey: key)
397397
}
398398
}
@@ -422,7 +422,7 @@ extension Date: BSONValue {
422422
public var msSinceEpoch: Int64 { return Int64((self.timeIntervalSince1970 * 1000.0).rounded()) }
423423

424424
public func encode(to storage: DocumentStorage, forKey key: String) throws {
425-
guard bson_append_date_time(storage.pointer, key, Int32(key.utf8.count), self.msSinceEpoch) else {
425+
guard bson_append_date_time(storage._bson, key, Int32(key.utf8.count), self.msSinceEpoch) else {
426426
throw bsonTooLargeError(value: self, forKey: key)
427427
}
428428
}
@@ -464,7 +464,7 @@ public struct DBPointer: BSONValue, Codable, Equatable {
464464

465465
public func encode(to storage: DocumentStorage, forKey key: String) throws {
466466
try withUnsafePointer(to: id.oid) { oidPtr in
467-
guard bson_append_dbpointer(storage.pointer, key, Int32(key.utf8.count), self.ref, oidPtr) else {
467+
guard bson_append_dbpointer(storage._bson, key, Int32(key.utf8.count), self.ref, oidPtr) else {
468468
throw bsonTooLargeError(value: self, forKey: key)
469469
}
470470
}
@@ -538,7 +538,7 @@ public struct Decimal128: BSONNumber, Equatable, Codable, CustomStringConvertibl
538538

539539
public func encode(to storage: DocumentStorage, forKey key: String) throws {
540540
try withUnsafePointer(to: self.decimal128) { ptr in
541-
guard bson_append_decimal128(storage.pointer, key, Int32(key.utf8.count), ptr) else {
541+
guard bson_append_decimal128(storage._bson, key, Int32(key.utf8.count), ptr) else {
542542
throw bsonTooLargeError(value: self, forKey: key)
543543
}
544544
}
@@ -601,7 +601,7 @@ extension Double: BSONNumber {
601601
public var bsonType: BSONType { return .double }
602602

603603
public func encode(to storage: DocumentStorage, forKey key: String) throws {
604-
guard bson_append_double(storage.pointer, key, Int32(key.utf8.count), self) else {
604+
guard bson_append_double(storage._bson, key, Int32(key.utf8.count), self) else {
605605
throw bsonTooLargeError(value: self, forKey: key)
606606
}
607607
}
@@ -681,7 +681,7 @@ extension Int32: BSONNumber {
681681
public var bsonType: BSONType { return .int32 }
682682

683683
public func encode(to storage: DocumentStorage, forKey key: String) throws {
684-
guard bson_append_int32(storage.pointer, key, Int32(key.utf8.count), self) else {
684+
guard bson_append_int32(storage._bson, key, Int32(key.utf8.count), self) else {
685685
throw bsonTooLargeError(value: self, forKey: key)
686686
}
687687
}
@@ -711,7 +711,7 @@ extension Int64: BSONNumber {
711711
public var bsonType: BSONType { return .int64 }
712712

713713
public func encode(to storage: DocumentStorage, forKey key: String) throws {
714-
guard bson_append_int64(storage.pointer, key, Int32(key.utf8.count), self) else {
714+
guard bson_append_int64(storage._bson, key, Int32(key.utf8.count), self) else {
715715
throw bsonTooLargeError(value: self, forKey: key)
716716
}
717717
}
@@ -764,11 +764,11 @@ public struct CodeWithScope: BSONValue, Equatable, Codable {
764764

765765
public func encode(to storage: DocumentStorage, forKey key: String) throws {
766766
if let s = self.scope {
767-
guard bson_append_code_with_scope(storage.pointer, key, Int32(key.utf8.count), self.code, s.data) else {
767+
guard bson_append_code_with_scope(storage._bson, key, Int32(key.utf8.count), self.code, s._bson) else {
768768
throw bsonTooLargeError(value: self, forKey: key)
769769
}
770770
} else {
771-
guard bson_append_code(storage.pointer, key, Int32(key.utf8.count), self.code) else {
771+
guard bson_append_code(storage._bson, key, Int32(key.utf8.count), self.code) else {
772772
throw bsonTooLargeError(value: self, forKey: key)
773773
}
774774
}
@@ -811,7 +811,7 @@ public struct MaxKey: BSONValue, Equatable, Codable {
811811
public var bsonType: BSONType { return .maxKey }
812812

813813
public func encode(to storage: DocumentStorage, forKey key: String) throws {
814-
guard bson_append_maxkey(storage.pointer, key, Int32(key.utf8.count)) else {
814+
guard bson_append_maxkey(storage._bson, key, Int32(key.utf8.count)) else {
815815
throw bsonTooLargeError(value: self, forKey: key)
816816
}
817817
}
@@ -842,7 +842,7 @@ public struct MinKey: BSONValue, Equatable, Codable {
842842
public var bsonType: BSONType { return .minKey }
843843

844844
public func encode(to storage: DocumentStorage, forKey key: String) throws {
845-
guard bson_append_minkey(storage.pointer, key, Int32(key.utf8.count)) else {
845+
guard bson_append_minkey(storage._bson, key, Int32(key.utf8.count)) else {
846846
throw bsonTooLargeError(value: self, forKey: key)
847847
}
848848
}
@@ -925,7 +925,7 @@ public struct ObjectId: BSONValue, Equatable, CustomStringConvertible, Codable {
925925
public func encode(to storage: DocumentStorage, forKey key: String) throws {
926926
// encode the bson_oid_t to the bson_t
927927
try withUnsafePointer(to: self.oid) { oidPtr in
928-
guard bson_append_oid(storage.pointer, key, Int32(key.utf8.count), oidPtr) else {
928+
guard bson_append_oid(storage._bson, key, Int32(key.utf8.count), oidPtr) else {
929929
throw bsonTooLargeError(value: self, forKey: key)
930930
}
931931
}
@@ -1044,7 +1044,7 @@ public struct RegularExpression: BSONValue, Equatable, Codable {
10441044
}
10451045

10461046
public func encode(to storage: DocumentStorage, forKey key: String) throws {
1047-
guard bson_append_regex(storage.pointer, key, Int32(key.utf8.count), self.pattern, self.options) else {
1047+
guard bson_append_regex(storage._bson, key, Int32(key.utf8.count), self.pattern, self.options) else {
10481048
throw bsonTooLargeError(value: self, forKey: key)
10491049
}
10501050
}
@@ -1077,7 +1077,7 @@ extension String: BSONValue {
10771077
public var bsonType: BSONType { return .string }
10781078

10791079
public func encode(to storage: DocumentStorage, forKey key: String) throws {
1080-
guard bson_append_utf8(storage.pointer, key, Int32(key.utf8.count), self, Int32(self.utf8.count)) else {
1080+
guard bson_append_utf8(storage._bson, key, Int32(key.utf8.count), self, Int32(self.utf8.count)) else {
10811081
throw bsonTooLargeError(value: self, forKey: key)
10821082
}
10831083
}
@@ -1135,7 +1135,7 @@ public struct Symbol: BSONValue, CustomStringConvertible, Codable, Equatable {
11351135

11361136
public func encode(to storage: DocumentStorage, forKey key: String) throws {
11371137
guard bson_append_symbol(
1138-
storage.pointer,
1138+
storage._bson,
11391139
key,
11401140
Int32(key.utf8.count),
11411141
self.stringValue,
@@ -1191,7 +1191,7 @@ public struct Timestamp: BSONValue, Equatable, Codable {
11911191
}
11921192

11931193
public func encode(to storage: DocumentStorage, forKey key: String) throws {
1194-
guard bson_append_timestamp(storage.pointer, key, Int32(key.utf8.count), self.timestamp, self.increment) else {
1194+
guard bson_append_timestamp(storage._bson, key, Int32(key.utf8.count), self.timestamp, self.increment) else {
11951195
throw bsonTooLargeError(value: self, forKey: key)
11961196
}
11971197
}
@@ -1227,7 +1227,7 @@ public struct BSONUndefined: BSONValue, Equatable, Codable {
12271227
}
12281228

12291229
public func encode(to storage: DocumentStorage, forKey key: String) throws {
1230-
guard bson_append_undefined(storage.pointer, key, Int32(key.utf8.count)) else {
1230+
guard bson_append_undefined(storage._bson, key, Int32(key.utf8.count)) else {
12311231
throw bsonTooLargeError(value: self, forKey: key)
12321232
}
12331233
}

0 commit comments

Comments
 (0)