func (c *Connection) read() (bool, []byte, error) {
	var header [2]byte
	var longLength [8]byte

	// Read out the header
	_, err := io.ReadFull(c.rw, header[:])
	if err != nil {
		return false, nil, err
	}

	bitFlags := header[0]

	// Read all the flags
	hasMore := bitFlags&hasMoreBitFlag == hasMoreBitFlag
	isLong := bitFlags&isLongBitFlag == isLongBitFlag
	isCommand := bitFlags&isCommandBitFlag == isCommandBitFlag

	// Error out in case get a more flag set to true
	if hasMore {
		return false, nil, errors.New("Received a packet with the MORE flag set to true, we don't support more")
	}

	// Determine the actual length of the body
	bodyLength := uint64(0)
	if isLong {
		// We read 2 bytes of the header already
		// In case of a long message, the length is bytes 2-8 of the header
		// We already have the first byte, so assign it, and then read the rest
		longLength[0] = header[1]

		_, err := io.ReadFull(c.rw, longLength[1:])
		if err != nil {
			return false, nil, err
		}

		bodyLength = byteOrder.Uint64(longLength[:])
	} else {
		// Short message length is just 1 byte, read it
		bodyLength = uint64(header[1])
	}

	if bodyLength > uint64(maxInt64) {
		return false, nil, fmt.Errorf("Body length %v overflows max int64 value %v", bodyLength, maxInt64)
	}

	buf := make([]byte, bodyLength)
	_, err = io.ReadFull(c.rw, buf)
	if err != nil {
		return false, nil, err
	}
	return isCommand, buf, nil
}
// read returns the isCommand flag, the body of the message, and optionally an error
read returns the isCommand flag, the body of the message, and optionally an error
// read returns the isCommand flag the body of the message and optionally an error
func (c *Connection) read() (bool, []byte, error) {
	var header [2]byte
	var longLength [8]byte
	_, err := io.ReadFull(c.rw, header[:])
	if err != nil {
		return false, nil, err
	}
	bitFlags := header[0]
	hasMore := bitFlags&hasMoreBitFlag == hasMoreBitFlag
	isLong := bitFlags&isLongBitFlag == isLongBitFlag
	isCommand := bitFlags&isCommandBitFlag == isCommandBitFlag
	if hasMore {
		return false, nil, errors.New("Received a packet with the MORE flag set to true, we don't support more")
	}
	bodyLength := uint64(0)
	if isLong {
		longLength[0] = header[1]
		_, err := io.ReadFull(c.rw, longLength[1:])
		if err != nil {
			return false, nil, err
		}
		bodyLength = byteOrder.Uint64(longLength[:])
	} else {
		bodyLength = uint64(header[1])
	}
	if bodyLength > uint64(maxInt64) {
		return false, nil, fmt.Errorf("Body length %v overflows max int64 value %v", bodyLength, maxInt64)
	}
	buf := make([]byte, bodyLength)
	_, err = io.ReadFull(c.rw, buf)
	if err != nil {
		return false, nil, err
	}
	return isCommand, buf, nil
}
func ( c * Connection ) read ( ) ( bool , [ ] byte , error ) { var header [ 2 ] byte var longLength [ 8 ] byte _ , err := io . ReadFull ( c . rw , header [ : ] ) if err != nil { return false , nil , err } bitFlags := header [ 0 ] hasMore := bitFlags & hasMoreBitFlag == hasMoreBitFlag isLong := bitFlags & isLongBitFlag == isLongBitFlag isCommand := bitFlags & isCommandBitFlag == isCommandBitFlag if hasMore { return false , nil , errors . New ( " " ) } bodyLength := uint64 ( 0 ) if isLong { longLength [ 0 ] = header [ 1 ] _ , err := io . ReadFull ( c . rw , longLength [ 1 : ] ) if err != nil { return false , nil , err } bodyLength = byteOrder . Uint64 ( longLength [ : ] ) } else { bodyLength = uint64 ( header [ 1 ] ) } if bodyLength > uint64 ( maxInt64 ) { return false , nil , fmt . Errorf ( " " , bodyLength , maxInt64 ) } buf := make ( [ ] byte , bodyLength ) _ , err = io . ReadFull ( c . rw , buf ) if err != nil { return false , nil , err } return isCommand , buf , nil }
read returns the isCommand flag, the body of the message, and optionally an error
read returns the isCommand flag the body of the message and optionally an error
// Read out the header // Read all the flags // Error out in case get a more flag set to true // Determine the actual length of the body // We read 2 bytes of the header already // In case of a long message, the length is bytes 2-8 of the header // We already have the first byte, so assign it, and then read the rest // Short message length is just 1 byte, read it