func encodeSortedSyncMap(sm *sync.Map, dst []byte, opts encOpts) ([]byte, error) {
	var (
		off int
		err error
		buf = cachedBuffer()
		mel *mapElems
	)
	if v := mapElemsPool.Get(); v != nil {
		mel = v.(*mapElems)
	} else {
		mel = &mapElems{s: make([]kv, 0)}
	}
	sm.Range(func(key, value interface{}) bool {
		kv := kv{}
		if buf.B, err = appendSyncMapKey(buf.B, key, opts); err != nil {
			return false
		}
		kv.key = buf.B[off+1 : len(buf.B)-1]
		buf.B = append(buf.B, ':')
		if buf.B, err = appendJSON(buf.B, value, opts); err != nil {
			return false
		}
		kv.keyval = buf.B[off:len(buf.B)]
		mel.s = append(mel.s, kv)
		off = len(buf.B)
		return true
	})
	if err == nil {
		sort.Sort(mel)
		for i, kv := range mel.s {
			if i != 0 {
				dst = append(dst, ',')
			}
			dst = append(dst, kv.keyval...)
		}
	}
	releaseMapElems(mel)
	bufferPool.Put(buf)
	return dst, err
}
encodeSortedSyncMap is similar to encodeSortedMap
but operates on a sync.Map type instead of a Go map.
package jettison
import (
	"encoding"
	"encoding/base64"
	"encoding/json"
	"errors"
	"fmt"
	"math"
	"reflect"
	"runtime"
	"sort"
	"strconv"
	"sync"
	"time"
	"unicode/utf8"
	"unsafe"
)
const hex = "0123456789abcdef"
func encodeBool(p unsafe.Pointer, dst []byte, _ encOpts) ([]byte, error) {
	if *(*bool)(p) {
		return append(dst, "true"...), nil
	}
	return append(dst, "false"...), nil
}
func encodeString(p unsafe.Pointer, dst []byte, opts encOpts) ([]byte, error) {
	dst = append(dst, '"')
	dst = appendEscapedBytes(dst, sp2b(p), opts)
	dst = append(dst, '"')
	return dst, nil
}
func encodeQuotedString(p unsafe.Pointer, dst []byte, opts encOpts) ([]byte, error) {
	dst = append(dst, `"\"`...)
	dst = appendEscapedBytes(dst, sp2b(p), opts)
	dst = append(dst, `\""`...)
	return dst, nil
}
func encodeFloat32(p unsafe.Pointer, dst []byte, _ encOpts) ([]byte, error) {
	return appendFloat(dst, float64(*(*float32)(p)), 32)
}
func encodeFloat64(p unsafe.Pointer, dst []byte, _ encOpts) ([]byte, error) {
	return appendFloat(dst, *(*float64)(p), 64)
}
func encodeInterface(p unsafe.Pointer, dst []byte, opts encOpts) ([]byte, error) {
	v := *(*interface{})(p)
	if v == nil {
		return append(dst, "null"...), nil
	}
	typ := reflect.TypeOf(v)
	ins := cachedInstr(typ)
	return ins(unpackEface(v).word, dst, opts)
}
func encodeNumber(p unsafe.Pointer, dst []byte, opts encOpts) ([]byte, error) {
	num := *(*string)(p)
	if num == "" {
		num = "0"  
	}
	if !opts.flags.has(noNumberValidation) && !isValidNumber(num) {
		return dst, fmt.Errorf("json: invalid number literal %q", num)
	}
	return append(dst, num...), nil
}
func encodeRawMessage(p unsafe.Pointer, dst []byte, opts encOpts) ([]byte, error) {
	v := *(*json.RawMessage)(p)
	if v == nil {
		return append(dst, "null"...), nil
	}
	if opts.flags.has(noCompact) {
		return append(dst, v...), nil
	}
	return appendCompactJSON(dst, v, !opts.flags.has(noHTMLEscaping))
}
func encodeTime(p unsafe.Pointer, dst []byte, opts encOpts) ([]byte, error) {
	t := *(*time.Time)(p)
	y := t.Year()
	if y < 0 || y >= 10000 {
		return dst, errors.New("time: year outside of range [0,9999]")
	}
	if opts.flags.has(unixTime) {
		return strconv.AppendInt(dst, t.Unix(), 10), nil
	}
	switch opts.timeLayout {
	case time.RFC3339:
		return appendRFC3339Time(t, dst, false), nil
	case time.RFC3339Nano:
		return appendRFC3339Time(t, dst, true), nil
	default:
		dst = append(dst, '"')
		dst = t.AppendFormat(dst, opts.timeLayout)
		dst = append(dst, '"')
		return dst, nil
	}
}
func encodeDuration(p unsafe.Pointer, dst []byte, opts encOpts) ([]byte, error) {
	d := *(*time.Duration)(p)
	switch opts.durationFmt {
	default:  
		return strconv.AppendInt(dst, d.Nanoseconds(), 10), nil
	case DurationMinutes:
		return appendFloat(dst, d.Minutes(), 64)
	case DurationSeconds:
		return appendFloat(dst, d.Seconds(), 64)
	case DurationMicroseconds:
		return strconv.AppendInt(dst, int64(d)/1e3, 10), nil
	case DurationMilliseconds:
		return strconv.AppendInt(dst, int64(d)/1e6, 10), nil
	case DurationString:
		dst = append(dst, '"')
		dst = appendDuration(dst, d)
		dst = append(dst, '"')
		return dst, nil
	}
}
func appendFloat(dst []byte, f float64, bs int) ([]byte, error) {
	if math.IsInf(f, 0) || math.IsNaN(f) {
		return dst, &UnsupportedValueError{
			reflect.ValueOf(f),
			strconv.FormatFloat(f, 'g', -1, bs),
		}
	}
	abs := math.Abs(f)
	format := byte('f')
	if abs != 0 {
		if bs == 64 && (abs < 1e-6 || abs >= 1e21) ||
			bs == 32 && (float32(abs) < 1e-6 || float32(abs) >= 1e21) {
			format = 'e'
		}
	}
	dst = strconv.AppendFloat(dst, f, format, -1, bs)
	if format == 'e' {
		n := len(dst)
		if n >= 4 && dst[n-4] == 'e' && dst[n-3] == '-' && dst[n-2] == '0' {
			dst[n-2] = dst[n-1]
			dst = dst[:n-1]
		}
	}
	return dst, nil
}
func encodePointer(p unsafe.Pointer, dst []byte, opts encOpts, ins instruction) ([]byte, error) {
	if p = *(*unsafe.Pointer)(p); p != nil {
		return ins(p, dst, opts)
	}
	return append(dst, "null"...), nil
}
func encodeStruct(
	p unsafe.Pointer, dst []byte, opts encOpts, flds []field,
) ([]byte, error) {
	var (
		nxt = byte('{')
		key []byte  
	)
	noHTMLEscape := opts.flags.has(noHTMLEscaping)
fieldLoop:
	for i := 0; i < len(flds); i++ {
		f := &flds[i]  
		if opts.isDeniedField(f.name) {
			continue
		}
		v := p
		for i := 0; i < len(f.embedSeq); i++ {
			s := &f.embedSeq[i]
			v = unsafe.Pointer(uintptr(v) + s.offset)
			if s.indir {
				if v = *(*unsafe.Pointer)(v); v == nil {
					continue fieldLoop
				}
			}
		}
		if f.omitNil && *(*unsafe.Pointer)(v) == nil {
			continue
		}
		if f.omitEmpty && f.empty(v) {
			continue
		}
		key = f.keyEscHTML
		if noHTMLEscape {
			key = f.keyNonEsc
		}
		dst = append(dst, nxt)
		nxt = ','
		dst = append(dst, key...)
		var err error
		if dst, err = f.instr(v, dst, opts); err != nil {
			return dst, err
		}
	}
	if nxt == '{' {
		return append(dst, "{}"...), nil
	}
	return append(dst, '}'), nil
}
func encodeSlice(
	p unsafe.Pointer, dst []byte, opts encOpts, ins instruction, es uintptr,
) ([]byte, error) {
	shdr := (*sliceHeader)(p)
	if shdr.Data == nil {
		if opts.flags.has(nilSliceEmpty) {
			return append(dst, "[]"...), nil
		}
		return append(dst, "null"...), nil
	}
	if shdr.Len == 0 {
		return append(dst, "[]"...), nil
	}
	return encodeArray(shdr.Data, dst, opts, ins, es, shdr.Len, false)
}
func encodeByteSlice(p unsafe.Pointer, dst []byte, opts encOpts) ([]byte, error) {
	b := *(*[]byte)(p)
	if b == nil {
		return append(dst, "null"...), nil
	}
	dst = append(dst, '"')
	if opts.flags.has(rawByteSlice) {
		dst = appendEscapedBytes(dst, b, opts)
	} else {
		n := base64.StdEncoding.EncodedLen(len(b))
		if a := cap(dst) - len(dst); a < n {
			new := make([]byte, cap(dst)+(n-a))
			copy(new, dst)
			dst = new[:len(dst)]
		}
		end := len(dst) + n
		base64.StdEncoding.Encode(dst[len(dst):end], b)
		dst = dst[:end]
	}
	return append(dst, '"'), nil
}
func encodeArray(
	p unsafe.Pointer, dst []byte, opts encOpts, ins instruction, es uintptr, len int, isByteArray bool,
) ([]byte, error) {
	if isByteArray && opts.flags.has(byteArrayAsString) {
		return encodeByteArrayAsString(p, dst, opts, len), nil
	}
	var err error
	nxt := byte('[')
	for i := 0; i < len; i++ {
		dst = append(dst, nxt)
		nxt = ','
		v := unsafe.Pointer(uintptr(p) + (uintptr(i) * es))
		if dst, err = ins(v, dst, opts); err != nil {
			return dst, err
		}
	}
	if nxt == '[' {
		return append(dst, "[]"...), nil
	}
	return append(dst, ']'), nil
}
func encodeByteArrayAsString(p unsafe.Pointer, dst []byte, opts encOpts, len int) []byte {
	b := *(*[]byte)(unsafe.Pointer(&sliceHeader{
		Data: p,
		Len:  len,
		Cap:  len,
	}))
	dst = append(dst, '"')
	dst = appendEscapedBytes(dst, b, opts)
	dst = append(dst, '"')
	return dst
}
func encodeMap(
	p unsafe.Pointer, dst []byte, opts encOpts, t reflect.Type, ki, vi instruction,
) ([]byte, error) {
	m := *(*unsafe.Pointer)(p)
	if m == nil {
		if opts.flags.has(nilMapEmpty) {
			return append(dst, "{}"...), nil
		}
		return append(dst, "null"...), nil
	}
	ml := maplen(m)
	if ml == 0 {
		return append(dst, "{}"...), nil
	}
	dst = append(dst, '{')
	rt := unpackEface(t).word
	it := newHiter(rt, m)
	var err error
	if opts.flags.has(unsortedMap) {
		dst, err = encodeUnsortedMap(it, dst, opts, ki, vi)
	} else {
		dst, err = encodeSortedMap(it, dst, opts, ki, vi, ml)
	}
	hiterPool.Put(it)
	if err != nil {
		return dst, err
	}
	return append(dst, '}'), err
}
func encodeUnsortedMap(
	it *hiter, dst []byte, opts encOpts, ki, vi instruction,
) ([]byte, error) {
	var (
		n   int
		err error
	)
	for ; it.key != nil; mapiternext(it) {
		if n != 0 {
			dst = append(dst, ',')
		}
		if dst, err = ki(it.key, dst, opts); err != nil {
			return dst, err
		}
		dst = append(dst, ':')
		if dst, err = vi(it.val, dst, opts); err != nil {
			return dst, err
		}
		n++
	}
	return dst, nil
}
func encodeSortedMap(
	it *hiter, dst []byte, opts encOpts, ki, vi instruction, ml int,
) ([]byte, error) {
	var (
		off int
		err error
		buf = cachedBuffer()
		mel *mapElems
	)
	if v := mapElemsPool.Get(); v != nil {
		mel = v.(*mapElems)
	} else {
		mel = &mapElems{s: make([]kv, 0, ml)}
	}
	for ; it.key != nil; mapiternext(it) {
		kv := kv{}
		if buf.B, err = ki(it.key, buf.B, opts); err != nil {
			break
		}
		kv.key = buf.B[off+1 : len(buf.B)-1]
		buf.B = append(buf.B, ':')
		if buf.B, err = vi(it.val, buf.B, opts); err != nil {
			break
		}
		kv.keyval = buf.B[off:len(buf.B)]
		mel.s = append(mel.s, kv)
		off = len(buf.B)
	}
	if err == nil {
		sort.Sort(mel)
		for i, kv := range mel.s {
			if i != 0 {
				dst = append(dst, ',')
			}
			dst = append(dst, kv.keyval...)
		}
	}
	releaseMapElems(mel)
	bufferPool.Put(buf)
	return dst, err
}
func encodeSyncMap(p unsafe.Pointer, dst []byte, opts encOpts) ([]byte, error) {
	sm := (*sync.Map)(p)
	dst = append(dst, '{')
	var err error
	if opts.flags.has(unsortedMap) {
		dst, err = encodeUnsortedSyncMap(sm, dst, opts)
	} else {
		dst, err = encodeSortedSyncMap(sm, dst, opts)
	}
	if err != nil {
		return dst, err
	}
	return append(dst, '}'), nil
}
func encodeUnsortedSyncMap(sm *sync.Map, dst []byte, opts encOpts) ([]byte, error) {
	var (
		n   int
		err error
	)
	sm.Range(func(key, value interface{}) bool {
		if n != 0 {
			dst = append(dst, ',')
		}
		if dst, err = appendSyncMapKey(dst, key, opts); err != nil {
			return false
		}
		dst = append(dst, ':')
		if dst, err = appendJSON(dst, value, opts); err != nil {
			return false
		}
		n++
		return true
	})
	return dst, err
}