blockpullorder.go 866 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (C) 2020 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package config
  7. func (o BlockPullOrder) String() string {
  8. switch o {
  9. case BlockPullOrderStandard:
  10. return "standard"
  11. case BlockPullOrderRandom:
  12. return "random"
  13. case BlockPullOrderInOrder:
  14. return "inOrder"
  15. default:
  16. return "unknown"
  17. }
  18. }
  19. func (o BlockPullOrder) MarshalText() ([]byte, error) {
  20. return []byte(o.String()), nil
  21. }
  22. func (o *BlockPullOrder) UnmarshalText(bs []byte) error {
  23. switch string(bs) {
  24. case "standard":
  25. *o = BlockPullOrderStandard
  26. case "random":
  27. *o = BlockPullOrderRandom
  28. case "inOrder":
  29. *o = BlockPullOrderInOrder
  30. default:
  31. *o = BlockPullOrderStandard
  32. }
  33. return nil
  34. }