aboutsummaryrefslogtreecommitdiff
path: root/weed/pb/proto_read_write_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/pb/proto_read_write_test.go')
-rw-r--r--weed/pb/proto_read_write_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/weed/pb/proto_read_write_test.go b/weed/pb/proto_read_write_test.go
new file mode 100644
index 000000000..7f6444ab5
--- /dev/null
+++ b/weed/pb/proto_read_write_test.go
@@ -0,0 +1,43 @@
+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.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)
+
+}