func()

in azkustodata/query/v2/frame_reader.go [57:93]


func (fr *frameReader) advance() ([]byte, error) {
	// Check if the context has been cancelled, so we won't keep reading after the response is cancelled.
	if fr.ctx.Err() != nil {
		return nil, fr.ctx.Err()
	}

	// Read until the end of the current line, which is the entire frame.
	line, err := fr.reader.ReadBytes('\n')
	if err != nil {
		return nil, err
	}

	// If the first character is ']', then we have reached the end of the response.
	if len(line) > 0 && line[0] == ']' {
		return nil, io.EOF
	}

	// Trim newline
	line = line[:len(line)-1]

	if len(line) > 0 && line[len(line)-1] == '\r' {
		line = line[:len(line)-1]
	}

	if len(line) < 2 {
		return nil, errors.ES(errors.OpUnknown, errors.KInternal, "Got EOF while reading frame")
	}

	// We skip the first byte of the line, as it is a comma, or the start of the array.
	if line[0] != '[' && line[0] != ',' {
		return nil, errors.ES(errors.OpUnknown, errors.KInternal, "Expected comma or start array, got '%c'", line[0])
	}

	line = line[1:]

	return line, nil
}