1- # BSONSerialization
1+ = BSONSerialization
22BSON Serialization in native Swift
33
4- ## Installation & Compatibility
4+ == Installation & Compatibility
55The recommended (and only tested) way to install and use BSONSerialization is
6- via ` SwiftPM ` , using at least Swift 4 .
6+ via `SwiftPM`, using at least Swift 5.1 .
77
88The content of your `Package.swift` should be something resembling:
9- ``` swift
9+ [source,swift]
10+ ----
1011import PackageDescription
1112
1213let package = Package(
1314 name: "MyAwesomePackage",
1415 dependencies: [.package(url: "https://github.com/Frizlab/BSONSerialization.git", from: "2.0.0")]
1516)
16- ```
17+ ----
1718
18- ## Usage
19+ == Usage
1920`BSONSerialization` has the same basic interface than `JSONSerialization`.
2021
2122Example of use:
22- ``` swift
23+ [source,swift]
24+ ----
2325let myFirstBSONDoc = ["key": "value"]
2426let serializedBSONDoc = try BSONSerialization.data(withBSONObject: myFirstBSONDoc, options: [])
2527let unserializedBSONDoc = try BSONSerialization.bsonObject(with: serializedBSONDoc, options: [])
2628try areBSONDocEqual(myFirstBSONDoc, unserializedBSONDoc) /* Returns true */
27- ```
29+ ----
2830
2931Serializing/deserializing to/from a stream is also supported. (Note: Due to the
3032specifications of the BSON format, serializing to a Data object is faster than
@@ -33,7 +35,7 @@ serializing to a stream.)
3335Finally, a method lets you know if a given dictionary can be serialized as a
3436BSON document.
3537
36- ## Alternatives
38+ == Alternatives
3739First, a word about the philosophy of this project. Most BSON frameworks create
3840a whole new type to represent the BSON document. This is useful to add new
3941elements to the documents and have the document serialization ready at all times.
@@ -47,21 +49,21 @@ If you prefer having an actual BSON object to which you can add elements
4749instead of standard Foundation object which are serialized later, I would
4850recommend this project: https://github.com/OpenKitten/BSON
4951
50- ## Reference
52+ == Reference
5153I used the BSON specification version 1.1 from http://bsonspec.org/spec.html
5254
5355All types in this specification, including deprecated ones are supported.
5456
55- ## To Do
56- - [ ] Allow direct serialization of ` Data ` object instead of having to use the
57+ == To Do
58+ * [ ] Allow direct serialization of `Data` object instead of having to use the
5759`MongoBinary` type
58- - [ ] Allow serializing Int64 or Int32 to Int directly, depending on the platform
59- - [ ] Xcode target for an iOS Framework
60+ * [ ] Allow serializing Int64 or Int32 to Int directly, depending on the platform
61+ * [ ] Xcode target for an iOS Framework
6062
6163I’ll work seriously on the project if it gains enough attention. Feel free to
6264open issues, I’ll do my best to answer.
6365
6466Pull requests are welcome 😉
6567
66- ## License
68+ == License
6769MIT (see License.txt file)
0 commit comments