You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
778 B

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package pb
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
  6. "github.com/golang/protobuf/jsonpb"
  7. )
  8. func TestJsonpMarshalUnmarshal(t *testing.T) {
  9. tv := &volume_server_pb.RemoteFile{
  10. BackendType: "aws",
  11. BackendId: "",
  12. FileSize: 12,
  13. }
  14. m := jsonpb.Marshaler{
  15. EmitDefaults: true,
  16. Indent: " ",
  17. }
  18. if text, err := m.MarshalToString(tv); err != nil {
  19. fmt.Printf("marshal eror: %v\n", err)
  20. } else {
  21. fmt.Printf("marshalled: %s\n", text)
  22. }
  23. rawJson := `{
  24. "backendType":"aws",
  25. "backendId":"temp",
  26. "fileSize":12
  27. }`
  28. tv1 := &volume_server_pb.RemoteFile{}
  29. if err := jsonpb.UnmarshalString(rawJson, tv1); err != nil {
  30. fmt.Printf("unmarshal error: %v\n", err)
  31. }
  32. fmt.Printf("unmarshalled: %+v\n", tv1)
  33. }