func (t Type) New() (Generic, error) {
	switch t {
	case CONNECT:
		return NewConnect(), nil
	case CONNACK:
		return NewConnack(), nil
	case PUBLISH:
		return NewPublish(), nil
	case PUBACK:
		return NewPuback(), nil
	case PUBREC:
		return NewPubrec(), nil
	case PUBREL:
		return NewPubrel(), nil
	case PUBCOMP:
		return NewPubcomp(), nil
	case SUBSCRIBE:
		return NewSubscribe(), nil
	case SUBACK:
		return NewSuback(), nil
	case UNSUBSCRIBE:
		return NewUnsubscribe(), nil
	case UNSUBACK:
		return NewUnsuback(), nil
	case PINGREQ:
		return NewPingreq(), nil
	case PINGRESP:
		return NewPingresp(), nil
	case DISCONNECT:
		return NewDisconnect(), nil
	}
	return nil, ErrInvalidPacketType
}
New creates a new packet based on the type. It is a shortcut to call one of
the New*Packet functions. An error is returned if the type is invalid.
package packet
import "errors"
var ErrInvalidPacketType = errors.New("invalid packet type")
type Type byte
const (
	_ Type = iota
	CONNECT
	CONNACK
	PUBLISH
	PUBACK
	PUBREC
	PUBREL
	PUBCOMP
	SUBSCRIBE
	SUBACK
	UNSUBSCRIBE
	UNSUBACK
	PINGREQ
	PINGRESP
	DISCONNECT
)
func Types() []Type {
	return []Type{CONNECT, CONNACK, PUBLISH, PUBACK, PUBREC, PUBREL, PUBCOMP,
		SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK, PINGREQ, PINGRESP, DISCONNECT}
}
func (t Type) String() string {
	switch t {
	case CONNECT:
		return "Connect"
	case CONNACK:
		return "Connack"
	case PUBLISH:
		return "Publish"
	case PUBACK:
		return "Puback"
	case PUBREC:
		return "Pubrec"
	case PUBREL:
		return "Pubrel"
	case PUBCOMP:
		return "Pubcomp"
	case SUBSCRIBE:
		return "Subscribe"
	case SUBACK:
		return "Suback"
	case UNSUBSCRIBE:
		return "Unsubscribe"
	case UNSUBACK:
		return "Unsuback"
	case PINGREQ:
		return "Pingreq"
	case PINGRESP:
		return "Pingresp"
	case DISCONNECT:
		return "Disconnect"
	}
	return "Unknown"
}
func (t Type) defaultFlags() byte {
	switch t {
	case CONNECT:
		return 0
	case CONNACK:
		return 0
	case PUBACK:
		return 0
	case PUBREC:
		return 0
	case PUBREL:
		return 2  
	case PUBCOMP:
		return 0
	case SUBSCRIBE:
		return 2  
	case SUBACK:
		return 0
	case UNSUBSCRIBE:
		return 2  
	case UNSUBACK:
		return 0
	case PINGREQ:
		return 0
	case PINGRESP:
		return 0
	case DISCONNECT:
		return 0
	}
	return 0
}