func (fh *FixedHeader) Read(reader io.Reader) (int, error) {

	var headBuf [1]byte
	n, err := reader.Read(headBuf[:])
	if n == 0 {
		return 0, err
	}

	fh.PacketType = PacketType(headBuf[0] >> 4)
	fh.Dup = bool(headBuf[0]&0x8 != 0)
	fh.QoS = byte((headBuf[0] & 0x6) >> 1)
	fh.Retain = bool(headBuf[0]&0x1 != 0)

	if fh.PacketType == 0 || fh.PacketType == 15 {
		return 1, errReservedPacketType
	}

	var multiplier = 1
	var length int
	var d int

	for {
		d, err = reader.Read(headBuf[:])
		if d == 0 {
			return n, err
		}
		n++

		length += int(headBuf[0]&127) * multiplier

		// if length > MaxMessageLength {
		// 	return n, errMessageLengthExceeded
		// }

		if headBuf[0]&128 == 0 {
			break
		}

		if multiplier > 0x4000 {
			return n, errMessageLengthInvalid
		}

		multiplier *= 128
	}

	fh.Length = length
	return n, nil
}
// Read reads a FixedHeader from an io.Reader.
Read reads a FixedHeader from an io.Reader.
// Read reads a FixedHeader from an io . Reader .
func (fh *FixedHeader) Read(reader io.Reader) (int, error) {
	var headBuf [1]byte
	n, err := reader.Read(headBuf[:])
	if n == 0 {
		return 0, err
	}
	fh.PacketType = PacketType(headBuf[0] >> 4)
	fh.Dup = bool(headBuf[0]&0x8 != 0)
	fh.QoS = byte((headBuf[0] & 0x6) >> 1)
	fh.Retain = bool(headBuf[0]&0x1 != 0)
	if fh.PacketType == 0 || fh.PacketType == 15 {
		return 1, errReservedPacketType
	}
	var multiplier = 1
	var length int
	var d int
	for {
		d, err = reader.Read(headBuf[:])
		if d == 0 {
			return n, err
		}
		n++
		length += int(headBuf[0]&127) * multiplier
		if headBuf[0]&128 == 0 {
			break
		}
		if multiplier > 0x4000 {
			return n, errMessageLengthInvalid
		}
		multiplier *= 128
	}
	fh.Length = length
	return n, nil
}
func ( fh * FixedHeader ) Read ( reader io . Reader ) ( int , error ) { var headBuf [ 1 ] byte n , err := reader . Read ( headBuf [ : ] ) if n == 0 { return 0 , err } fh . PacketType = PacketType ( headBuf [ 0 ] >> 4 ) fh . Dup = bool ( headBuf [ 0 ] & 0x8 != 0 ) fh . QoS = byte ( ( headBuf [ 0 ] & 0x6 ) >> 1 ) fh . Retain = bool ( headBuf [ 0 ] & 0x1 != 0 ) if fh . PacketType == 0 || fh . PacketType == 15 { return 1 , errReservedPacketType } var multiplier = 1 var length int var d int for { d , err = reader . Read ( headBuf [ : ] ) if d == 0 { return n , err } n ++ length += int ( headBuf [ 0 ] & 127 ) * multiplier if headBuf [ 0 ] & 128 == 0 { break } if multiplier > 0x4000 { return n , errMessageLengthInvalid } multiplier *= 128 } fh . Length = length return n , nil }
Read reads a FixedHeader from an io.Reader.
Read reads a FixedHeader from an io . Reader .
// if length > MaxMessageLength { // 	return n, errMessageLengthExceeded // }