2019-11-27 19:09:42 +08:00
|
|
|
package pb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
|
|
|
|
"github.com/golang/protobuf/jsonpb"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestJsonpMarshalUnmarshal(t *testing.T) {
|
|
|
|
|
|
|
|
tv := &volume_server_pb.TieredVolume{
|
|
|
|
BackendType: "aws",
|
|
|
|
BackendName: "",
|
|
|
|
Version: 12,
|
|
|
|
}
|
|
|
|
|
|
|
|
m := jsonpb.Marshaler{
|
|
|
|
EmitDefaults: true,
|
2019-11-28 04:34:57 +08:00
|
|
|
Indent: " ",
|
2019-11-27 19:09:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if text, err := m.MarshalToString(tv); err != nil {
|
|
|
|
fmt.Printf("marshal eror: %v\n", err)
|
|
|
|
} else {
|
|
|
|
fmt.Printf("marshalled: %s\n", text)
|
|
|
|
}
|
|
|
|
|
|
|
|
rawJson := `{
|
|
|
|
"backendType":"aws",
|
|
|
|
"backendName":"temp",
|
|
|
|
"version":12
|
|
|
|
}`
|
|
|
|
|
|
|
|
tv1 := &volume_server_pb.TieredVolume{}
|
|
|
|
if err := jsonpb.UnmarshalString(rawJson, tv1); err != nil {
|
2019-12-03 07:06:12 +08:00
|
|
|
fmt.Printf("unmarshal error: %v\n", err)
|
2019-11-27 19:09:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("unmarshalled: %+v\n", tv1)
|
|
|
|
|
|
|
|
}
|