package decoder

import (
	
	
	
)

type ptrDecoder struct {
	dec        Decoder
	typ        reflect.Type
	structName string
	fieldName  string
}

// newPtrDecoder returns the decoder of a pointer to typ: a basicPtrDecoder if typ has an allocator of its own
// ( see allocatorOf ), and else a ptrDecoder.
func newPtrDecoder( Decoder,  reflect.Type, ,  string) Decoder {
	 := ptrDecoder{
		dec:        ,
		typ:        ,
		structName: ,
		fieldName:  ,
	}
	if  := allocatorOf();  != nil {
		return &basicPtrDecoder{ptrDecoder: , alloc: }
	}
	return &
}

func ( *ptrDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	 := .Buf
	 = skipWhiteSpace(, )
	if [] == 'n' {
		if  := validateNull(, );  != nil {
			return 0, 
		}
		if  != nil {
			*(*unsafe.Pointer)() = nil
		}
		 += 4
		return , nil
	}
	var  unsafe.Pointer
	if *(*unsafe.Pointer)() == nil {
		 = newValue(.typ)
		*(*unsafe.Pointer)() = 
	} else {
		 = *(*unsafe.Pointer)()
	}
	// after an error, the pointer is left as it is, as encoding/json leaves it; the cursor is the one of the decoder:
	// after a key of a map of another type, the map goes on from it ( see errMapKeyType )
	return .dec.Decode(, , , )
}

// basicPtrDecoder is the decoder of a pointer to a type which has an allocator of its own ( see allocatorOf ),
// which allocates the value a nil pointer is set to. It is a type of its own, so that the decoder of a pointer
// to any other type is the one it was.
type basicPtrDecoder struct {
	ptrDecoder
	alloc func() unsafe.Pointer
}

func ( *basicPtrDecoder) ( *RuntimeContext, ,  int64,  unsafe.Pointer) (int64, error) {
	 := .Buf
	 = skipWhiteSpace(, )
	if [] == 'n' {
		if  := validateNull(, );  != nil {
			return 0, 
		}
		if  != nil {
			*(*unsafe.Pointer)() = nil
		}
		return  + 4, nil
	}
	 := *(*unsafe.Pointer)()
	if  == nil {
		 = .alloc()
		*(*unsafe.Pointer)() = 
	}
	// as ptrDecoder.Decode
	return .dec.Decode(, , , )
}

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