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
810 B

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
2 years ago
5 years ago
2 years ago
5 years ago
2 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
2 years ago
5 years ago
5 years ago
  1. package pb
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
  6. jsonpb "google.golang.org/protobuf/encoding/protojson"
  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.MarshalOptions{
  15. EmitUnpopulated: true,
  16. Indent: " ",
  17. }
  18. if text, err := m.Marshal(tv); err != nil {
  19. fmt.Printf("marshal eror: %v\n", err)
  20. } else {
  21. fmt.Printf("marshalled: %s\n", string(text))
  22. }
  23. rawJson := `{
  24. "backendType":"aws",
  25. "backendId":"temp",
  26. "fileSize":12
  27. }`
  28. tv1 := &volume_server_pb.RemoteFile{}
  29. if err := jsonpb.Unmarshal([]byte(rawJson), tv1); err != nil {
  30. fmt.Printf("unmarshal error: %v\n", err)
  31. }
  32. fmt.Printf("unmarshalled: %+v\n", tv1)
  33. }