Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import Foundation
public struct Payload: Codable, Equatable, Hashable {
public var text: String
public var reply: Reply?
public var attachment: Attachment?
public init(text: String, reply: Reply?, attachment: Attachment?) {
self.text = text
self.reply = reply
self.attachment = attachment
}
public init(with marshaled: Data) throws {
let proto = try CMIXText(serializedData: marshaled)
var reply: Reply?
if proto.hasReply {
reply = Reply(
messageId: proto.reply.messageID,
senderId: proto.reply.senderID
)
}
self.init(text: proto.text, reply: reply, attachment: nil)
}
public func asData() -> Data {
var protoModel = CMIXText()
protoModel.text = text
if let reply = reply {
protoModel.reply = reply.asTextReply()
}
return try! protoModel.serializedData()
}
}