From b2e612a96937e64c90b45bff7cdf823f0d0e0d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=AB=E9=80=8D=E6=97=AD?= Date: Fri, 19 Aug 2016 11:59:09 +0800 Subject: [PATCH] error message add data, push message content string->bytes --- mpush_client/ClientListener.swift | 2 +- mpush_client/DefaultClientListener.swift | 2 +- mpush_client/ErrorMessage.swift | 8 +++++--- mpush_client/PacketDecoder.swift | 3 +-- mpush_client/PushMessage.swift | 6 +++--- mpush_clientTests/mpush_clientTests.swift | 2 +- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/mpush_client/ClientListener.swift b/mpush_client/ClientListener.swift index 22152b3..91dc10e 100644 --- a/mpush_client/ClientListener.swift +++ b/mpush_client/ClientListener.swift @@ -16,7 +16,7 @@ protocol ClientListener { func onHandshakeOk(client: Client, heartbeat: Int); - func onReceivePush(client: Client, content: String); + func onReceivePush(client: Client, content: NSData); func onKickUser(deviceId: String, userId: String); } \ No newline at end of file diff --git a/mpush_client/DefaultClientListener.swift b/mpush_client/DefaultClientListener.swift index 9f0f8dc..75301d2 100644 --- a/mpush_client/DefaultClientListener.swift +++ b/mpush_client/DefaultClientListener.swift @@ -39,7 +39,7 @@ final class DefaultClientListener: ClientListener { } } - func onReceivePush(client: Client, content: String) { + func onReceivePush(client: Client, content: NSData) { if let listener = self.listener { dispatch_async(dispatch_queue, {listener.onReceivePush(client, content: content)}) } diff --git a/mpush_client/ErrorMessage.swift b/mpush_client/ErrorMessage.swift index 4e2f3a4..d87ee50 100644 --- a/mpush_client/ErrorMessage.swift +++ b/mpush_client/ErrorMessage.swift @@ -9,14 +9,16 @@ import Foundation final class ErrorMessage: ByteBufMessage, CustomDebugStringConvertible { - var cmd:Int8 = 0; - var code:Int8 = 0; - var reason:String?; + var cmd: Int8 = 0; + var code: Int8 = 0; + var reason: String?; + var data: String?; override func decode(body: RFIReader) { cmd = body.readByte(); code = body.readByte(); reason = body.readString(); + data = body.readString(); } diff --git a/mpush_client/PacketDecoder.swift b/mpush_client/PacketDecoder.swift index bc52695..f087bc2 100644 --- a/mpush_client/PacketDecoder.swift +++ b/mpush_client/PacketDecoder.swift @@ -25,7 +25,6 @@ final class PacketDecoder { return Packet.HB_PACKET; } buffer.reset(); - } return nil; } @@ -54,7 +53,7 @@ final class PacketDecoder { let data = buffer.readBytes(bodyLength) body = NSData(bytes: data, length: data.count); } - return Packet(cmd: command,cc: cc,flags: flags,sessionId: sessionId,lrc:lrc,body:body); + return Packet(cmd: command, cc: cc, flags: flags, sessionId: sessionId, lrc: lrc, body: body); } } \ No newline at end of file diff --git a/mpush_client/PushMessage.swift b/mpush_client/PushMessage.swift index 8ba5f50..8aca396 100644 --- a/mpush_client/PushMessage.swift +++ b/mpush_client/PushMessage.swift @@ -9,13 +9,13 @@ import Foundation final class PushMessage: BaseMessage, CustomDebugStringConvertible { - var content:String!; + var content:NSData!; override func decode(body:NSData) { - content = String(data: body, encoding:NSUTF8StringEncoding) + content = body; } var debugDescription: String { - return "PushMessage={content:\(content)}" + return "PushMessage={content:\(content.length)}" } } \ No newline at end of file diff --git a/mpush_clientTests/mpush_clientTests.swift b/mpush_clientTests/mpush_clientTests.swift index e9c52b7..ac21ada 100644 --- a/mpush_clientTests/mpush_clientTests.swift +++ b/mpush_clientTests/mpush_clientTests.swift @@ -60,7 +60,7 @@ class mpush_clientTests: XCTestCase { } } - func onReceivePush(client: Client, content: String){} + func onReceivePush(client: Client, content: NSData){} func onKickUser(deviceId: String, userId: String){} }