MCPcopy Create free account
hub / github.com/Restream/reindexer / decodeSlice

Method decodeSlice

cjson/decoder.go:343–601  ·  view source on GitHub ↗
(pl *payloadIface, rdser *Serializer, v *reflect.Value, fieldsoutcnt []int, cctagsPath []int16)

Source from the content-addressed store, hash-verified

341}
342
343func (dec *Decoder) decodeSlice(pl *payloadIface, rdser *Serializer, v *reflect.Value, fieldsoutcnt []int, cctagsPath []int16) {
344 atag := rdser.GetCArrayTag()
345 count := atag.Count()
346 subtag := atag.Tag()
347
348 var origV reflect.Value
349 var ptr unsafe.Pointer
350
351 k := v.Kind()
352
353 offset := 0
354 var sliceV reflect.Value
355 switch k {
356 case reflect.Slice:
357 offset = mkSlice(v, count)
358 sliceV = *v
359 case reflect.Interface:
360 origV = *v
361 *v = reflect.ValueOf(reflect.New(ifaceSliceType).Interface()).Elem()
362 defer func() {
363 origV.Set(*v)
364 *v = origV
365 }()
366 offset = mkSlice(v, count)
367 sliceV = *v
368 case reflect.Array:
369 if v.Len() < count {
370 panic(fmt.Errorf("array bounds overflow. Required %d, but array len is %d", count, v.Len()))
371 }
372 // Slice() creates a view backed by the array, so writes affect the original array.
373 sliceV = v.Slice(0, v.Len())
374 // offset is 0
375 // No concatenation for the fixed size arrays
376 default:
377 if count == 0 { // Allows empty slice for any scalar type (using default value)
378 return
379 } else {
380 panic(fmt.Errorf("can not convert '%s' to 'array'", v.Type().Kind().String()))
381 }
382 }
383
384 if count == 0 {
385 return
386 }
387 ptr = sliceV.UnsafePointer()
388
389 if subtag != TAG_OBJECT {
390 k := v.Type().Elem().Kind()
391 isPtr := false
392 if k == reflect.Ptr {
393 k = v.Type().Elem().Elem().Kind()
394 isPtr = true
395 }
396 switch k {
397 case reflect.Int:
398 if !isPtr {
399 sl := (*[1 << 28]int)(ptr)[offset : offset+count : offset+count]
400 for i := range count {

Callers 1

decodeValueMethod · 0.95

Calls 15

decodeValueMethod · 0.95
mkSliceFunction · 0.85
asIntFunction · 0.85
asFloatFunction · 0.85
asStringFunction · 0.85
asIfaceFunction · 0.85
InterfaceMethod · 0.80
SliceMethod · 0.80
ReadFloat32sMethod · 0.80
ReadFloat64sMethod · 0.80
TypeMethod · 0.65
GetCArrayTagMethod · 0.45

Tested by

no test coverage detected