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

		hasMore   = true
		isCommand = false
	)

	for hasMore {
		// 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 = isCommand || (bitFlags&isCommandBitFlag == isCommandBitFlag)

		// 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
		}
		frames = append(frames, buf)
	}

	return isCommand, frames, nil
}
// readMultipart returns the isCommand flag, the body of the message, and optionally an error
readMultipart returns the isCommand flag, the body of the message, and optionally an error
// readMultipart returns the isCommand flag the body of the message and optionally an error
func (c *Connection) readMultipart() (bool, [][]byte, error) {
	var (
		header     [2]byte
		longLength [8]byte
		frames     [][]byte
		hasMore   = true
		isCommand = false
	)
	for hasMore {
		_, 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 = isCommand || (bitFlags&isCommandBitFlag == isCommandBitFlag)
		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
		}
		frames = append(frames, buf)
	}
	return isCommand, frames, nil
}
func ( c * Connection ) readMultipart ( ) ( bool , [ ] [ ] byte , error ) { var ( header [ 2 ] byte longLength [ 8 ] byte frames [ ] [ ] byte hasMore = true isCommand = false ) for hasMore { _ , 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 = isCommand || ( bitFlags & isCommandBitFlag == isCommandBitFlag ) 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 } frames = append ( frames , buf ) } return isCommand , frames , nil }
readMultipart returns the isCommand flag, the body of the message, and optionally an error
readMultipart returns the isCommand flag the body of the message and optionally an error
// Read out the header // Read all the flags // 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