28 lines
525 B
Go
28 lines
525 B
Go
package mdb
|
|
|
|
/*Copyright (c) 2022, John David Lee
|
|
All rights reserved.
|
|
|
|
This source code is licensed under the BSD-style license found in the
|
|
LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
|
|
"git.crumpington.com/public/mdb/kvstore"
|
|
)
|
|
|
|
func decode[T any](data []byte) *T {
|
|
item := new(T)
|
|
must(json.Unmarshal(data, item))
|
|
return item
|
|
}
|
|
|
|
func encode(item any) []byte {
|
|
w := bytes.NewBuffer(kvstore.GetDataBuf(0)[:0])
|
|
must(json.NewEncoder(w).Encode(item))
|
|
return w.Bytes()
|
|
}
|