PackStream is a binary message format very similar to MessagePack. It can be used stand-alone, but it has been built as a message format for use in the Bolt protocol to communicate between the Neo4j server and its clients.
This implementation is written in Swift, primarily as a dependency for the Swift Bolt implementation. That implementation will in turn provide Theo, the Neo4j Swift driver, with Bolt support.
- macOS 14+ / iOS 17+ / tvOS 17+ / watchOS 10+ / Linux
- Swift 6.0+
Through PackStream you can encode Bool, Int, Float (Double in Swift lingo), String, List, Map and Structure. They all implement the PackProtocol, so if you want to have a collection of packable items, you can specify them as implementing PackProtocol.
First, remember to
import PackStreamThen you can use it, like for instance so:
let map = Map(dictionary: [
"alpha": 42,
"beta": 39.3,
"gamma": "☺",
"delta": List(items: [1,2,3,4])
])
let result = try map.pack()
let restored = try Map.unpack(result)A list of the numbers 1 to 40
let items = Array(Int8(1)...Int8(40))
let value = List(items: items)gets encoded to the following bytes
D4:28:01:02:03:04:05:06:07:08:09:0A:0B:0C:0D:0E:0F:10:11:12:13:14:15:16:17:18:19:1A:1B:1C:1D:1E:1F:20:22:23:24:25:26:27:28
Add the following to your dependencies array in Package.swift:
.package(url: "https://github.com/Neo4j-Swift/PackStream-Swift.git", from: "6.0.0"),and you can now do a
swift build