package pgproto3

import (
	
	
)

type CopyFail struct {
	Message string
}

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

// 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 ( *CopyFail) ( []byte) error {
	if len() == 0 {
		return &invalidMessageFormatErr{messageType: "CopyFail"}
	}

	 := bytes.IndexByte(, 0)
	if  != len()-1 {
		return &invalidMessageFormatErr{messageType: "CopyFail"}
	}

	.Message = string([:])

	return nil
}

// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
func ( *CopyFail) ( []byte) ([]byte, error) {
	,  := beginMessage(, 'f')
	 = append(, .Message...)
	 = append(, 0)
	return finishMessage(, )
}

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