Skip to content

Commit 149c096

Browse files
Added Packet struct
1 parent 5653e6f commit 149c096

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Sources/Socket/Packet.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import Foundation
22

3+
public struct Packet {
4+
public let id : UInt8
5+
public let data : [UInt8]
6+
}
7+
38
extension Socket {
49

510
/// Receive UInt8 from socket.
@@ -31,11 +36,11 @@ extension Socket {
3136
}
3237

3338
/// 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 {
3540
let (packet, length) : (UInt8, UInt16) = try recvHeader(length: headerLength)
3641
let data : [UInt8] = try recvUInt8(length: Int32(length), flags: flags)
3742

38-
return (packet, data)
43+
return Packet(id: packet, data: data)
3944
}
4045

4146
/// Send header data for outgoing message.

Tests/SocketTests/SocketTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ class SocketTests : XCTestCase {
3636
}
3737

3838
func testRecv() throws {
39-
let (packet, data) : (UInt8, [UInt8]) = try socket!.recvPacket(headerLength: 3)
39+
let packet : Packet = try socket!.recvPacket(headerLength: 3)
4040

41-
print("Received packet : #\(packet)")
42-
print(data)
41+
print("Received packet : #\(packet.id)")
42+
print(packet.data)
4343
}
4444

4545
func testSend() throws {

0 commit comments

Comments
 (0)