@@ -36,35 +36,35 @@ enum BackendMessage {
3636 case commandComplete( CommandComplete )
3737 case error( Error )
3838
39- init ( from stream: StreamReader ) throws {
40- let rawType = try stream. read ( UInt8 . self)
39+ static func decode ( from stream: StreamReader ) async throws -> Self {
40+ let rawType = try await stream. read ( UInt8 . self)
4141 guard let messageType = RawType ( rawValue: rawType) else {
4242 fatalError ( " unknown message type: \( rawType) " )
4343 }
44- self = try stream. withSubStreamReader (
44+ return try await stream. withSubStreamReader (
4545 sizedBy: Int32 . self,
4646 includingHeader: true )
4747 { stream in
4848 switch messageType {
4949 case . authentication:
50- return . authentication( try . init ( from: stream) )
50+ return . authentication( try await . decode ( from: stream) )
5151 case . parameterStatus:
52- return . parameterStatus( try . init ( from: stream) )
52+ return . parameterStatus( try await . decode ( from: stream) )
5353 case . backendKeyData:
54- return . backendKeyData( try . init ( from: stream) )
54+ return . backendKeyData( try await . decode ( from: stream) )
5555 case . readyForQuery:
56- return . readyForQuery( try . init ( from: stream) )
56+ return . readyForQuery( try await . decode ( from: stream) )
5757 case . rowDescription:
58- return . rowDescription( try . init ( from: stream) )
58+ return . rowDescription( try await . decode ( from: stream) )
5959 case . dataRow:
60- return . dataRow( try . init ( from: stream) )
60+ return . dataRow( try await . decode ( from: stream) )
6161 case . commandComplete:
62- return . commandComplete( try . init ( from: stream) )
62+ return . commandComplete( try await . decode ( from: stream) )
6363 case . errorResponse:
64- return . error( try . init ( from: stream) )
64+ return . error( try await . decode ( from: stream) )
6565 default :
6666 print ( " type: \( rawType) size: \( stream. limit) " )
67- print ( try stream. readUntilEnd ( ) )
67+ print ( try await stream. readUntilEnd ( ) )
6868 fatalError ( )
6969 }
7070 }
0 commit comments