forked from vapor/postgres-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgresMessage+Close.swift
40 lines (33 loc) · 1.37 KB
/
PostgresMessage+Close.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
37
38
39
40
import NIOCore
extension PostgresMessage {
/// Identifies the message as a Close Command
@available(*, deprecated, message: "Will be removed from public API")
public struct Close: PostgresMessageType {
public static var identifier: PostgresMessage.Identifier {
return .close
}
/// Close Target. Determines if the Close command should close a prepared statement
/// or portal.
public enum Target: Int8 {
case preparedStatement = 0x53 // 'S' - prepared statement
case portal = 0x50 // 'P' - portal
}
/// Determines if the `name` identifes a portal or a prepared statement
public var target: Target
/// The name of the prepared statement or portal to describe
/// (an empty string selects the unnamed prepared statement or portal).
public var name: String
/// See `CustomStringConvertible`.
public var description: String {
switch target {
case .preparedStatement: return "Statement(\(name))"
case .portal: return "Portal(\(name))"
}
}
/// Serializes this message into a byte buffer.
public func serialize(into buffer: inout ByteBuffer) throws {
buffer.writeInteger(target.rawValue)
buffer.writeNullTerminatedString(name)
}
}
}