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

Method Encode

cjson/encoder.go:932–956  ·  view source on GitHub ↗
(src any, wrser *Serializer)

Source from the content-addressed store, hash-verified

930}
931
932func (enc *Encoder) Encode(src any, wrser *Serializer) (stateToken int, err error) {
933
934 v := reflect.ValueOf(src)
935 enc.state.lock.Lock()
936 defer enc.state.lock.Unlock()
937
938 pos := len(wrser.Bytes())
939 enc.tagsMatcher = &enc.state.tagsMatcher
940 enc.tmUpdated = false
941 err = enc.encodeValue(v, wrser, mkFieldInfo(v, 0, reflect.StructField{}), &enc.state.ctagsWCache)
942 if err != nil {
943 return
944 }
945
946 if enc.tmUpdated {
947 payloadLen := len(wrser.buf) - pos
948 wrser.grow(int(unsafe.Sizeof(uint32(0))) + 1)
949 copy(wrser.buf[pos+int(unsafe.Sizeof(uint32(0)))+1:], wrser.buf[pos:pos+payloadLen])
950 wrser.buf[pos] = TAG_END
951 *(*uint32)(unsafe.Pointer(&wrser.Bytes()[pos+1])) = uint32(len(wrser.buf) - pos)
952 enc.tagsMatcher.WriteUpdated(wrser)
953 }
954 stateToken = int(enc.state.StateToken)
955 return
956}
957
958func (enc *Encoder) EncodeRaw(src any, wrser *Serializer) error {
959

Callers 9

packItemFunction · 0.95
initFunction · 0.95
BenchmarkCJsonEncodeFunction · 0.95
BenchmarkGobEncodeFunction · 0.95
BenchmarkJsonEncodeFunction · 0.95
bytesMethod · 0.45

Calls 9

encodeValueMethod · 0.95
mkFieldInfoFunction · 0.85
copyFunction · 0.85
BytesMethod · 0.80
SizeofMethod · 0.80
WriteUpdatedMethod · 0.80
LockMethod · 0.45
UnlockMethod · 0.45
growMethod · 0.45

Tested by 7

initFunction · 0.76
BenchmarkCJsonEncodeFunction · 0.76
BenchmarkGobEncodeFunction · 0.76
BenchmarkJsonEncodeFunction · 0.76