36 lines
751 B
Swift
36 lines
751 B
Swift
//
|
|
// DataExtension.swift
|
|
// sdlan
|
|
//
|
|
// Created by 安礼成 on 2024/2/1.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
extension Data {
|
|
|
|
mutating public func append(int32val: Int32) {
|
|
self.append(contentsOf: [
|
|
(UInt8) (int32val >> 24 & 0xFF),
|
|
(UInt8) (int32val >> 16 & 0xFF),
|
|
(UInt8) (int32val >> 8 & 0xFF),
|
|
(UInt8) (int32val & 0xFF)
|
|
])
|
|
}
|
|
|
|
mutating public func append(int16val: Int16) {
|
|
self.append(contentsOf: [
|
|
(UInt8) (int16val >> 8 & 0xFF),
|
|
(UInt8) (int16val & 0xFF)
|
|
])
|
|
}
|
|
|
|
mutating public func append(str: String) {
|
|
if let data = str.data(using: .utf8) {
|
|
self.append(contentsOf: data)
|
|
}
|
|
}
|
|
|
|
}
|
|
|