Skip to content

Commit a520d99

Browse files
authored
SWIFT-840: Decimal 128 Support (#6)
1 parent e92f308 commit a520d99

File tree

3 files changed

+536
-7
lines changed

3 files changed

+536
-7
lines changed

Sources/BSON/BSON.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public enum BSON {
1212
/// A BSON int64.
1313
case int64(Int64)
1414

15+
/// A BSON Decimal128
16+
case decimal128(BSONDecimal128)
17+
1518
/// A BSON Array
1619
indirect case array([BSON])
1720

@@ -98,6 +101,14 @@ extension BSON {
98101
return i
99102
}
100103

104+
/// If this `BSON` is an `.decimal128`, return it as an `BSONDecimal128`. Otherwise, return nil.
105+
public var decimal128Value: BSONDecimal128? {
106+
guard case let .decimal128(i) = self else {
107+
return nil
108+
}
109+
return i
110+
}
111+
101112
/// If this `BSON` is a `.document`, return it as a `BSONDocument`. Otherwise, return nil.
102113
public var documentValue: BSONDocument? {
103114
guard case let .document(d) = self else {
@@ -266,6 +277,7 @@ extension BSON {
266277
.document: BSONDocument.self,
267278
.int32: Int32.self,
268279
.int64: Int64.self,
280+
.decimal128: BSONDecimal128.self,
269281
.bool: Bool.self,
270282
.string: String.self,
271283
.double: Double.self,
@@ -294,6 +306,8 @@ extension BSON {
294306
return v
295307
case let .int64(v):
296308
return v
309+
case let .decimal128(v):
310+
return v
297311
case let .array(v):
298312
return v
299313
case let .bool(v):

0 commit comments

Comments
 (0)