package pgproto3

import (
	
	
	
	

	
)

type CopyInResponse struct {
	OverallFormat     byte
	ColumnFormatCodes []uint16
}

// Backend identifies this message as sendable by the PostgreSQL backend.
func (*CopyInResponse) () {}

// 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 ( *CopyInResponse) ( []byte) error {
	 := bytes.NewBuffer()

	if .Len() < 3 {
		return &invalidMessageFormatErr{messageType: "CopyInResponse"}
	}

	 := .Next(1)[0]

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

	 := make([]uint16, )
	for  := 0;  < ; ++ {
		[] = binary.BigEndian.Uint16(.Next(2))
	}

	* = CopyInResponse{OverallFormat: , ColumnFormatCodes: }

	return nil
}

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

	 = append(, .OverallFormat)
	 = pgio.AppendUint16(, uint16(len(.ColumnFormatCodes)))
	for ,  := range .ColumnFormatCodes {
		 = pgio.AppendUint16(, )
	}

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

	return 
}

// MarshalJSON implements encoding/json.Marshaler.
func ( CopyInResponse) () ([]byte, error) {
	return json.Marshal(struct {
		              string
		 []uint16
	}{
		:              "CopyInResponse",
		: .ColumnFormatCodes,
	})
}

// UnmarshalJSON implements encoding/json.Unmarshaler.
func ( *CopyInResponse) ( []byte) error {
	// Ignore null, like in the main JSON package.
	if string() == "null" {
		return nil
	}

	var  struct {
		     string
		 []uint16
	}
	if  := json.Unmarshal(, &);  != nil {
		return 
	}

	if len(.) != 1 {
		return errors.New("invalid length for CopyInResponse.OverallFormat")
	}

	.OverallFormat = .[0]
	.ColumnFormatCodes = .
	return nil
}