24
`github.com/bytedance/sonic/internal/jit`
25
`github.com/bytedance/sonic/internal/native`
26
`github.com/bytedance/sonic/internal/rt`
31
func encodeNil(rb *[]byte) error {
32
*rb = append(*rb, 'n', 'u', 'l', 'l')
36
func encodeString(buf *[]byte, val string) error {
42
*buf = append(*buf, '"')
43
pbuf = (*rt.GoSlice)(unsafe.Pointer(buf))
44
pstr = (*rt.GoString)(unsafe.Pointer(&val))
49
dn := pbuf.Cap - pbuf.Len
50
sp := padd(pstr.Ptr, sidx)
51
dp := padd(pbuf.Ptr, pbuf.Len)
52
nb := native.Quote(sp, sn, dp, &dn, 0)
55
if pbuf.Len += dn; nb >= 0 {
61
*pbuf = growslice(rt.UnpackType(byteType), *pbuf, pbuf.Cap * 2)
65
*buf = append(*buf, '"')
69
func encodeTypedPointer(buf *[]byte, vt *rt.GoType, vp *unsafe.Pointer, sb *_Stack, fv uint64) error {
72
} else if fn, err := findOrCompile(vt, (fv&(1<<bitPointerValue)) != 0); err != nil {
74
} else if vt.Indirect() {
75
rt.MoreStack(_FP_size + native.MaxFrameSize)
77
err := fn(buf, *vp, sb, fv)
81
rt.MoreStack(_FP_size + native.MaxFrameSize)
83
err := fn(buf, unsafe.Pointer(vp), sb, fv)
89
func encodeJsonMarshaler(buf *[]byte, val json.Marshaler, opt Options) error {
90
if ret, err := val.MarshalJSON(); err != nil {
93
if opt & CompactMarshaler != 0 {
94
return compact(buf, ret)
96
if opt & NoValidateJSONMarshaler == 0 {
97
if ok, s := Valid(ret); !ok {
98
return error_marshaler(ret, s)
101
*buf = append(*buf, ret...)
106
func encodeTextMarshaler(buf *[]byte, val encoding.TextMarshaler, opt Options) error {
107
if ret, err := val.MarshalText(); err != nil {
110
if opt & NoQuoteTextMarshaler != 0 {
111
*buf = append(*buf, ret...)
114
return encodeString(buf, rt.Mem2Str(ret) )
118
func htmlEscape(dst []byte, src []byte) []byte {
121
dst = append(dst, src[:0]...)
122
sbuf := (*rt.GoSlice)(unsafe.Pointer(&src))
123
dbuf := (*rt.GoSlice)(unsafe.Pointer(&dst))
126
if cap(dst) - len(dst) < len(src) + native.BufPaddingSize {
127
cap := len(src) * 3 / 2 + native.BufPaddingSize
128
*dbuf = growslice(typeByte, *dbuf, cap)
131
for sidx < sbuf.Len {
132
sp := padd(sbuf.Ptr, sidx)
133
dp := padd(dbuf.Ptr, dbuf.Len)
135
sn := sbuf.Len - sidx
136
dn := dbuf.Cap - dbuf.Len
137
nb := native.HTMLEscape(sp, sn, dp, &dn)
140
if dbuf.Len += dn; nb >= 0 {
146
*dbuf = growslice(typeByte, *dbuf, dbuf.Cap * 2)
152
argPtrs = []bool { true, true, true, false }
157
_F_assertI2I = jit.Func(assertI2I)
160
func asText(v unsafe.Pointer) (string, error) {
161
text := assertI2I(_T_encoding_TextMarshaler, *(*rt.GoIface)(v))
162
r, e := (*(*encoding.TextMarshaler)(unsafe.Pointer(&text))).MarshalText()
163
return rt.Mem2Str(r), e
166
func asJson(v unsafe.Pointer) (string, error) {
167
text := assertI2I(_T_json_Marshaler, *(*rt.GoIface)(v))
168
r, e := (*(*json.Marshaler)(unsafe.Pointer(&text))).MarshalJSON()
169
return rt.Mem2Str(r), e