File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change 1
1
import Foundation
2
2
3
+ public struct Packet {
4
+ public let id : UInt8
5
+ public let data : [ UInt8 ]
6
+ }
7
+
3
8
extension Socket {
4
9
5
10
/// Receive UInt8 from socket.
@@ -31,11 +36,11 @@ extension Socket {
31
36
}
32
37
33
38
/// Receive packet data for incoming message.
34
- public func recvPacket( headerLength : Int32 , flags : Int32 = 0 ) throws -> ( UInt8 , [ UInt8 ] ) {
39
+ public func recvPacket( headerLength : Int32 , flags : Int32 = 0 ) throws -> Packet {
35
40
let ( packet, length) : ( UInt8 , UInt16 ) = try recvHeader ( length: headerLength)
36
41
let data : [ UInt8 ] = try recvUInt8 ( length: Int32 ( length) , flags: flags)
37
42
38
- return ( packet, data)
43
+ return Packet ( id : packet, data : data)
39
44
}
40
45
41
46
/// Send header data for outgoing message.
Original file line number Diff line number Diff line change @@ -36,10 +36,10 @@ class SocketTests : XCTestCase {
36
36
}
37
37
38
38
func testRecv( ) throws {
39
- let ( packet, data ) : ( UInt8 , [ UInt8 ] ) = try socket!. recvPacket ( headerLength: 3 )
39
+ let packet : Packet = try socket!. recvPacket ( headerLength: 3 )
40
40
41
- print ( " Received packet : # \( packet) " )
42
- print ( data)
41
+ print ( " Received packet : # \( packet. id ) " )
42
+ print ( packet . data)
43
43
}
44
44
45
45
func testSend( ) throws {
You can’t perform that action at this time.
0 commit comments