MCPcopy Create free account
hub / github.com/blues/note / typeEncoder

Function typeEncoder

jsonxt/encode.go:356–383  ·  view source on GitHub ↗
(t reflect.Type)

Source from the content-addressed store, hash-verified

354}
355
356func typeEncoder(t reflect.Type) encoderFunc {
357 if fi, ok := encoderCache.Load(t); ok {
358 return fi.(encoderFunc)
359 }
360
361 // To deal with recursive types, populate the map with an
362 // indirect func before we build it. This type waits on the
363 // real func (f) to be ready and then calls it. This indirect
364 // func is only used for recursive types.
365 var (
366 wg sync.WaitGroup
367 f encoderFunc
368 )
369 wg.Add(1)
370 fi, loaded := encoderCache.LoadOrStore(t, encoderFunc(func(e *encodeState, v reflect.Value, opts encOpts) {
371 wg.Wait()
372 f(e, v, opts)
373 }))
374 if loaded {
375 return fi.(encoderFunc)
376 }
377
378 // Compute the real encoder and replace the indirect func with it.
379 f = newTypeEncoder(t, true)
380 wg.Done()
381 encoderCache.Store(t, f)
382 return f
383}
384
385var (
386 marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem()

Callers 5

valueEncoderFunction · 0.85
newMapEncoderFunction · 0.85
newArrayEncoderFunction · 0.85
newPtrEncoderFunction · 0.85
typeFieldsFunction · 0.85

Calls 2

encoderFuncFuncType · 0.85
newTypeEncoderFunction · 0.85

Tested by

no test coverage detected