{"id":16776393,"url":"https://github.com/crichez/swift-bison","last_synced_at":"2025-11-02T07:30:34.867Z","repository":{"id":37787785,"uuid":"474174798","full_name":"crichez/swift-bison","owner":"crichez","description":"BSON (Binary JSON) reading and writing in Swift","archived":true,"fork":false,"pushed_at":"2022-08-02T13:51:11.000Z","size":430,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-23T05:14:16.701Z","etag":null,"topics":["bson","ios","ipados","linux","macos","mongodb","serialization","swift","tvos","watchos","windows"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crichez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null}},"created_at":"2022-03-25T21:58:04.000Z","updated_at":"2024-04-20T18:00:12.000Z","dependencies_parsed_at":"2022-06-23T21:44:47.138Z","dependency_job_id":null,"html_url":"https://github.com/crichez/swift-bison","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crichez%2Fswift-bison","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crichez%2Fswift-bison/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crichez%2Fswift-bison/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crichez%2Fswift-bison/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crichez","download_url":"https://codeload.github.com/crichez/swift-bison/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239389573,"owners_count":19630308,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bson","ios","ipados","linux","macos","mongodb","serialization","swift","tvos","watchos","windows"],"created_at":"2024-10-13T07:09:48.711Z","updated_at":"2025-02-18T00:31:45.099Z","avatar_url":"https://github.com/crichez.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🦬 Bison\n\nBSON (binary JSON) encoding and decoding in Swift.\n\n## Overview\n\nThe swift-bison package features **two flavors** of BSON document management:\n* `BisonRead` \u0026 `BisonWrite`: custom APIs designed for flexibility and performance.\n* `BisonEncode` \u0026 `BisonDecode`: Swift `Codable` adapters to start working with BSON today.\n\nThis project is tested in continuous integration on the following platforms:\n* macOS 11\n* iOS 15\n* tvOS 15\n* watchOS 8\n* ubuntu 20.04\n* Windows Server 2022\n\n## Version\n\nYou can import this package by adding the following line to your `Package.swift` dependencies:\n```swift\n.package(url: \"https://github.com/crichez/swift-bison\", .upToNextMinor(\"0.0.1\"))\n```\n\n*Note:* versions before 1.0.0 are considered pre-release, and sources-breaking changes may be \nintroduced with a minor version bump. Once the project graduates to 1.0.0, regular semantic\nversioning rules will apply.\n\n## Documentation\n\n**This package is documented using [swift-docc](https://github.com/apple/swift-docc)**. You can \nbuild the documentation for a specific module by following instructions at that repository,\nor read inline documentation for each source file. The following sections give a brief \nintroduction to the most common APIs of each module.\n\n### BisonWrite\n\nImport the `BisonWrite` module to compose and encode complex documents using a custom result \nbuilder. The following example declares a simple BSON document with conditionals and nesting,\nthen encodes it to an Array of bytes.\n\n```swift\nimport BisonWrite\n\nlet ownerDoc = WritableDoc {\n    \"name\" =\u003e \"Bob Belcher\"\n    if season8 {\n        \"age\" =\u003e Int64(46)\n    } else {\n        \"age\" =\u003e Int64(45)\n    }\n    \"children\" =\u003e WritableArray {\n        \"Tina\"\n        \"Louise\"\n        \"Gene\"\n    }\n}\n.encode(as: [UInt8].self)\n```\n\n### BisonRead\n\nImport the `BisonRead` module to parse and decode documents from raw bytes. The following example\nparses a document, then extracts select values.\n\n```swift\nimport BisonRead\n\ndo {\n    // Parse and validate the document.\n    let doc = try ReadableDoc(bsonBytes: ownerDoc)\n    // Get the \"name\" value and initialize it as a String.\n    guard let nameData = doc[\"name\"] else { return }\n    let name = try String(bsonBytes: nameData)\n    // Get the \"children\" nested document and initialize each value.\n    guard let childrenData = doc[\"children\"] else { return }\n    let childrenDoc = try ReadableDoc(bsonBytes: childrenData)\n    for childNameData in childrenDoc.values {\n        let childName = try String(bsonBytes: childNameData)\n    }\n} catch DocError\u003c[UInt8]\u003e.unknownType(let type, let key, let progress) {\n    // Handle document parsing errors.\n} catch ValueError.sizeMismatch {\n    // Handle value parsing errors.\n}\n```\n\n### BisonEncode \u0026 BisonDecode\n\nImport the `BisonEncode` \u0026 `BisonDecode` modules to use the `BSONEncoder` and `BSONDecoder` types.\nThese expose a similar API to Foundation's JSON encoder and decoder, while still featuring support\nfor custom BSON types through `BisonWrite` \u0026 `BisonRead` APIs.\n\n```swift\nimport BisonEncode\nimport BisonDecode\nimport Foundation\n\nstruct Owner: Codable {\n    let name: String\n    let age: Int64\n    let children: [String]\n}\n\ndo {\n    let owner = Owner(name: \"Bob Belcher\", age: 46, children: [\"Tina\", \"Louise\", \"Gene\"])\n    let encodedOwnerDoc = try BSONEncoder\u003cData\u003e().encode(owner)\n    let decodedOwner = try BSONDecoder().decode(Owner.self, from: encodedOwnerDoc)\n} catch DecodingError.typeMismatch(let requested, let context) {\n    // Handle traditional Swift EncodingErrors and DecodingErrors\n}\n```\n\n### ObjectID\n\nThe `ObjectID` module includes a full-featured BSON ObjectID implementation.\n\n```swift\nimport ObjectID\n\n// Initialize IDs randomly or from hexadecimal data.\nvar randomID = ObjectID()\n// Use the timestamp property for chronological tracking.\nlet created: Date = randomID.timestamp\n// Use the increment property for version tracking.\nlet version: Int = randomID.increment\n// Easily output hexadecimal strings using custom LosslessStringConvertible conformance\nlet hexID = String(describing: randomID)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrichez%2Fswift-bison","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrichez%2Fswift-bison","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrichez%2Fswift-bison/lists"}