MCPcopy
hub / github.com/openai/openai-go / typeEncoder

Function typeEncoder

internal/encoding/json/encode.go:378–405  ·  view source on GitHub ↗
(t reflect.Type)

Source from the content-addressed store, hash-verified

376}
377
378func typeEncoder(t reflect.Type) encoderFunc {
379 if fi, ok := encoderCache.Load(t); ok {
380 return fi.(encoderFunc)
381 }
382
383 // To deal with recursive types, populate the map with an
384 // indirect func before we build it. This type waits on the
385 // real func (f) to be ready and then calls it. This indirect
386 // func is only used for recursive types.
387 var (
388 wg sync.WaitGroup
389 f encoderFunc
390 )
391 wg.Add(1)
392 fi, loaded := encoderCache.LoadOrStore(t, encoderFunc(func(e *encodeState, v reflect.Value, opts encOpts) {
393 wg.Wait()
394 f(e, v, opts)
395 }))
396 if loaded {
397 return fi.(encoderFunc)
398 }
399
400 // Compute the real encoder and replace the indirect func with it.
401 f = newTypeEncoder(t, true)
402 wg.Done()
403 encoderCache.Store(t, f)
404 return f
405}
406
407var (
408 // SHIM(begin): TypeFor[T]() reflect.Type

Callers 5

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

Calls 2

newTypeEncoderFunction · 0.85
encoderFuncFuncType · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…