Skip to content

Commit 805c5c6

Browse files
committed
all: swift-format -r -i ./
1 parent d2b659b commit 805c5c6

8 files changed

+30
-33
lines changed

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let package = Package(
1111
.library(
1212
name: "RTP",
1313
targets: ["RTP"]
14-
),
14+
)
1515
],
1616
dependencies: [],
1717
targets: [

Sources/RTP/Connection.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,16 @@
5050
if let error = error {
5151
print("Error receiving UDP packet: \(error)")
5252
return
53-
} else if let data = data {
53+
}
54+
else if let data = data {
5455
// print("⬇️ Received UDP packet of size: \(data.count)")
5556

5657
do {
5758
let packet = try Packet(from: data)
5859
// print("🅿️ Parsed RTP packet: \(packet)")
5960
self?.receiverBlock(packet)
60-
} catch {
61+
}
62+
catch {
6163
print("Error handling RTP: \(error)")
6264
return
6365
}

Sources/RTP/Data+Extensions.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Foundation
22

3-
internal extension Data {
3+
extension Data {
44
// big returns a big-endian integer of type T extracted from the bytes at the specified offset.
55
func big<T: FixedWidthInteger>(at offset: Int) -> T {
66
var value: T = 0
77
withUnsafeMutablePointer(to: &value) {
8-
self.copyBytes(to: UnsafeMutableBufferPointer(start: $0, count: 1), from: offset ..< offset + MemoryLayout<T>.size)
8+
self.copyBytes(to: UnsafeMutableBufferPointer(start: $0, count: 1), from: offset..<offset + MemoryLayout<T>.size)
99
}
1010
return T(bigEndian: value)
1111
}
@@ -14,7 +14,7 @@ internal extension Data {
1414
func little<T: FixedWidthInteger>(at offset: Int) -> T {
1515
var value: T = 0
1616
withUnsafeMutablePointer(to: &value) {
17-
self.copyBytes(to: UnsafeMutableBufferPointer(start: $0, count: 1), from: offset ..< offset + MemoryLayout<T>.size)
17+
self.copyBytes(to: UnsafeMutableBufferPointer(start: $0, count: 1), from: offset..<offset + MemoryLayout<T>.size)
1818
}
1919
return T(littleEndian: value)
2020
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Foundation
22

3-
public extension FixedWidthInteger {
3+
extension FixedWidthInteger {
44
// random is a convenience function to generate a random value of the concrete type in [min,max]
5-
static func random() -> Self {
5+
public static func random() -> Self {
66
Self.random(in: .min ... .max)
77
}
88
}

Sources/RTP/Packet.swift

+9-14
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public struct Packet {
3030
public let padding: UInt8
3131

3232
var payloadWithoutPadding: Data {
33-
payload[0 ..< payload.count - Int(padding)]
33+
payload[0..<payload.count - Int(padding)]
3434
}
3535

3636
var encodedSize: Int {
@@ -81,9 +81,7 @@ public struct Packet {
8181
}
8282
let hasPadding = (data[0] & Self.paddingMask) != 0
8383
let hasExtension = (data[0] & Self.extensionMask) != 0
84-
let sizeWithPaddingAndExtension = Self.headerSize +
85-
(hasPadding ? 1 : 0) +
86-
(hasExtension ? Extension.headerSize : 0)
84+
let sizeWithPaddingAndExtension = Self.headerSize + (hasPadding ? 1 : 0) + (hasExtension ? Extension.headerSize : 0)
8785

8886
// Parse second octet
8987
marker = (data[Self.markerOffset] & Self.markerMask) != 0
@@ -106,10 +104,11 @@ public struct Packet {
106104

107105
// Parse optional CSRCs in octets 13+
108106
if csrcCount > 0 {
109-
csrcs = (0 ..< csrcCount).map {
107+
csrcs = (0..<csrcCount).map {
110108
data.big(at: Self.csrcOffset + $0)
111109
}
112-
} else {
110+
}
111+
else {
113112
csrcs = nil
114113
}
115114

@@ -130,14 +129,10 @@ public struct Packet {
130129
var data = Data(capacity: encodedSize)
131130

132131
// Encode first octect (version, padding, extension)
133-
data.append(contentsOf: [(Self.version << 6 & Self.versionMask) |
134-
(padding > 0 ? Self.paddingMask : 0) |
135-
(`extension` != nil ? Self.extensionMask : 0) |
136-
(UInt8(csrcs?.count ?? 0) & Self.csrcCountMask)])
132+
data.append(contentsOf: [(Self.version << 6 & Self.versionMask) | (padding > 0 ? Self.paddingMask : 0) | (`extension` != nil ? Self.extensionMask : 0) | (UInt8(csrcs?.count ?? 0) & Self.csrcCountMask)])
137133

138134
// Encode second octet
139-
data.append(contentsOf: [(marker ? Self.markerMask : 0) |
140-
(payloadType.rawValue & Self.payloadTypeMask)])
135+
data.append(contentsOf: [(marker ? Self.markerMask : 0) | (payloadType.rawValue & Self.payloadTypeMask)])
141136

142137
// Encode sequence number
143138
data.append(contentsOf: [UInt8(sequenceNumber >> 8 & 0xFF), UInt8(sequenceNumber & 0xFF)])
@@ -150,7 +145,7 @@ public struct Packet {
150145

151146
// Encode CSRCs
152147
if let csrcs = csrcs {
153-
for i in 0 ..< csrcs.count {
148+
for i in 0..<csrcs.count {
154149
data.append(contentsOf: [UInt8(csrcs[i] >> 24 & 0xFF), UInt8(csrcs[i] >> 16 & 0xFF), UInt8(csrcs[i] >> 8 & 0xFF), UInt8(csrcs[i] & 0xFF)])
155150
}
156151
}
@@ -203,7 +198,7 @@ public struct Extension {
203198
throw EncodingError.extensionDataTooSmall(size)
204199
}
205200

206-
payload = data[Self.headerSize ..< size]
201+
payload = data[Self.headerSize..<size]
207202
}
208203
}
209204

Tests/RTPTests/ConnectionTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
XCTAssertEqual(conn.conn.state, .cancelled)
1818
conn.conn.restart()
1919
sleep(1)
20-
XCTAssertEqual(conn.conn.state, .cancelled) // NWConnection instances cannot be restarted once cancelled
20+
XCTAssertEqual(conn.conn.state, .cancelled) // NWConnection instances cannot be restarted once cancelled
2121
}
2222
}
2323

Tests/RTPTests/PacketTests.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import XCTest
55
class PacketTests: XCTestCase {
66
func testInitWithData() throws {
77
let bytes: [UInt8] = [
8-
2 << 6, // Version 2, no marker or extension
9-
111, // Opus payload type
10-
0, 123, // Sequence number 123
11-
0, 0, 0, 1, // Timestamp 1
12-
0, 255, 255, 255, // SSRC 0x00FFFFFF
8+
2 << 6, // Version 2, no marker or extension
9+
111, // Opus payload type
10+
0, 123, // Sequence number 123
11+
0, 0, 0, 1, // Timestamp 1
12+
0, 255, 255, 255, // SSRC 0x00FFFFFF
1313
]
1414

1515
let packet = try RTP.Packet(from: Data(bytes))

Tests/RTPTests/TypeTests.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ class TypeTests: XCTestCase {
2424

2525
func testPacketInitWithData() throws {
2626
let bytes: [UInt8] = [
27-
2 << 6, // Version 2, no marker or extension
28-
111, // Opus payload type
29-
0, 123, // Sequence number 123
30-
0, 0, 0, 1, // Timestamp 1
31-
0, 255, 255, 255, // SSRC 0x00FFFFFF
27+
2 << 6, // Version 2, no marker or extension
28+
111, // Opus payload type
29+
0, 123, // Sequence number 123
30+
0, 0, 0, 1, // Timestamp 1
31+
0, 255, 255, 255, // SSRC 0x00FFFFFF
3232
]
3333

3434
let packet = try RTP.Packet(from: Data(bytes))

0 commit comments

Comments
 (0)