blockpullorder.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. type BlockPullOrder int32
  8. const (
  9. BlockPullOrderStandard BlockPullOrder = 0
  10. BlockPullOrderRandom BlockPullOrder = 1
  11. BlockPullOrderInOrder BlockPullOrder = 2
  12. )
  13. func (o BlockPullOrder) String() string {
  14. switch o {
  15. case BlockPullOrderStandard:
  16. return "standard"
  17. case BlockPullOrderRandom:
  18. return "random"
  19. case BlockPullOrderInOrder:
  20. return "inOrder"
  21. default:
  22. return "unknown"
  23. }
  24. }
  25. func (o BlockPullOrder) MarshalText() ([]byte, error) {
  26. return []byte(o.String()), nil
  27. }
  28. func (o *BlockPullOrder) UnmarshalText(bs []byte) error {
  29. switch string(bs) {
  30. case "standard":
  31. *o = BlockPullOrderStandard
  32. case "random":
  33. *o = BlockPullOrderRandom
  34. case "inOrder":
  35. *o = BlockPullOrderInOrder
  36. default:
  37. *o = BlockPullOrderStandard
  38. }
  39. return nil
  40. }