forked from vapor/postgres-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgresMessageType.swift
36 lines (30 loc) · 1.37 KB
/
PostgresMessageType.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import NIOCore
@available(*, deprecated, message: "Will be removed from public API. Internally we now use `PostgresBackendMessage` and `PostgresFrontendMessage`")
public protocol PostgresMessageType {
static var identifier: PostgresMessage.Identifier { get }
static func parse(from buffer: inout ByteBuffer) throws -> Self
func serialize(into buffer: inout ByteBuffer) throws
}
@available(*, deprecated, message: "`PostgresMessageType` protocol is deprecated.")
extension PostgresMessageType {
@available(*, deprecated, message: "Will be removed from public API.")
func message() throws -> PostgresMessage {
var buffer = ByteBufferAllocator().buffer(capacity: 0)
try self.serialize(into: &buffer)
return .init(identifier: Self.identifier, data: buffer)
}
public init(message: PostgresMessage) throws {
var message = message
self = try Self.parse(from: &message.data)
}
@available(*, deprecated, message: "Will be removed from public API.")
public static var identifier: PostgresMessage.Identifier {
return .none
}
public static func parse(from buffer: inout ByteBuffer) throws -> Self {
fatalError("\(Self.self) does not support parsing.")
}
public func serialize(into buffer: inout ByteBuffer) throws {
fatalError("\(Self.self) does not support serializing.")
}
}