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

Method encode

internal/encoding/json/encode.go:744–781  ·  view source on GitHub ↗
(e *encodeState, v reflect.Value, opts encOpts)

Source from the content-addressed store, hash-verified

742}
743
744func (se structEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) {
745 next := byte('{')
746FieldLoop:
747 for i := range se.fields.list {
748 f := &se.fields.list[i]
749
750 // Find the nested struct field by following f.index.
751 fv := v
752 for _, i := range f.index {
753 if fv.Kind() == reflect.Pointer {
754 if fv.IsNil() {
755 continue FieldLoop
756 }
757 fv = fv.Elem()
758 }
759 fv = fv.Field(i)
760 }
761
762 if (f.omitEmpty && isEmptyValue(fv)) ||
763 (f.omitZero && (f.isZero == nil && fv.IsZero() || (f.isZero != nil && f.isZero(fv)))) {
764 continue
765 }
766 e.WriteByte(next)
767 next = ','
768 if opts.escapeHTML {
769 e.WriteString(f.nameEscHTML)
770 } else {
771 e.WriteString(f.nameNonEsc)
772 }
773 opts.quoted = f.quoted
774 f.encoder(e, fv, opts)
775 }
776 if next == '{' {
777 e.WriteString("{}")
778 } else {
779 e.WriteByte('}')
780 }
781}
782
783func newStructEncoder(t reflect.Type) encoderFunc {
784 se := structEncoder{fields: cachedTypeFields(t)}

Callers

nothing calls this directly

Calls 3

isEmptyValueFunction · 0.85
IsZeroMethod · 0.80
isZeroMethod · 0.65

Tested by

no test coverage detected