Skip to content

Commit

Permalink
Merge pull request #6 from malcommac/fix/swift-5-support
Browse files Browse the repository at this point in the history
Full Swift 5 support and watchOS platform support
  • Loading branch information
malcommac authored Nov 15, 2020
2 parents 8932172 + 5bccf03 commit 62c3109
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 101 deletions.
Binary file modified .DS_Store
Binary file not shown.
26 changes: 0 additions & 26 deletions CHANGELOG.md

This file was deleted.

13 changes: 12 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
// swift-tools-version:5.1
import PackageDescription

let package = Package(
name: "SwiftMsgPack"
name: "SwiftMsgPack",
products: [
.library(name: "SwiftMsgPack", targets: ["SwiftMsgPack"])
],
targets: [
.target(name: "SwiftMsgPack"),
.testTarget(
name: "SwiftMsgPackTests",
dependencies: ["SwiftMsgPack"]
),
]
)
108 changes: 43 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,35 @@
<p align="center" >
<img src="https://raw.githubusercontent.com/malcommac/SwiftMsgPack/develop/logo.png" width=210px height=204px alt="SwiftMsgPack" title="SwiftMsgPack">
<img src="banner.png" width=300px alt="SwiftLocation" title="SwiftLocation">
</p>

<p align="center"><strong>It's like JSON, but faster!</strong></p>


