Skip to content

Commit 7331b52

Browse files
fabianfettgwynne
andauthored
Add conveniences to PSQLFrontendMessage (#173)
### Motivation We want to use the `NIOSingleStepByteToMessageDecoder` within the `PSQLChannelHandler` in the future. For this reason it is important that we will be able to decode PSQLFrontendMessages for tests in the future. ### Changes - Rename protocol `PSQLFrontendMessagePayloadEncodable` to `PSQLMessagePayloadEncodable` - `PSQLFrontendMessage.ID` is now `RawRepresentable` ### Result Code that makes testing easier in the future. Co-authored-by: Gwynne Raskind <[email protected]>
1 parent 7acca81 commit 7331b52

21 files changed

+73
-45
lines changed

Sources/PostgresNIO/New/Extensions/ByteBuffer+PSQL.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal extension ByteBuffer {
2020
}
2121

2222
mutating func writeFrontendMessageID(_ messageID: PSQLFrontendMessage.ID) {
23-
self.writeInteger(messageID.byte)
23+
self.writeInteger(messageID.rawValue)
2424
}
2525

2626
mutating func readFloat() -> Float? {

Sources/PostgresNIO/New/Messages/Cancel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import NIOCore
22

33
extension PSQLFrontendMessage {
44

5-
struct Cancel: PayloadEncodable, Equatable {
5+
struct Cancel: PSQLMessagePayloadEncodable, Equatable {
66
/// The cancel request code. The value is chosen to contain 1234 in the most significant 16 bits,
77
/// and 5678 in the least significant 16 bits. (To avoid confusion, this code must not be the same
88
/// as any protocol version number.)

Sources/PostgresNIO/New/Messages/Close.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import NIOCore
22

33
extension PSQLFrontendMessage {
44

5-
enum Close: PayloadEncodable, Equatable {
5+
enum Close: PSQLMessagePayloadEncodable, Equatable {
66
case preparedStatement(String)
77
case portal(String)
88

Sources/PostgresNIO/New/Messages/Describe.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import NIOCore
22

33
extension PSQLFrontendMessage {
44

5-
enum Describe: PayloadEncodable, Equatable {
5+
enum Describe: PSQLMessagePayloadEncodable, Equatable {
66

77
case preparedStatement(String)
88
case portal(String)

Sources/PostgresNIO/New/Messages/Execute.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import NIOCore
22

33
extension PSQLFrontendMessage {
44

5-
struct Execute: PayloadEncodable, Equatable {
5+
struct Execute: PSQLMessagePayloadEncodable, Equatable {
66
/// The name of the portal to execute (an empty string selects the unnamed portal).
77
let portalName: String
88

Sources/PostgresNIO/New/Messages/Parse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import NIOCore
22

33
extension PSQLFrontendMessage {
44

5-
struct Parse: PayloadEncodable, Equatable {
5+
struct Parse: PSQLMessagePayloadEncodable, Equatable {
66
/// The name of the destination prepared statement (an empty string selects the unnamed prepared statement).
77
let preparedStatementName: String
88

Sources/PostgresNIO/New/Messages/Password.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import NIOCore
22

33
extension PSQLFrontendMessage {
44

5-
struct Password: PayloadEncodable, Equatable {
5+
struct Password: PSQLMessagePayloadEncodable, Equatable {
66
let value: String
77

88
func encode(into buffer: inout ByteBuffer) {

Sources/PostgresNIO/New/Messages/SASLInitialResponse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import NIOCore
22

33
extension PSQLFrontendMessage {
44

5-
struct SASLInitialResponse: PayloadEncodable, Equatable {
5+
struct SASLInitialResponse: PSQLMessagePayloadEncodable, Equatable {
66

77
let saslMechanism: String
88
let initialData: [UInt8]

Sources/PostgresNIO/New/Messages/SASLResponse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import NIOCore
22

33
extension PSQLFrontendMessage {
44

5-
struct SASLResponse: PayloadEncodable, Equatable {
5+
struct SASLResponse: PSQLMessagePayloadEncodable, Equatable {
66

77
let data: [UInt8]
88

Sources/PostgresNIO/New/Messages/SSLRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import NIOCore
33
extension PSQLFrontendMessage {
44
/// A message asking the PostgreSQL server if TLS is supported
55
/// For more info, see https://www.postgresql.org/docs/10/static/protocol-flow.html#id-1.10.5.7.11
6-
struct SSLRequest: PayloadEncodable, Equatable {
6+
struct SSLRequest: PSQLMessagePayloadEncodable, Equatable {
77
/// The SSL request code. The value is chosen to contain 1234 in the most significant 16 bits,
88
/// and 5679 in the least significant 16 bits.
99
let code: Int32

0 commit comments

Comments
 (0)