diff --git a/utils.go b/utils.go index f93f64d..ee6469b 100644 --- a/utils.go +++ b/utils.go @@ -42,11 +42,19 @@ func GenerateReqrepSubject(server, service, subject string) string { return fmt.Sprintf("%s.reqrep.%s.%s.%s", globalConfig.StreamName, server, service, subject) } -// ToBytes ... -func ToBytes(data interface{}) []byte { +// InterfaceToBytes ... +func InterfaceToBytes(data interface{}) []byte { b, err := json.Marshal(data) if err != nil { - fmt.Printf("[natsio.ToBytes] error: %v with data: %v\n", err, data) + fmt.Printf("[natsio.InterfaceToBytes] error: %v with data: %v\n", err, data) } return b } + +func BytesToInterface(b []byte, pointer interface{}) error { + err := json.Unmarshal(b, pointer) + if err != nil { + fmt.Printf("[natsio.BytesToInterface] error: %v with data: %s\n", err, string(b)) + } + return err +}