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.

bytefifo.go 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package queue
  5. // ByteFIFO defines a FIFO that takes a byte array
  6. type ByteFIFO interface {
  7. // Len returns the length of the fifo
  8. Len() int64
  9. // PushFunc pushes data to the end of the fifo and calls the callback if it is added
  10. PushFunc(data []byte, fn func() error) error
  11. // Pop pops data from the start of the fifo
  12. Pop() ([]byte, error)
  13. // Close this fifo
  14. Close() error
  15. }
  16. // UniqueByteFIFO defines a FIFO that Uniques its contents
  17. type UniqueByteFIFO interface {
  18. ByteFIFO
  19. // Has returns whether the fifo contains this data
  20. Has(data []byte) (bool, error)
  21. }
  22. var _ (ByteFIFO) = &DummyByteFIFO{}
  23. // DummyByteFIFO represents a dummy fifo
  24. type DummyByteFIFO struct{}
  25. // PushFunc returns nil
  26. func (*DummyByteFIFO) PushFunc(data []byte, fn func() error) error {
  27. return nil
  28. }
  29. // Pop returns nil
  30. func (*DummyByteFIFO) Pop() ([]byte, error) {
  31. return []byte{}, nil
  32. }
  33. // Close returns nil
  34. func (*DummyByteFIFO) Close() error {
  35. return nil
  36. }
  37. // Len is always 0
  38. func (*DummyByteFIFO) Len() int64 {
  39. return 0
  40. }
  41. var _ (UniqueByteFIFO) = &DummyUniqueByteFIFO{}
  42. // DummyUniqueByteFIFO represents a dummy unique fifo
  43. type DummyUniqueByteFIFO struct {
  44. DummyByteFIFO
  45. }
  46. // Has always returns false
  47. func (*DummyUniqueByteFIFO) Has([]byte) (bool, error) {
  48. return false, nil
  49. }