forked from vapor/postgres-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadyForQuery.swift
31 lines (27 loc) · 988 Bytes
/
ReadyForQuery.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 PostgresBackendMessage {
enum TransactionState: UInt8, PayloadDecodable, Hashable {
case idle = 73 // ascii: I
case inTransaction = 84 // ascii: T
case inFailedTransaction = 69 // ascii: E
static func decode(from buffer: inout ByteBuffer) throws -> Self {
let value = try buffer.throwingReadInteger(as: UInt8.self)
guard let state = Self.init(rawValue: value) else {
throw PSQLPartialDecodingError.valueNotRawRepresentable(value: value, asType: TransactionState.self)
}
return state
}
}
}
extension PostgresBackendMessage.TransactionState: CustomDebugStringConvertible {
var debugDescription: String {
switch self {
case .idle:
return ".idle"
case .inTransaction:
return ".inTransaction"
case .inFailedTransaction:
return ".inFailedTransaction"
}
}
}