mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 09:18:31 +02:00
feat: trie implementation
This commit is contained in:
26
internal/utils/trie/json.go
Normal file
26
internal/utils/trie/json.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package trie
|
||||
|
||||
import (
|
||||
"maps"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
)
|
||||
|
||||
var sonicConfig = sonic.Config{
|
||||
EncodeNullForInfOrNan: true,
|
||||
}.Froze()
|
||||
|
||||
func (r *Root) MarshalJSON() ([]byte, error) {
|
||||
return sonicConfig.Marshal(maps.Collect(r.Walk))
|
||||
}
|
||||
|
||||
func (r *Root) UnmarshalJSON(data []byte) error {
|
||||
var m map[string]any
|
||||
if err := sonicConfig.Unmarshal(data, &m); err != nil {
|
||||
return err
|
||||
}
|
||||
for k, v := range m {
|
||||
r.Store(NewKey(k), v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user