resp.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Package resp is an umbrella package which covers both the old RESP protocol
  2. // (resp2) and the new one (resp3), allowing clients to choose which one they
  3. // care to use
  4. package resp
  5. import (
  6. "bufio"
  7. "io"
  8. )
  9. // Marshaler is the interface implemented by types that can marshal themselves
  10. // into valid RESP.
  11. type Marshaler interface {
  12. MarshalRESP(io.Writer) error
  13. }
  14. // Unmarshaler is the interface implemented by types that can unmarshal a RESP
  15. // description of themselves. UnmarshalRESP should _always_ fully consume a RESP
  16. // message off the reader, unless there is an error returned from the reader
  17. // itself.
  18. //
  19. // Note that, unlike Marshaler, Unmarshaler _must_ take in a *bufio.Reader.
  20. type Unmarshaler interface {
  21. UnmarshalRESP(*bufio.Reader) error
  22. }
  23. // ErrDiscarded is used to wrap an error encountered while unmarshaling a
  24. // message. If an error was encountered during unmarshaling but the rest of the
  25. // message was successfully discarded off of the wire, then the error can be
  26. // wrapped in this type.
  27. type ErrDiscarded struct {
  28. Err error
  29. }
  30. func (ed ErrDiscarded) Error() string {
  31. return ed.Err.Error()
  32. }
  33. // Unwrap implements the errors.Wrapper interface.
  34. func (ed ErrDiscarded) Unwrap() error {
  35. return ed.Err
  36. }