Skip to content

Commit

Permalink
Update README, start Podspec, Support 32-bit devices
Browse files Browse the repository at this point in the history
  • Loading branch information
niklassaers committed Mar 17, 2017
1 parent 80b1046 commit 375cbfc
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 18 deletions.
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0.2
33 changes: 33 additions & 0 deletions PackStream.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Pod::Spec.new do |s|

s.name = "PackStream"
s.version = "0.1.2"
s.summary = "PackStream implementation in Swift"

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
s.description = <<-DESC
PackStream is a binary message format very similar to [MessagePack](http://msgpack.org). 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.
DESC

s.homepage = "https://github.com/niklassaers/PackStream-Swift"

s.authors = { "Niklas Saers" => "niklas@saers.com" }
s.social_media_url = "http://twitter.com/niklassaers"

s.license = { :type => "BSD", :file => "LICENSE" }

s.ios.deployment_target = "10.0"
s.osx.deployment_target = "10.12"
s.watchos.deployment_target = "3.0"
s.tvos.deployment_target = "10.0"

s.source = { :git => "https://github.com/niklassaers/PackStream-Swift.git" }
s.source_files = "Sources"

end
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
PackStream implementation in Swift

The purpose of this implementation is to be a dependency to a Swift Bolt implementation. That implementation will aid Theo, the Neo4j Swift driver, with Bolt support
PackStream is a binary message format very similar to [MessagePack](http://msgpack.org). 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.

To use with Xcode, type "swift package generate-xcodeproj"

CocoaPods

Carthage

44 changes: 30 additions & 14 deletions Sources/Int.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,36 @@ extension Int: PackProtocol {

public func pack() throws -> [Byte] {

switch self {
case -0x10 ... 0x7F:
return try Int8(self).pack()
case -0x7F ..< -0x7F:
return try Int8(self).pack()
case -0x8000 ..< 0x8000:
return try Int16(self).pack()
case -0x80000000 ..< 0x80000000:
return try Int32(self).pack()
case -0x8000000000000000 ... (0x800000000000000 - 1):
return try Int64(self).pack()
default:
throw PackError.notPackable
}
#if __LP64__

switch self {
case -0x10 ... 0x7F:
return try Int8(self).pack()
case -0x7F ..< -0x7F:
return try Int8(self).pack()
case -0x8000 ..< 0x8000:
return try Int16(self).pack()
case -0x80000000 ... 0x7fffffff:
return try Int32(self).pack()
case -0x8000000000000000 ... (0x800000000000000 - 1):
return try Int64(self).pack()
default:
throw PackError.notPackable
}
#else
switch self {
case -0x10 ... 0x7F:
return try Int8(self).pack()
case -0x7F ..< -0x7F:
return try Int8(self).pack()
case -0x8000 ..< 0x8000:
return try Int16(self).pack()
case -0x80000000 ... 0x7fffffff:
return try Int32(self).pack()
default:
throw PackError.notPackable
}
#endif
}

public static func unpack(_ bytes: ArraySlice<Byte>) throws -> Int {
Expand Down
2 changes: 1 addition & 1 deletion Sources/List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension List: PackProtocol {

public func pack() throws -> [Byte] {

switch items.count {
switch UInt(items.count) {
case 0:
return [ Constants.shortListMinMarker ]
case 1...15:
Expand Down
2 changes: 1 addition & 1 deletion Sources/Map.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension Map: PackProtocol {
return keyBytes + valueBytes
}).reduce([Byte](), { $0 + $1 })

switch dictionary.count {
switch UInt(dictionary.count) {
case 0:
return [ Constants.shortMapMinMarker ]

Expand Down
2 changes: 1 addition & 1 deletion Sources/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension String: PackProtocol {
}
}

let n = bytes.count
let n = UInt(bytes.count)

if n == 0 {
return [ 0x80 ]
Expand Down

0 comments on commit 375cbfc

Please sign in to comment.