32 lines
618 B
Go
32 lines
618 B
Go
package encoding
|
|
|
|
import (
|
|
"io"
|
|
|
|
"git.nakama.town/fmartingr/gotoolkit/model"
|
|
"github.com/pelletier/go-toml/v2"
|
|
)
|
|
|
|
var (
|
|
_ model.Encoder = &TOMLEncoding{}
|
|
_ model.Decoder = &TOMLEncoding{}
|
|
)
|
|
|
|
type TOMLEncoding struct{}
|
|
|
|
func (e *TOMLEncoding) Encode(v any) ([]byte, error) {
|
|
return toml.Marshal(v)
|
|
}
|
|
|
|
func (e *TOMLEncoding) Decode(input []byte, output any) error {
|
|
return toml.Unmarshal(input, output)
|
|
}
|
|
|
|
func (e *TOMLEncoding) DecodeReader(input io.Reader, output any) error {
|
|
decoder := toml.NewDecoder(input)
|
|
return decoder.Decode(output)
|
|
}
|
|
|
|
func NewTOMLEncoding() *TOMLEncoding {
|
|
return &TOMLEncoding{}
|
|
}
|