A fast, safe, and efficient CBOR serialization library for Swift on any platform.
swiftpackageindex.com/thecoolwinter/CBOR/1.1.1/documentation/cbor
atproto
swift
cbor
1//
2// Data+hexString.swift
3// CBOR
4//
5// Created by Khan Winter on 9/1/25.
6//
7
8#if canImport(FoundationEssentials)
9import FoundationEssentials
10#else
11import Foundation
12#endif
13
14extension Data {
15 private static let hexAlphabet = Array("0123456789abcdef".unicodeScalars)
16
17 func hexString() -> String {
18 // I'd rather use: map { String(format: "%02hhX", $0) }.joined()
19 // but that doesn't compile on linux...
20 String(reduce(into: "".unicodeScalars) { result, value in
21 result.append(Self.hexAlphabet[Int(value / 0x10)])
22 result.append(Self.hexAlphabet[Int(value % 0x10)])
23 })
24 }
25}