package decoder

import (
	
	
	
	

	
	
)

type unmarshalTextDecoder struct {
	typ reflect.Type
}

func newUnmarshalTextDecoder( reflect.Type) *unmarshalTextDecoder {
	return &unmarshalTextDecoder{typ: }
}

var (
	nullbytes = []byte(`null`)
)

func ( *unmarshalTextDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	, ,  := .decodeText(, , , )
	if  != nil {
		.methodError()
	}
	return , 
}

// decodeText decodes the value at cursor into p, and returns the position after it, and the error of UnmarshalText
// apart from the one of the decoding.
func ( *unmarshalTextDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error, error) {
	 := .Buf
	 = skipWhiteSpace(, )
	 := 
	,  := skipValue(, , )
	if  != nil {
		return 0, nil, 
	}
	 := [:]
	switch  := [0]; {
	case  == 'n':
		// null leaves the value as it is, and is not given to UnmarshalText
		return , nil, nil
	case  != '"':
		// a value of another kind than a string, which is a type error
		,  := .textUnmarshalerKindError(, , .typ)
		return , nil, 
	}

	// a string, which skipValue found valid, which ends at its length: a method which appends to it doesn't write into
	// the input after it
	 = jsonstring.UnquoteValid()
	 = [:len():len()]
	 := *(*any)(unsafe.Pointer(&emptyInterface{
		typ: runtime.TypePtr(.typ),
		ptr: *(*unsafe.Pointer)(unsafe.Pointer(&)),
	}))
	return , .(encoding.TextUnmarshaler).UnmarshalText(), nil
}

// textKeyDecoder is the decoder of the keys of a map whose type implements encoding.TextUnmarshaler by its pointer
// type: the entry of a key which UnmarshalText fails for is dropped, as the one of a key of another type is ( see
// errMapKeyType ), and the error of the method is recorded as the one of a value.
type textKeyDecoder struct {
	unmarshalTextDecoder
}

func ( *textKeyDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	, ,  := .decodeText(, , , )
	if  != nil {
		.methodError()
		return , errMapKeyType
	}
	return , 
}

func ( *unmarshalTextDecoder) ( *RuntimeContext, ,  int64) ([][]byte, int64, error) {
	return nil, 0, fmt.Errorf("json: unmarshal text decoder does not support decode path")
}