package pgproto3

import (
	
	
	
	
)
Frontend acts as a client for the PostgreSQL wire protocol version 3.
type Frontend struct {
	cr ChunkReader
	w  io.Writer
NewFrontend creates a new Frontend.
func ( ChunkReader,  io.Writer) *Frontend {
	return &Frontend{cr: , w: }
}
Send sends a message to the backend.
func ( *Frontend) ( FrontendMessage) error {
	,  := .w.Write(.Encode(nil))
	return 
}

func ( error) error {
	if  == io.EOF {
		return io.ErrUnexpectedEOF
	}
	return 
}
Receive receives a message from the backend. The returned message is only valid until the next call to Receive.
func ( *Frontend) () (BackendMessage, error) {
	if !.partialMsg {
		,  := .cr.Next(5)
		if  != nil {
			return nil, translateEOFtoErrUnexpectedEOF()
		}

		.msgType = [0]
		.bodyLen = int(binary.BigEndian.Uint32([1:])) - 4
		.partialMsg = true
	}

	,  := .cr.Next(.bodyLen)
	if  != nil {
		return nil, translateEOFtoErrUnexpectedEOF()
	}

	.partialMsg = false

	var  BackendMessage
	switch .msgType {
	case '1':
		 = &.parseComplete
	case '2':
		 = &.bindComplete
	case '3':
		 = &.closeComplete
	case 'A':
		 = &.notificationResponse
	case 'c':
		 = &.copyDone
	case 'C':
		 = &.commandComplete
	case 'd':
		 = &.copyData
	case 'D':
		 = &.dataRow
	case 'E':
		 = &.errorResponse
	case 'G':
		 = &.copyInResponse
	case 'H':
		 = &.copyOutResponse
	case 'I':
		 = &.emptyQueryResponse
	case 'K':
		 = &.backendKeyData
	case 'n':
		 = &.noData
	case 'N':
		 = &.noticeResponse
	case 'R':
		var  error
		,  = .findAuthenticationMessageType()
		if  != nil {
			return nil, 
		}
	case 's':
		 = &.portalSuspended
	case 'S':
		 = &.parameterStatus
	case 't':
		 = &.parameterDescription
	case 'T':
		 = &.rowDescription
	case 'V':
		 = &.functionCallResponse
	case 'W':
		 = &.copyBothResponse
	case 'Z':
		 = &.readyForQuery
	default:
		return nil, fmt.Errorf("unknown message type: %c", .msgType)
	}

	 = .Decode()
	return , 
}
Authentication message type constants.
const (
	AuthTypeOk                = 0
	AuthTypeCleartextPassword = 3
	AuthTypeMD5Password       = 5
	AuthTypeSASL              = 10
	AuthTypeSASLContinue      = 11
	AuthTypeSASLFinal         = 12
)

func ( *Frontend) ( []byte) (BackendMessage, error) {
	if len() < 4 {
		return nil, errors.New("authentication message too short")
	}
	 := binary.BigEndian.Uint32([:4])

	switch  {
	case AuthTypeOk:
		return &.authenticationOk, nil
	case AuthTypeCleartextPassword:
		return &.authenticationCleartextPassword, nil
	case AuthTypeMD5Password:
		return &.authenticationMD5Password, nil
	case AuthTypeSASL:
		return &.authenticationSASL, nil
	case AuthTypeSASLContinue:
		return &.authenticationSASLContinue, nil
	case AuthTypeSASLFinal:
		return &.authenticationSASLFinal, nil
	default:
		return nil, fmt.Errorf("unknown authentication type: %d", )
	}