package pgproto3

import (
	
	
	

	
)

type Parse struct {
	Name          string
	Query         string
	ParameterOIDs []uint32
}

// Frontend identifies this message as sendable by a PostgreSQL frontend.
func (*Parse) () {}

// Decode decodes src into dst. src must contain the complete message with the exception of the initial 1 byte message
// type identifier and 4 byte message length.
func ( *Parse) ( []byte) error {
	* = Parse{}

	 := bytes.NewBuffer()

	,  := .ReadBytes(0)
	if  != nil {
		return 
	}
	.Name = string([:len()-1])

	,  = .ReadBytes(0)
	if  != nil {
		return 
	}
	.Query = string([:len()-1])

	if .Len() < 2 {
		return &invalidMessageFormatErr{messageType: "Parse"}
	}
	 := int(binary.BigEndian.Uint16(.Next(2)))

	for  := 0;  < ; ++ {
		if .Len() < 4 {
			return &invalidMessageFormatErr{messageType: "Parse"}
		}
		.ParameterOIDs = append(.ParameterOIDs, binary.BigEndian.Uint32(.Next(4)))
	}

	return nil
}

// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
func ( *Parse) ( []byte) []byte {
	 = append(, 'P')
	 := len()
	 = pgio.AppendInt32(, -1)

	 = append(, .Name...)
	 = append(, 0)
	 = append(, .Query...)
	 = append(, 0)

	 = pgio.AppendUint16(, uint16(len(.ParameterOIDs)))
	for ,  := range .ParameterOIDs {
		 = pgio.AppendUint32(, )
	}

	pgio.SetInt32([:], int32(len([:])))

	return 
}

// MarshalJSON implements encoding/json.Marshaler.
func ( Parse) () ([]byte, error) {
	return json.Marshal(struct {
		          string
		          string
		         string
		 []uint32
	}{
		:          "Parse",
		:          .Name,
		:         .Query,
		: .ParameterOIDs,
	})
}