Adopt swift-format (#2794)

* Apply formatting

* Apply no block comments rule

* Apply OmitExplicitReturns

* Apple OnlyOneTrailingClosureArgument

* Apply NoAssignmentInExpressions

* Fix up DontRepeatTypeInStaticProperties lint errors

* Apply `OrderedImports`

* Apply `ReplaceForEachWithForLoop`

* format file

* Enable the formatting pipeline

* Adopt `AmbiguousTrailingClosureOverload`

* Fix license header

* Fix format check

* Fix `EndOfLineComment`

* Fix CI

* Adapt CI script to check if changes when running formatting

* Separate lint and format into to steps

* Fix format

* Adopt `UseEarlyExits`

* Revert "Adopt `UseEarlyExits`"

This reverts commit d1ac5bbe12.
This commit is contained in:
Franz Busch authored and GitHub committed 2024-07-19 11:48:17 +02:00
1 parent 980bd3e630
commit c9756e1083
374 files changed
+23992 -14890

No files matched your search

@@ -48,7 +48,7 @@ public final class WebSocketFrameEncoder: ChannelOutboundHandler {
/// for a mask key.
private static let maximumFrameHeaderLength: Int = (2 + 4 + 8)
public init() { }
public init() {}
public func handlerAdded(context: ChannelHandlerContext) {
self.headerBuffer = context.channel.allocator.buffer(capacity: WebSocketFrameEncoder.maximumFrameHeaderLength)
@@ -63,7 +63,11 @@ public final class WebSocketFrameEncoder: ChannelOutboundHandler {
// First, we explode the frame structure and apply the mask.
let frameHeader = FrameHeader(frame: data)
var (extensionData, applicationData) = self.mask(key: frameHeader.maskKey, extensionData: data.extensionData, applicationData: data.data)
var (extensionData, applicationData) = self.mask(
key: frameHeader.maskKey,
extensionData: data.extensionData,
applicationData: data.data
)
// Now we attempt to prepend the frame header to the first buffer. If we can't, we'll write to the header buffer. If we have
// an extension data buffer, that's the first buffer, and we'll also write it here.
@@ -83,7 +87,11 @@ public final class WebSocketFrameEncoder: ChannelOutboundHandler {
}
/// Applies the websocket masking operation based on the passed byte buffers.
private func mask(key: WebSocketMaskingKey?, extensionData: ByteBuffer?, applicationData: ByteBuffer) -> (ByteBuffer?, ByteBuffer) {
private func mask(
key: WebSocketMaskingKey?,
extensionData: ByteBuffer?,
applicationData: ByteBuffer
) -> (ByteBuffer?, ByteBuffer) {
guard let key = key else {
return (extensionData, applicationData)
}
@@ -181,9 +189,8 @@ extension ByteBuffer {
}
}
/// A helper object that holds only a websocket frame header. Used to avoid accidentally CoWing on some paths.
fileprivate struct FrameHeader {
private struct FrameHeader {
var length: Int
var maskKey: WebSocketMaskingKey?
var firstByte: UInt8 = 0
@@ -214,7 +221,6 @@ fileprivate struct FrameHeader {
size += 4 // Masking key
}
return size
}
}