feat: custom json marshaler implementation

This commit is contained in:
yusing
2025-04-16 14:36:27 +08:00
parent 75fd8d1fdc
commit cdfc9d553b
10 changed files with 1479 additions and 0 deletions

24
pkg/json/map.go Normal file
View File

@@ -0,0 +1,24 @@
package json
import (
"reflect"
)
type Map[V any] map[string]V
func (m Map[V]) MarshalJSONTo(buf []byte) []byte {
buf = append(buf, '{')
i := 0
n := len(m)
for k, v := range m {
buf = AppendString(buf, k)
buf = append(buf, ':')
buf = appendMarshal(reflect.ValueOf(v), buf)
if i != n-1 {
buf = append(buf, ',')
}
i++
}
buf = append(buf, '}')
return buf
}