func (fh *FixedHeader) ReadBuffer(buf []byte) (int, error) {

	if len(buf) < 2 {
		return 0, errIncompleteHeader
	}

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

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

	buf = buf[1:]
	n := 1

	var multiplier = 1
	var length int

	if buf[0] == 0 {
		fh.Length = 0
		return 2, nil
	}

	for {
		n++
		length += int(buf[0]&127) * multiplier

		if buf[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) ReadBuffer(buf []byte) (int, error) {
	if len(buf) < 2 {
		return 0, errIncompleteHeader
	}
	fh.PacketType = PacketType(buf[0] >> 4)
	fh.Dup = bool(buf[0]&0x8 != 0)
	fh.QoS = byte((buf[0] & 0x6) >> 1)
	fh.Retain = bool(buf[0]&0x1 != 0)
	if fh.PacketType == 0 || fh.PacketType == 15 {
		return 0, errReservedPacketType
	}
	buf = buf[1:]
	n := 1
	var multiplier = 1
	var length int
	if buf[0] == 0 {
		fh.Length = 0
		return 2, nil
	}
	for {
		n++
		length += int(buf[0]&127) * multiplier
		if buf[0]&128 == 0 {
			break
		}
		if multiplier > 0x4000 {
			return n, errMessageLengthInvalid
		}
		multiplier *= 128
	}
	fh.Length = length
	return n, nil
}
func ( fh * FixedHeader ) ReadBuffer ( buf [ ] byte ) ( int , error ) { if len ( buf ) < 2 { return 0 , errIncompleteHeader } fh . PacketType = PacketType ( buf [ 0 ] >> 4 ) fh . Dup = bool ( buf [ 0 ] & 0x8 != 0 ) fh . QoS = byte ( ( buf [ 0 ] & 0x6 ) >> 1 ) fh . Retain = bool ( buf [ 0 ] & 0x1 != 0 ) if fh . PacketType == 0 || fh . PacketType == 15 { return 0 , errReservedPacketType } buf = buf [ 1 : ] n := 1 var multiplier = 1 var length int if buf [ 0 ] == 0 { fh . Length = 0 return 2 , nil } for { n ++ length += int ( buf [ 0 ] & 127 ) * multiplier if buf [ 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 .