[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![CI Status](https://travis-ci.org/malcommac/SwiftMsgPack.svg)](https://travis-ci.org/malcommac/SwiftMsgPack) [![Version](https://img.shields.io/cocoapods/v/SwiftMsgPack.svg?style=flat)](http://cocoadocs.org/docsets/SwiftMsgPack) [![License](https://img.shields.io/cocoapods/l/SwiftMsgPack.svg?style=flat)](http://cocoadocs.org/docsets/SwiftMsgPack) [![Platform](https://img.shields.io/cocoapods/p/SwiftMsgPack.svg?style=flat)](http://cocoadocs.org/docsets/SwiftMsgPack)

<p align="center" >MsgPack for Swift... Its' like JSON <a href="http://theburningmonk.com/2011/12/performance-test-binary-serializers-part-ii/"> but faster</a><br/>
Made with ♥ in pure Swift, no dependencies, lightweight & fully portable
<p/>
<p align="center" >★★ <b>Star our github repository to help us!</b> ★★</p>
<p align="center" >Created by <a href="http://www.danielemargutti.com">Daniele Margutti</a> (<a href="http://www.twitter.com/danielemargutti">@danielemargutti</a>)</p>
## What's this?

[MessagePack](http://msgpack.org/) is an efficient binary serialization format, which lets you exchange data among multiple languages like JSON, except that it's faster and smaller. Small integers are encoded into a single byte while typical short strings require only one extra byte in addition to the strings themselves.
You can read more about [specs directly from the main web](https://github.com/msgpack/msgpack/blob/master/spec.md) site.
[MessagePack](http://msgpack.org/) is an efficient binary serialization format, which lets you exchange data among multiple languages like JSON, except that it's [faster and smaller](http://theburningmonk.com/2011/12/performance-test-binary-serializers-part-ii). Small integers are encoded into a single byte while typical short strings require only one extra byte in addition to the strings themselves.
You can read more about [specs directly from the main web](https://github.com/msgpack/msgpack/blob/master/spec.md) site.
Moreover it's made in pure Swift, no dependencies, lightweight & fully portable

## You also may like
## Your Support

Do you like `SwiftMsgPack`? I'm also working on several other opensource libraries.
*Hi fellow developer!*
You know, maintaing and developing tools consumes resources and time. While I enjoy making them **your support is foundamental to allow me continue its development**.

Take a look here:
If you are using SwiftLocation or any other of my creations please consider the following options:

* **[SwiftDate](https://github.com/malcommac/SwiftDate)** - Date & Timezone management in Swift
* **[Hydra](https://github.com/malcommac/Hydra)** - Promise, Async/Await on sterioids!
* **[SwiftLocation](https://github.com/malcommac/SwiftLocation)** - CoreLocation and Beacon Monitoring on steroid!
* **[SwiftRichString](https://github.com/malcommac/SwiftRichString)** - Elegant and painless attributed string in Swift
* **[SwiftScanner](https://github.com/malcommac/SwiftScanner)** - String scanner in pure Swift with full unicode support
* **[SwiftSimplify](https://github.com/malcommac/SwiftSimplify)** - Tiny high-performance Swift Polyline Simplification Library
- [**Make a donation with PayPal**](https://www.paypal.com/paypalme/danielemargutti/20)
- [**Become a Sponsor**](https://github.com/sponsors/malcommac)

- [⭐️ Follow Me & Discover Other Projects](https://github.com/malcommac)

## Index
* **[Current Release](#release)**
* **[How to use](#howto)**
* **[Supported Types](#supportedtypes)**
* **[Installation (CocoaPods, SwiftPM and Carthage)](#installation)**
* **[Tests](#tests)**
* **[Requirements](#requirements)**
* **[Credits](#credits)**

<a name="release" />

## Current Release

* **Swift 4.x**: Latest is 1.0.0 [Download here](https://github.com/malcommac/SwiftMsgPack/releases/tag/1.0.0).
* **Swift 3.x**: Last is 0.9.1 [Download here](https://github.com/malcommac/SwiftMsgPack/releases/tag/0.9.1).

A complete list of changes for each release is available in the [CHANGELOG](CHANGELOG.md) file.

<a name="howto" />

Expand All @@ -56,23 +43,24 @@ It's pretty easy, take a look here:
```swift
var data = Data()
do {
let obj1 = "Hello World"
let obj2 = 45.5
let obj3: [AnyHashable:Any?] = [ "key_1" : "value test","key_2" : 4,"key_3" : true, otherHashableKey: "value1"]
// Now you can pack your instances by passing them to pack function
try data.pack(obj1,obj2,obj3)
let obj1 = "Hello World"
let obj2 = 45.5
let obj3: [AnyHashable:Any?] = [ "key_1" : "value test","key_2" : 4,"key_3" : true, otherHashableKey: "value1"]
// Now you can pack your instances by passing them to pack function
try data.pack(obj1,obj2,obj3)
} catch {
print("Something went wrong while packing data: \(error)")
print("Something went wrong while packing data: \(error)")
}
```

Deserializing data is pretty simple too, just call `unpack` function to an instance of `Data` with msgpack data:

```swift
let data: Data = // msgpack data...
do {
let decodedObj: Any? = try data.unpack()
} catch {
print("Something went wrong while unpacking data: \(error)")
print("Something went wrong while unpacking data: \(error)")
}
```

Expand Down Expand Up @@ -115,13 +103,13 @@ You can install Swiftline using CocoaPods, carthage and Swift package manager
Add swiftline as dependency in your `Package.swift`

```
import PackageDescription
import PackageDescription
let package = Package(name: "YourPackage",
dependencies: [
.Package(url: "https://github.com/malcommac/SwiftMsgPack.git", majorVersion: 0),
]
)
let package = Package(name: "YourPackage",
dependencies: [
.Package(url: "https://github.com/malcommac/SwiftMsgPack.git", majorVersion: 0),
]
)
```

<a name="tests" />
Expand All @@ -132,33 +120,23 @@ SwiftMsgPack has an extensive coverage using XCTest.
You can found a complete list of tests inside `Tests/SwiftMsgPackTests` folder.
Tests can also be runned with XCode using the SwiftMsgPack project.

<a name="requirements" />

## Requirements

Current version is compatible with:

* Swift 4.x+ (Swift 3.x up to 0.9.1)
* iOS 9.0 or later
* tvOS 9.0 or later
* macOS 10.10 or later
* Linux compatible environments

<a name="credits" />

## Credits & License
SwiftMsgPack is owned and maintained by [Daniele Margutti](http://www.danielemargutti.com/).
## Contributing

As open source creation any help is welcome!
- If you **need help** or you'd like to **ask a general question**, open an issue.
- If you **found a bug**, open an issue.
- If you **have a feature request**, open an issue.
- If you **want to contribute**, submit a pull request.

The code of this library is licensed under MIT License; you can use it in commercial products without any limitation.
## Copyright & Acknowledgements

The only requirement is to add a line in your Credits/About section with the text below:
SwiftLocation is currently owned and maintained by Daniele Margutti.
You can follow me on Twitter [@danielemargutti](http://twitter.com/danielemargutti).
My web site is [https://www.danielemargutti.com](https://www.danielemargutti.com)

```
This software uses open source SwiftMsgPack's library to manage MsgPack data.
Web: http://github.com/malcommac/SwiftMsgPack.
Created by Daniele Margutti and licensed under MIT License.
```
This software is licensed under [MIT License](LICENSE.md).

msgpack.org[SwiftMsgPack]
***Follow me on:***
- 💼 [Linkedin](https://www.linkedin.com/in/danielemargutti/)
- 🐦 [Twitter](https://twitter.com/danielemargutti)
4 changes: 2 additions & 2 deletions Sources/SwiftMsgPack/Decoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private struct StreamReader {
guard index + length <= data.count else {
throw MsgPackError.unexpectedData
}
let range = Range(index..<(index + length))
let range = index ..< (index + length)
index += length
return data.subdata(in: range)
}
Expand All @@ -144,7 +144,7 @@ public extension Data {
///
/// - Returns: decoded data
/// - Throws: an error if decoding task cannot be finished correctly due to an error
public func unpack() throws -> Any? {
func unpack() throws -> Any? {
// Create a reader which has a point to the current position in data instance
// and several help functions to read data
var reader = StreamReader(self)
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftMsgPack/Encoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public extension Data {
/// - Returns: `self` `(maybe used to chain multiple pack`)
/// - Throws: throw an exception if packing fails for some reason
@discardableResult
public mutating func pack(_ objects: Any?...) throws -> Data {
mutating func pack(_ objects: Any?...) throws -> Data {
try objects.forEach { try self.pack($0) }
return self
}
Expand All @@ -62,7 +62,7 @@ public extension Data {
/// - Returns: `self` `(maybe used to chain multiple pack`)
/// - Throws: throw an exception if packing fails for some reason
@discardableResult
public mutating func pack(_ obj: Any?) throws -> Data {
mutating func pack(_ obj: Any?) throws -> Data {

guard let obj = obj else {
// If the object is nil we want to write the nil
Expand Down Expand Up @@ -200,7 +200,7 @@ public extension Data {
/// - Parameter bool: boolean value to pack
/// - Returns: the instance of `self` modified with the packed data
@discardableResult
public mutating func pack(boolean bool: Bool) throws -> Data {
mutating func pack(boolean bool: Bool) throws -> Data {
try self.writeDataTypeHeader(.boolean(bool))
return self
}
Expand Down
Binary file removed SwiftMsgPack-logo-source.sketch
Binary file not shown.
3 changes: 2 additions & 1 deletion SwiftMsgPack.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'SwiftMsgPack'
spec.version = '1.0.0'
spec.version = '1.2.0'
spec.summary = 'MsgPack Encoder/Decoder in pure Swift'
spec.homepage = 'https://github.com/malcommac/SwiftMsgPack'
spec.license = { :type => 'MIT', :file => 'LICENSE' }
Expand All @@ -11,6 +11,7 @@ Pod::Spec.new do |spec|
spec.ios.deployment_target = '8.0'
spec.osx.deployment_target = '10.10'
spec.tvos.deployment_target = '9.0'
spec.watchos.deployment_target = '2.0'
spec.requires_arc = true
spec.module_name = 'SwiftMsgPack'
end
Binary file added Tests/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion Tests/SwiftMsgPackTests/SwiftMsgPackTests_BoolNil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class SwiftMsgPackTests_BoolNil: XCTestCase {

} catch let err {
// Something went wrong while packing data
XCTFail("[\(testName)] Failed to pack nil: \(err) (src='\(value)')")
XCTFail("[\(testName)] Failed to pack nil: \(err) (src='\(String(describing: value))')")
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftMsgPackTests/SwiftMsgPackTests_Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class SwiftMsgPackTests_Data: XCTestCase {
// Append real data
bytes.append(contentsOf: data_sequence)
// Get generated data
let data = Data(bytes: data_sequence)
let data = Data(data_sequence)
return (data,bytes)
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftMsgPackTests/SwiftMsgPackTests_String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class SwiftMsgPackTests_String: XCTestCase {
XCTFail("[\(testName)] Failed to cast unpacked data to a valid String instance")
return
}
guard str_value.characters.count == value.characters.count else {
guard str_value.count == value.count else {
XCTFail("[\(testName)] Unpacked string has a different number of characters than source")
return
}
Expand Down
Binary file added banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed logo.png
Binary file not shown.

0 comments on commit 62c3109

Please sign in to comment.