forked from vapor/postgres-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgresMessage+BackendKeyData.swift
29 lines (25 loc) · 1.21 KB
/
PostgresMessage+BackendKeyData.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
import NIO
extension PostgresMessage {
/// Identifies the message as cancellation key data.
/// The frontend must save these values if it wishes to be able to issue CancelRequest messages later.
public struct BackendKeyData: CustomStringConvertible {
/// Parses an instance of this message type from a byte buffer.
public static func parse(from buffer: inout ByteBuffer) throws -> BackendKeyData {
guard let processID = buffer.readInteger(as: Int32.self) else {
throw PostgresError.protocol("Could not parse process id from backend key data")
}
guard let secretKey = buffer.readInteger(as: Int32.self) else {
throw PostgresError.protocol("Could not parse secret key from backend key data")
}
return .init(processID: processID, secretKey: secretKey)
}
/// The process ID of this backend.
public var processID: Int32
/// The secret key of this backend.
public var secretKey: Int32
/// See `CustomStringConvertible`.
public var description: String {
return "processID: \(processID), secretKey: \(secretKey)"
}
}
}