59 lines
1.1 KiB
Swift
59 lines
1.1 KiB
Swift
//
|
|
// NoticeMessage.swift
|
|
// sdlan
|
|
//
|
|
// Created by 安礼成 on 2025/7/14.
|
|
//
|
|
|
|
|
|
//
|
|
// NoticeMessage.swift
|
|
// sdlan
|
|
//
|
|
// Created by 安礼成 on 2024/6/3.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
struct NoticeMessage {
|
|
// 消息类型
|
|
enum NoticeType: UInt8 {
|
|
case upgrade = 1
|
|
case alert = 2
|
|
}
|
|
|
|
struct UpgradeMessage: Codable {
|
|
let prompt: String
|
|
let address: String
|
|
|
|
var binaryData: Data {
|
|
let json = try! JSONEncoder().encode(self)
|
|
var data = Data()
|
|
data.append(contentsOf: [NoticeType.upgrade.rawValue])
|
|
data.append(json)
|
|
|
|
return data
|
|
}
|
|
}
|
|
|
|
struct AlertMessage: Codable {
|
|
let alert: String
|
|
|
|
var binaryData: Data {
|
|
let json = try! JSONEncoder().encode(self)
|
|
var data = Data()
|
|
data.append(contentsOf: [NoticeType.alert.rawValue])
|
|
data.append(json)
|
|
|
|
return data
|
|
}
|
|
}
|
|
|
|
enum InboundMessage {
|
|
case none
|
|
case upgradeMessage(UpgradeMessage)
|
|
case alertMessage(AlertMessage)
|
|
}
|
|
|
|
}
|