package decoder

import (
	
	

	
)

type floatDecoder struct {
	op         func(unsafe.Pointer, float64)
	structName string
	fieldName  string
}

func newFloatDecoder(,  string,  func(unsafe.Pointer, float64)) *floatDecoder {
	return &floatDecoder{op: , structName: , fieldName: }
}

var (
	floatTable = [256]bool{
		'0': true,
		'1': true,
		'2': true,
		'3': true,
		'4': true,
		'5': true,
		'6': true,
		'7': true,
		'8': true,
		'9': true,
		'.': true,
		'e': true,
		'E': true,
		'+': true,
		'-': true,
	}

	validEndNumberChar = [256]bool{
		nul:  true,
		' ':  true,
		'\t': true,
		'\r': true,
		'\n': true,
		',':  true,
		':':  true,
		'}':  true,
		']':  true,
	}
)

func floatBytes( *Stream) []byte {
	 := .cursor
	for {
		.cursor++
		if floatTable[.char()] {
			continue
		} else if .char() == nul {
			if .read() {
				.cursor-- // for retry current character
				continue
			}
		}
		break
	}
	return .buf[:.cursor]
}

func ( *floatDecoder) ( *Stream) ([]byte, error) {
	for {
		switch .char() {
		case ' ', '\n', '\t', '\r':
			.cursor++
			continue
		case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
			return floatBytes(), nil
		case 'n':
			if  := nullBytes();  != nil {
				return nil, 
			}
			return nil, nil
		case nul:
			if .read() {
				continue
			}
			goto 
		default:
			goto 
		}
	}
:
	return nil, errors.ErrUnexpectedEndOfJSON("float", .totalOffset())
}

func ( *floatDecoder) ( []byte,  int64) ([]byte, int64, error) {
	for {
		switch [] {
		case ' ', '\n', '\t', '\r':
			++
			continue
		case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
			 := 
			++
			for floatTable[[]] {
				++
			}
			 := [:]
			return , , nil
		case 'n':
			if  := validateNull(, );  != nil {
				return nil, 0, 
			}
			 += 4
			return nil, , nil
		default:
			return nil, 0, errors.ErrUnexpectedEndOfJSON("float", )
		}
	}
}

func ( *floatDecoder) ( *Stream,  int64,  unsafe.Pointer) error {
	,  := .decodeStreamByte()
	if  != nil {
		return 
	}
	if  == nil {
		return nil
	}
	 := *(*string)(unsafe.Pointer(&))
	,  := strconv.ParseFloat(, 64)
	if  != nil {
		return errors.ErrSyntax(.Error(), .totalOffset())
	}
	.op(, )
	return nil
}

func ( *floatDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	 := .Buf
	, ,  := .decodeByte(, )
	if  != nil {
		return 0, 
	}
	if  == nil {
		return , nil
	}
	 = 
	if !validEndNumberChar[[]] {
		return 0, errors.ErrUnexpectedEndOfJSON("float", )
	}
	 := *(*string)(unsafe.Pointer(&))
	,  := strconv.ParseFloat(, 64)
	if  != nil {
		return 0, errors.ErrSyntax(.Error(), )
	}
	.op(, )
	return , nil
}

func ( *floatDecoder) ( *RuntimeContext, ,  int64) ([][]byte, int64, error) {
	 := .Buf
	, ,  := .decodeByte(, )
	if  != nil {
		return nil, 0, 
	}
	if  == nil {
		return [][]byte{nullbytes}, , nil
	}
	return [][]byte{}, , nil
}