package msgpack

import (
	
	

	
)

var sliceStringPtrType = reflect.TypeOf((*[]string)(nil))

// DecodeArrayLen decodes array length. Length is -1 when array is nil.
func ( *Decoder) () (int, error) {
	,  := .readCode()
	if  != nil {
		return 0, 
	}
	return .arrayLen()
}

func ( *Decoder) ( byte) (int, error) {
	if  == msgpcode.Nil {
		return -1, nil
	} else if  >= msgpcode.FixedArrayLow &&  <= msgpcode.FixedArrayHigh {
		return int( & msgpcode.FixedArrayMask), nil
	}
	switch  {
	case msgpcode.Array16:
		,  := .uint16()
		return int(), 
	case msgpcode.Array32:
		,  := .uint32()
		return int(), 
	}
	return 0, fmt.Errorf("msgpack: invalid code=%x decoding array length", )
}

func ( *Decoder,  reflect.Value) error {
	 := .Addr().Convert(sliceStringPtrType).Interface().(*[]string)
	return .decodeStringSlicePtr()
}

func ( *Decoder) ( *[]string) error {
	,  := .DecodeArrayLen()
	if  != nil {
		return 
	}
	if  == -1 {
		return nil
	}

	 := makeStrings(*, )
	for  := 0;  < ; ++ {
		,  := .DecodeString()
		if  != nil {
			return 
		}
		 = append(, )
	}
	* = 

	return nil
}

func ( []string,  int) []string {
	if  > sliceAllocLimit {
		 = sliceAllocLimit
	}

	if  == nil {
		return make([]string, 0, )
	}

	if cap() >=  {
		return [:0]
	}

	 = [:cap()]
	 = append(, make([]string, -len())...)
	return [:0]
}

func ( *Decoder,  reflect.Value) error {
	,  := .DecodeArrayLen()
	if  != nil {
		return 
	}

	if  == -1 {
		.Set(reflect.Zero(.Type()))
		return nil
	}
	if  == 0 && .IsNil() {
		.Set(reflect.MakeSlice(.Type(), 0, 0))
		return nil
	}

	if .Cap() >=  {
		.Set(.Slice(0, ))
	} else if .Len() < .Cap() {
		.Set(.Slice(0, .Cap()))
	}

	for  := 0;  < ; ++ {
		if  >= .Len() {
			.Set(growSliceValue(, ))
		}
		 := .Index()
		if  := .DecodeValue();  != nil {
			return 
		}
	}

	return nil
}

func ( reflect.Value,  int) reflect.Value {
	 :=  - .Len()
	if  > sliceAllocLimit {
		 = sliceAllocLimit
	}
	 = reflect.AppendSlice(, reflect.MakeSlice(.Type(), , ))
	return 
}

func ( *Decoder,  reflect.Value) error {
	,  := .DecodeArrayLen()
	if  != nil {
		return 
	}

	if  == -1 {
		return nil
	}
	if  > .Len() {
		return fmt.Errorf("%s len is %d, but msgpack has %d elements", .Type(), .Len(), )
	}

	for  := 0;  < ; ++ {
		 := .Index()
		if  := .DecodeValue();  != nil {
			return 
		}
	}

	return nil
}

func ( *Decoder) () ([]interface{}, error) {
	,  := .readCode()
	if  != nil {
		return nil, 
	}
	return .decodeSlice()
}

func ( *Decoder) ( byte) ([]interface{}, error) {
	,  := .arrayLen()
	if  != nil {
		return nil, 
	}
	if  == -1 {
		return nil, nil
	}

	 := make([]interface{}, 0, min(, sliceAllocLimit))
	for  := 0;  < ; ++ {
		,  := .decodeInterfaceCond()
		if  != nil {
			return nil, 
		}
		 = append(, )
	}

	return , nil
}

func ( *Decoder) ( byte) error {
	,  := .arrayLen()
	if  != nil {
		return 
	}

	for  := 0;  < ; ++ {
		if  := .Skip();  != nil {
			return 
		}
	}

	return nil
}