func (p *Pubrel) Type() Type {
	return PUBREL
}
Type returns the packets type.
package packet
import (
	"fmt"
)
func identifiedLen() int {
	return headerLen(2) + 2
}
func identifiedDecode(src []byte, id *ID, t Type) (int, error) {
	total, _, rl, err := decodeHeader(src, t)
	if err != nil {
		return total, err
	}
	if rl != 2 {
		return total, makeError(t, "expected remaining length to be 2")
	}
	pid, n, err := readUint(src[total:], 2, t)
	total += n
	if err != nil {
		return total, err
	}
	packetID := ID(pid)
	if !packetID.Valid() {
		return total, makeError(t, "packet id must be grater than zero")
	}
	*id = packetID
	return total, nil
}
func identifiedEncode(dst []byte, id ID, t Type) (int, error) {
	if !id.Valid() {
		return 0, makeError(t, "packet id must be grater than zero")
	}
	total, err := encodeHeader(dst, 0, 2, identifiedLen(), t)
	if err != nil {
		return total, err
	}
	n, err := writeUint(dst[total:], uint64(id), 2, t)
	total += n
	if err != nil {
		return total, err
	}
	return total, nil
}
type Puback struct {
	ID ID
}
func NewPuback() *Puback {
	return &Puback{}
}
func (p *Puback) Type() Type {
	return PUBACK
}
func (p *Puback) Len() int {
	return identifiedLen()
}
func (p *Puback) Decode(src []byte) (int, error) {
	return identifiedDecode(src, &p.ID, PUBACK)
}
func (p *Puback) Encode(dst []byte) (int, error) {
	return identifiedEncode(dst, p.ID, PUBACK)
}
func (p *Puback) String() string {
	return fmt.Sprintf("<Puback ID=%d>", p.ID)
}
type Pubcomp struct {
	ID ID
}
func NewPubcomp() *Pubcomp {
	return &Pubcomp{}
}
func (p *Pubcomp) Type() Type {
	return PUBCOMP
}
func (p *Pubcomp) Len() int {
	return identifiedLen()
}
func (p *Pubcomp) Decode(src []byte) (int, error) {
	return identifiedDecode(src, &p.ID, PUBCOMP)
}
func (p *Pubcomp) Encode(dst []byte) (int, error) {
	return identifiedEncode(dst, p.ID, PUBCOMP)
}
func (p *Pubcomp) String() string {
	return fmt.Sprintf("<Pubcomp ID=%d>", p.ID)
}
type Pubrec struct {
	ID ID
}
func NewPubrec() *Pubrec {
	return &Pubrec{}
}
func (p *Pubrec) Type() Type {
	return PUBREC
}
func (p *Pubrec) Len() int {
	return identifiedLen()
}
func (p *Pubrec) Decode(src []byte) (int, error) {
	return identifiedDecode(src, &p.ID, PUBREC)
}
func (p *Pubrec) Encode(dst []byte) (int, error) {
	return identifiedEncode(dst, p.ID, PUBREC)
}
func (p *Pubrec) String() string {
	return fmt.Sprintf("<Pubrec ID=%d>", p.ID)
}
type Pubrel struct {
	ID ID
}
func NewPubrel() *Pubrel {
	return &Pubrel{}
}