forked from SwiftcordApp/DiscordKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patch (RobustWebSocket): allow resuming when seq is nil
feat: add NullEncoder property wrapper chore: clean up logging messages
- Loading branch information
1 parent
43e697f
commit 65c2202
Showing
4 changed files
with
32 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// NullEncoder.swift | ||
// From https://stackoverflow.com/a/62312021/ | ||
// | ||
// | ||
// Created by Vincent Kwok on 14/10/22. | ||
// | ||
|
||
import Foundation | ||
|
||
/// Explicitly include a value even when nil when encoded | ||
@propertyWrapper | ||
public struct NullEncodable<T>: Encodable where T: Encodable { | ||
public let wrappedValue: T? | ||
|
||
public init(wrappedValue: T?) { | ||
self.wrappedValue = wrappedValue | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.singleValueContainer() | ||
switch wrappedValue { | ||
case .some(let value): try container.encode(value) | ||
case .none: try container.encodeNil() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters