forked from vapor/postgres-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgresMessage+Describe.swift
37 lines (31 loc) · 1.21 KB
/
PostgresMessage+Describe.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
import NIOCore
extension PostgresMessage {
/// Identifies the message as a Describe command.
public struct Describe: PostgresMessageType {
public static var identifier: PostgresMessage.Identifier {
return .describe
}
/// Command type.
public enum Command: UInt8 {
case statement = 0x53 // S
case portal = 0x50 // P
}
/// 'S' to describe a prepared statement; or 'P' to describe a portal.
public let command: Command
/// 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 command {
case .statement: return "Statement(" + name + ")"
case .portal: return "Portal(" + name + ")"
}
}
/// Serializes this message into a byte buffer.
public func serialize(into buffer: inout ByteBuffer) {
buffer.writeInteger(command.rawValue)
buffer.writeNullTerminatedString(name)
}
}
}