func (h *Header) Validate(length uint32) error {
    t := h.Type()
    if t == MsgTypeInvaild {
        return ErrBadMsgType
    } else if _, err := h.Qos(); err != nil {
        return err
    }
    switch t { // TODO better validation
    case MsgTypePublish:
        if length > PublishMaxLen {
            return ErrTooLong
        }
    default:
        if length > DefaultMaxLen {
            return ErrTooLong
        }
    }
    return nil
}
// Validate header and the length of the message
Validate header and the length of the message
// Validate header and the length of the message
func (h *Header) Validate(length uint32) error {
    t := h.Type()
    if t == MsgTypeInvaild {
        return ErrBadMsgType
    } else if _, err := h.Qos(); err != nil {
        return err
    }
    switch t { 
    case MsgTypePublish:
        if length > PublishMaxLen {
            return ErrTooLong
        }
    default:
        if length > DefaultMaxLen {
            return ErrTooLong
        }
    }
    return nil
}
func ( h * Header ) Validate ( length uint32 ) error { t := h . Type ( ) if t == MsgTypeInvaild { return ErrBadMsgType } else if _ , err := h . Qos ( ) ; err != nil { return err } switch t { case MsgTypePublish : if length > PublishMaxLen { return ErrTooLong } default : if length > DefaultMaxLen { return ErrTooLong } } return nil }
Validate header and the length of the message
Validate header and the length of the message
// TODO better validation