내용은 잘 모르겠음. 추후 공부해야되는 내용

Hex Code 문자열로 변경해 주는거 같은데 정확한 Hasher() 함수의 기능에 대해서는 잘 모름.ㅜㅜ

extension Data {
    struct HexEncodingOptions: OptionSet {
        let rawValue: Int
        static let upperCase = HexEncodingOptions(rawValue: 1 << 0)
    }

    func hexEncodedString(options: HexEncodingOptions = []) -> String {
        let hexDigits = Array((options.contains(.upperCase) ? "0123456789ABCDEF" : "0123456789abcdef").utf16)
        var chars: [unichar] = []
        chars.reserveCapacity(2 * count)
        for byte in self {
            chars.append(hexDigits[Int(byte / 16)])
            chars.append(hexDigits[Int(byte % 16)])
        }
        return String(utf16CodeUnits: chars, count: chars.count)
    }
}

 

[사용방법]

var hasher = Hasher()
hasher.combine("787899")
hasher.bombine("1022032")
var hashValue = hasher.finalize()
var data = Data()

//data.append(UnsafeBufferPointer(start: &hashValue, count: 1))
withUnsafePointer(to: &hashValue) {
	data.append(UnsafeBufferPointer(start: $0, count: 1))
}

log(direction: .ETC, ofType: self, datas: data.hexEncodedString())

+ Recent posts