seaweedfs/weed/pb/proto_read_write_test.go
2022-08-17 12:42:03 -07:00

44 lines
797 B
Go

package pb
import (
"fmt"
"testing"
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
jsonpb "google.golang.org/protobuf/encoding/protojson"
)
func TestJsonpMarshalUnmarshal(t *testing.T) {
tv := &volume_server_pb.RemoteFile{
BackendType: "aws",
BackendId: "",
FileSize: 12,
}
m := jsonpb.Marshaler{
EmitDefaults: true,
Indent: " ",
}
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",
"backendId":"temp",
"fileSize":12
}`
tv1 := &volume_server_pb.RemoteFile{}
if err := jsonpb.UnmarshalString(rawJson, tv1); err != nil {
fmt.Printf("unmarshal error: %v\n", err)
}
fmt.Printf("unmarshalled: %+v\n", tv1)
}