aboutsummaryrefslogtreecommitdiff
path: root/weed/pb/proto_read_write_test.go
blob: d6b2faaeff81c32218262b12595459dd071f80c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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)

}