add Player model
This commit is contained in:
18
Sources/stella/Decoders/MsgPack.swift
Normal file
18
Sources/stella/Decoders/MsgPack.swift
Normal file
@@ -0,0 +1,18 @@
|
||||
import SwiftMsgpack
|
||||
import Vapor
|
||||
|
||||
extension MsgPackEncoder: @retroactive ContentEncoder, @retroactive @unchecked Sendable {
|
||||
public func encode<E>(_ encodable: E, to body: inout ByteBuffer, headers: inout HTTPHeaders) throws where E : Encodable {
|
||||
let data = try self.encode(encodable)
|
||||
body.writeString(data.base64EncodedString())
|
||||
}
|
||||
}
|
||||
|
||||
extension MsgPackDecoder: @retroactive ContentDecoder, @retroactive @unchecked Sendable {
|
||||
public func decode<D>(_ decodable: D.Type, from body: ByteBuffer, headers: HTTPHeaders) throws -> D where D : Decodable {
|
||||
guard let base64String = body.peekString(length: body.capacity), let data = Data(base64Encoded: base64String) else {
|
||||
throw Abort(.badRequest)
|
||||
}
|
||||
return try self.decode(decodable, from: data)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user