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

Method encodeSlice

cjson/encoder.go:634–820  ·  view source on GitHub ↗
(v reflect.Value, rdser *Serializer, f fieldInfo, cache *ctagsWCache)

Source from the content-addressed store, hash-verified

632}
633
634func (enc *Encoder) encodeSlice(v reflect.Value, rdser *Serializer, f fieldInfo, cache *ctagsWCache) error {
635 l := v.Len()
636 if l == 0 && f.isOmitEmpty {
637 return nil
638 }
639 if f.elemKind == reflect.Uint8 {
640 rdser.PutCTag(mkctag(TAG_STRING, f.ctagName, 0))
641 rdser.PutVString(base64.StdEncoding.EncodeToString(v.Bytes()))
642 } else {
643 rdser.PutCTag(mkctag(TAG_ARRAY, f.ctagName, 0))
644
645 subTag := TAG_OBJECT
646 switch f.elemKind {
647 case reflect.Int, reflect.Int16, reflect.Int64, reflect.Int8, reflect.Int32,
648 reflect.Uint, reflect.Uint16, reflect.Uint64, reflect.Uint32:
649 subTag = TAG_VARINT
650 case reflect.Float32:
651 subTag = TAG_FLOAT
652 case reflect.Float64:
653 subTag = TAG_DOUBLE
654 case reflect.String:
655 if f.isUuid {
656 subTag = TAG_UUID
657 } else {
658 subTag = TAG_STRING
659 }
660 case reflect.Bool:
661 subTag = TAG_BOOL
662 }
663
664 rdser.PutCArrayTag(mkcarraytag(l, subTag))
665
666 if f.kind == reflect.Slice {
667 ptr := unsafe.Pointer(v.Pointer())
668
669 switch f.elemKind {
670 case reflect.Int:
671 sl := (*[1 << 28]int)(ptr)[:l:l]
672 for _, v := range sl {
673 rdser.PutVarInt(int64(v))
674 }
675 case reflect.Uint:
676 sl := (*[1 << 28]uint)(ptr)[:l:l]
677 for _, v := range sl {
678 rdser.PutVarInt(int64(v))
679 }
680 case reflect.Int32:
681 sl := (*[1 << 28]int32)(ptr)[:l:l]
682 for _, v := range sl {
683 rdser.PutVarInt(int64(v))
684 }
685 case reflect.Uint32:
686 sl := (*[1 << 28]uint32)(ptr)[:l:l]
687 for _, v := range sl {
688 rdser.PutVarInt(int64(v))
689 }
690 case reflect.Int16:
691 sl := (*[1 << 29]int16)(ptr)[:l:l]

Callers 1

encodeValueMethod · 0.95

Calls 15

encodeValueMethod · 0.95
mkctagFunction · 0.85
mkcarraytagFunction · 0.85
mkFieldInfoFunction · 0.85
BytesMethod · 0.80
WriteFloat32sMethod · 0.80
WriteFloat64sMethod · 0.80
PutFloat32Method · 0.80
ParseUuidFunction · 0.70
LenMethod · 0.45
PutCTagMethod · 0.45
PutVStringMethod · 0.45

Tested by

no test coverage detected