-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major 7 simple value encoding is done
- Loading branch information
Hassan Shahbazi
authored and
Hassan Shahbazi
committed
May 15, 2018
1 parent
3c9d17f
commit c8eef6a
Showing
6 changed files
with
78 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+79.2 KB
(180%)
...codeproj/project.xcworkspace/xcuserdata/hassan.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// MyNSObject.swift | ||
// CBORSwift | ||
// | ||
// Created by Hassan Shahbazi on 2018-05-15. | ||
// Copyright © 2018 Hassan Shahbazi. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
public class NSByteString: NSObject { | ||
private var value: String = "" | ||
|
||
public init(_ value: String) { | ||
super.init() | ||
self.value = value | ||
} | ||
|
||
@objc override func encode() -> String { | ||
var byteArray = [UInt8]() | ||
for offset in stride(from: 0, to: self.value.count, by: 2) { | ||
let byte = value[offset..<offset+2].hex_decimal | ||
byteArray.append(UInt8(byte)) | ||
} | ||
let encodedArray = Encoder.prepareByteArray(major: .major2, measure: byteArray.count) | ||
let headerData = Data(bytes: encodedArray).binary_decimal.hex | ||
let byteData = Data(bytes: byteArray).hex | ||
|
||
return headerData.appending(byteData) | ||
} | ||
} | ||
|
||
public class NSSimpleValue: NSObject { | ||
private let FALSECode: UInt8 = 0x14 | ||
private let TRUECode: UInt8 = 0x15 | ||
private let NILCode: UInt8 = 0x16 | ||
private var value: Bool? | ||
|
||
public init(_ value: NSNumber?) { | ||
super.init() | ||
self.value = value?.boolValue | ||
} | ||
|
||
@objc override func encode() -> String { | ||
var byte = NILCode | ||
if value != nil { | ||
byte = (value!) ? TRUECode : FALSECode | ||
} | ||
var encodedArray = Encoder.prepareByteArray(major: .major7, measure: 0) | ||
encodedArray = [UInt8](encodedArray[0..<3]) | ||
|
||
var byteArray = Data(bytes: [byte]).hex.hex_binary | ||
byteArray = [UInt8](byteArray[3..<byteArray.count]) | ||
|
||
encodedArray.append(contentsOf: byteArray) | ||
return Data(bytes: encodedArray).binary_decimal.hex | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters