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

18
pkg/json/map_slice.go Normal file
View File

@@ -0,0 +1,18 @@
package json
type MapSlice[V any] []Map[V]
func (s MapSlice[V]) MarshalJSONTo(buf []byte) []byte {
buf = append(buf, '[')
i := 0
n := len(s)
for _, entry := range s {
buf = entry.MarshalJSONTo(buf)
if i != n-1 {
buf = append(buf, ',')
}
i++
}
buf = append(buf, ']')
return buf
}