This commit is contained in:
Edwardro22
2017-08-03 01:47:21 +03:00
19 changed files with 309 additions and 46 deletions

View File

@@ -21,6 +21,7 @@ import (
"bytes"
"encoding/gob"
"encoding/json"
"fmt"
"reflect"
"github.com/cgrates/cgrates/utils"
@@ -192,6 +193,19 @@ type LoadWriter interface {
SetTPThresholdCfg([]*utils.TPThresholdCfg) error
}
// NewMarshaler returns the marshaler type selected by mrshlerStr
func NewMarshaler(mrshlerStr string) (ms Marshaler, err error) {
switch mrshlerStr {
case utils.MSGPACK:
ms = NewCodecMsgpackMarshaler()
case utils.JSON:
ms = new(JSONMarshaler)
default:
err = fmt.Errorf("Unsupported marshaler: %v", mrshlerStr)
}
return
}
type Marshaler interface {
Marshal(v interface{}) ([]byte, error)
Unmarshal(data []byte, v interface{}) error