https://github.com/fitnesskit/datadecoder
Swift Data Decoder. Easily Decode Data values
https://github.com/fitnesskit/datadecoder
data-decoders decoder nsdata swift swift-package-manager swift3
Last synced: about 1 month ago
JSON representation
Swift Data Decoder. Easily Decode Data values
- Host: GitHub
- URL: https://github.com/fitnesskit/datadecoder
- Owner: FitnessKit
- License: mit
- Created: 2017-03-31T13:31:24.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-04-20T15:38:56.000Z (about 6 years ago)
- Last Synced: 2025-04-09T23:52:40.973Z (about 1 month ago)
- Topics: data-decoders, decoder, nsdata, swift, swift-package-manager, swift3
- Language: Swift
- Homepage: https://fitnesskit.github.io/DataDecoder
- Size: 154 KB
- Stars: 12
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DataDecoder
Swift Data Decoder. Easily Decode Data values[](https://developer.apple.com/swift)
[](http://cocoapods.org/pods/DataDecoder)
[](http://cocoapods.org/pods/DataDecoder)
[](http://cocoapods.org/pods/DataDecoder)
[](http://clayallsopp.github.io/readme-score?url=https://github.com/fitnesskit/datadecoder)## Installation
DataDecoder is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod "DataDecoder"
```Swift Package Manager:
```swift
dependencies: [
.package(url: "https://github.com/FitnessKit/DataDecoder", from: "5.0.0"),
]
```Swift4
```swift
dependencies: [
.package(url: "https://github.com/FitnessKit/DataDecoder", .branch("swift42")),
]
```## How to Use ##
Example:
```swift
let sensorData: Data = Data([ 0x02, 0xFE, 0xFF, 0xEF, 0xBE, 0xAD, 0xDE, 0xA5])var decoder = DecodeData()
let height = decoder.decodeUInt8(sensorData)
let weight = decoder.decodeUInt16(sensorData)
let deadbeef = decoder.decodeUInt32(sensorData)
let nib = decoder.decodeNibble(sensorData)
//This should come back 0 as there is no more data left
let novalue = decoder.decodeNibble(sensorData)
```Example Using Optionals:
```swift
let sensorData: Data = Data([ 0x02, 0xFE, 0xFF, 0xEF, 0xBE, 0xAD, 0xDE, 0xA5])var decoder = DecodeData()
if let height = decoder.decodeUInt8IfPresent(sensorData) {}
let weight = decoder.decodeUInt16IfPresent(sensorData)
let deadbeef = decoder.decodeUInt32IfPresent(sensorData)
let nib = decoder.decodeNibbleIfPresent(sensorData)
// This will be nil as there is no data left
let novalue = decoder.decodeUInt8IfPresent(sensorData)
```## Data Decoders ##
* Nibble
* UInt8/Int8
* UInt16/Int16
* UInt24/Int23
* UInt32/Int32
* UInt48
* UInt64/Int64
* IP Address to String Value
* MAC Address to String Value### IEEE-11073
* 16-bit SFLOAT
* 32-bit FLOAT### IEEE-754
* Float32
* Float64## Author
This package is developed and maintained by Kevin A. Hoogheem
## License
DataDecoder is available under the [MIT license](http://opensource.org/licenses/MIT)