41 lines
854 B
Go
41 lines
854 B
Go
package dinetrpc
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/vmihailenco/msgpack"
|
|
)
|
|
|
|
func MarshalMsgpack(v ...interface{}) ([]byte, error) {
|
|
var buf bytes.Buffer
|
|
enc := msgpack.NewEncoder(&buf)
|
|
enc.UseJSONTag(true)
|
|
err := enc.Encode(v)
|
|
return buf.Bytes(), err
|
|
}
|
|
|
|
func (cm ClassMethod) MarshalMsgpack() ([]byte, error) {
|
|
return msgpack.Marshal(ClassMethodJSONString(cm))
|
|
}
|
|
|
|
func UnmarshalMsgpack(data []byte, v ...interface{}) error {
|
|
r := bytes.NewReader(data)
|
|
dec := msgpack.NewDecoder(r)
|
|
//dec.UseJSONTag(true)
|
|
return dec.Decode(v)
|
|
}
|
|
|
|
func (v *Value) UnmarshalMsgpack(b []byte) error {
|
|
// XXX because isValue_Value interface is not assignable
|
|
return nil
|
|
}
|
|
|
|
func (cm *ClassMethod) UnmarshalMsgpack(b []byte) error {
|
|
var cms string
|
|
if err := msgpack.Unmarshal(b, &cms); err != nil {
|
|
return err
|
|
}
|
|
*cm = ClassMethodFromJSONString(cms)
|
|
return nil
|
|
}
|