package pgproto3

import (
	
	

	
)

type CommandComplete struct {
	CommandTag []byte
}

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

// 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 ( *CommandComplete) ( []byte) error {
	 := bytes.IndexByte(, 0)
	if  == -1 {
		return &invalidMessageFormatErr{messageType: "CommandComplete", details: "unterminated string"}
	}
	if  != len()-1 {
		return &invalidMessageFormatErr{messageType: "CommandComplete", details: "string terminated too early"}
	}

	.CommandTag = [:]

	return nil
}

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

	 = append(, .CommandTag...)
	 = append(, 0)

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

	return 
}

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

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

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

	.CommandTag = []byte(.)
	return nil
}