forked from vapor/postgres-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgresMessage+Parse.swift
31 lines (26 loc) · 1.4 KB
/
PostgresMessage+Parse.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
import NIOCore
extension PostgresMessage {
/// Identifies the message as a Parse command.
@available(*, deprecated, message: "Will be removed from public API")
public struct Parse: PostgresMessageType {
public static var identifier: PostgresMessage.Identifier {
return .parse
}
/// The name of the destination prepared statement (an empty string selects the unnamed prepared statement).
public var statementName: String
/// The query string to be parsed.
public var query: String
/// The number of parameter data types specified (can be zero).
/// Note that this is not an indication of the number of parameters that might appear in the
/// query string, only the number that the frontend wants to prespecify types for.
/// Specifies the object ID of the parameter data type. Placing a zero here is equivalent to leaving the type unspecified.
public var parameterTypes: [PostgresDataType]
/// Serializes this message into a byte buffer.
public func serialize(into buffer: inout ByteBuffer) {
buffer.writeString(statementName + "\0")
buffer.writeString(query + "\0")
buffer.writeInteger(numericCast(self.parameterTypes.count), as: Int16.self)
self.parameterTypes.forEach { buffer.writeInteger($0.rawValue) }
}
}
}