forked from vapor/postgres-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathByteBuffer+PSQL.swift
32 lines (25 loc) · 901 Bytes
/
ByteBuffer+PSQL.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
import NIOCore
internal extension ByteBuffer {
mutating func psqlWriteBackendMessageID(_ messageID: PostgresBackendMessage.ID) {
self.writeInteger(messageID.rawValue)
}
mutating func psqlWriteFrontendMessageID(_ messageID: PostgresFrontendMessage.ID) {
self.writeInteger(messageID.rawValue)
}
@usableFromInline
mutating func psqlReadFloat() -> Float? {
return self.readInteger(as: UInt32.self).map { Float(bitPattern: $0) }
}
@usableFromInline
mutating func psqlReadDouble() -> Double? {
return self.readInteger(as: UInt64.self).map { Double(bitPattern: $0) }
}
@usableFromInline
mutating func psqlWriteFloat(_ float: Float) {
self.writeInteger(float.bitPattern)
}
@usableFromInline
mutating func psqlWriteDouble(_ double: Double) {
self.writeInteger(double.bitPattern)
}
}