forked from vapor/postgres-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgresMessage+NotificationResponse.swift
29 lines (26 loc) · 1.28 KB
/
PostgresMessage+NotificationResponse.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 NIOCore
extension PostgresMessage {
/// Identifies the message as a notification response.
public struct NotificationResponse {
public var backendPID: Int32
public var channel: String
public var payload: String
}
}
@available(*, deprecated, message: "Deprecating conformance to `PostgresMessageType` since it is deprecated.")
extension PostgresMessage.NotificationResponse: PostgresMessageType {
public static let identifier = PostgresMessage.Identifier.notificationResponse
/// Parses an instance of this message type from a byte buffer.
public static func parse(from buffer: inout ByteBuffer) throws -> Self {
guard let backendPID: Int32 = buffer.readInteger() else {
throw PostgresError.protocol("Invalid NotificationResponse message: unable to read backend PID")
}
guard let channel = buffer.readNullTerminatedString() else {
throw PostgresError.protocol("Invalid NotificationResponse message: unable to read channel")
}
guard let payload = buffer.readNullTerminatedString() else {
throw PostgresError.protocol("Invalid NotificationResponse message: unable to read payload")
}
return .init(backendPID: backendPID, channel: channel, payload: payload)
}
}