Swiftpack.co - Package - OpenKitten/BSON

BSON

Swift 3.1 License Build Status

BSON 5 is the fastest BSON library speeding past all libraries including C. It's compliant to the whole C BSON specification test suite, and even passes official libraries in compliance slightly.

It's not only fast, it's also got an extremely easy and intuitive API for extraction.

BSON is parsed and generated as specified for version 1.1 of the BSON specification.

Usage

The supported method for using this library is trough the Swift Package manager, like this:

import PackageDescription

let package = Package(
    name: "MyApp",
    dependencies: [.Package(url: "https://github.com/OpenKitten/BSON.git", majorVersion: 5)]
)

Create Documents naturally:

var userDocument: Document = [
	"username": "Joannis",
	"online": true,
	"age": 20,
	"pi_constant": 3.14,
	"profile": [
		"firstName": "Joannis",
		"lastName": "Orlandos"
	]
]

let favouriteNumbers: Document = [1, 3, 7, 14, 21, 24, 34]

userDocument["favouriteNumbers"] = favouriteNumbers

Access values in an array like you would in Swift Arrays and values in an object like a Dictionary.

let favouriteNumber = favouriteNumbers[0]
let usernameValue = userDocument["username"]

Extract types with simplicity:

let username = String(userDocument["username"]) // "Joannis"
let isOnline = Bool(userDocument["online"]) // true
let age = Int(userDocument["age"]) // 20
let pi = Double(userDocument["pi_constant"]) // 3.14

Chain subscripts easily to find results without a hassle as shown underneath using this JSON structure (assuming this is represented in BSON):

{
  "users": [
  	{
  		"username": "Joannis",
  		"profile": {
  		  "firstName": "Joannis",
  		  "lastName": "Orlandos"
  		}
  	},
  	{
  		"username": "Obbut",
  		"profile": {
  		  "firstName": "Robbert",
  		  "lastName": "Brandsma"
  		}
  	}
  ]
}
let obbutLastName = String(object["users"][1]["profile"]["lastName"]) // "Brandsma"

Check the documentation for more information.

Performance

The performance in this BSON library is thanks to specialized algorithms per-operation with a centralized cache for indexed information. BSON is 100% lazy, so if you don't read data, it doesn't cost any performance.

Supported Types

All non-deprecated BSON 1.1 types are supported.

  • Double
  • String
  • Document
  • Array
  • ObjectId
  • Bool
  • DateTime
  • 32-bit integer
  • 64-bit integer
  • Null value
  • Binary
  • Regular Expression
  • Min Key
  • Max Key
  • Timestamp
  • Javascript Code
  • Javascript Code with Scope
  • Decimal128

Github

link
Stars: 74

Dependencies

Used By

Total: 0

Releases

6.0.9 - 2019-07-21 10:10:09

  • Fix a bug when representing the big endian timestamp of an ObjectId as Date

6.0.7 - 2019-06-30 11:15:24

  • Fixed a bug in subscripts with large differences in values
  • Fixed a bug in validating Binary

6.0.5 - 2019-04-08 10:11:35

  • Release iOS support

5.2.6 - 2019-04-01 20:09:56

  • Fixed the tag's branch
  • Compilation fixed for Swift 4.2

6.0.4 - 2019-04-01 12:56:36

  • Fixed an issue that caused ObjectId generation to fail when using Swift 5 with open source Foundation
  • Added ObjectIdGenerator.default for accessing a thread-specific ObjectId generator
  • Added a new init to Document that allows initialising a document with an existing NIO ByteBuffer

6.0.3 - 2019-03-14 16:38:31

  • Support cocoapods on macOS
  • Make Document hashable

6.0.2 - 2019-02-23 10:45:26

  • Fixed a cocoapods dependency constraint

6.0.1 - 2019-02-22 18:05:28

  • Fixed a deprecation warning

6.0.0 - 2019-01-27 10:14:49

Another major release with some optimizations, SwiftNIO support and the same API you love.

- 2018-10-25 12:18:21

5.2.4 - 2018-07-03 10:21:47

  • Fixed UInt decoding

5.2.3 - 2017-10-18 18:59:41

  • Improved caching the count

- 2017-10-17 11:15:24

  • Fixed performance issues for count operations

BSON ended up re-indexing documents when the count was being read

  • Fixed BSONEncoder refusing the max and min value for an integer

- 2017-10-04 11:43:37

  • Fixed a very obscure bug that would sometimes cause misinterpreting "primitive" BSON values (like Double, Int) when the backing storage of the array containing the bytes of the Document is not contiguous
  • Added a range check in the Int initializer, to prevent crashes when converting a Double whose value falls outside the Int.min-Int.max range

5.2.0 - 2017-09-24 13:26:57

Swift 4 codable support. Swift 3.0 and 3.1 are still supported, too, but without Codable.

5.1.5 - 2017-09-11 10:52:10

  • Fixed the internal cache not updating properly on append

5.1.4 - 2017-06-20 15:09:46

  • Fixed index mutations affecting other documents

4.1.5 - 2017-06-20 15:06:25

Fixed a very specific ExtendedJSON serialization bug

5.1.3 - 2017-06-16 15:51:00

  • Better subdocument equation

5.1.2 - 2017-06-16 10:54:59

Fixed creation of documents from an arrayslice with an offset of startIndex > 0

5.1.1 - 2017-06-14 05:26:18

  • Fixed DictionaryValue, it's been broken for months apparently.
  • Fixed overall correctness in validation (too permissive)
  • Fixed array validation (not permissive enough, arrays with the key "username" make sense apparently)
  • Complete unit test suite for BSON's Spec

5.1.0 - 2017-06-12 18:50:07

Reworked the entire parser for stability and a tonne of performance.

5.0.5 - 2017-05-18 11:31:18

When you've got a Dictionary<String, Primitive> or [String : Primitive] you can now convert them to a Document using Document(dictionary). The same goes for [Primitive] / Array<Primitive>

5.0.4 - 2017-05-18 11:30:01

Fixed a crash when replacing an element with a smaller element and verifying the data

5.0.0 - 2017-05-01 09:12:40

  • Rewrote the public extraction and input APIs.

5.0.1 - 2017-05-01 09:12:12

Foundation.Data support

5.0.2 - 2017-05-01 09:11:35

Fixed a bug when overwriting a value which contains Null and a serialization error on other setters to nil

5.0.3 - 2017-05-01 09:10:47

Fixed a kittencore conversion bug

4.1.4 - 2017-03-29 18:49:35

  • Swift 3.1 support

4.1.3 - 2017-02-08 17:13:08

  • Fixed a null terminator bug causing two equal documents to be unequal