compressor.go 680 B

12345678910111213141516171819202122232425262728
  1. package gocql
  2. import (
  3. "github.com/golang/snappy"
  4. )
  5. type Compressor interface {
  6. Name() string
  7. Encode(data []byte) ([]byte, error)
  8. Decode(data []byte) ([]byte, error)
  9. }
  10. // SnappyCompressor implements the Compressor interface and can be used to
  11. // compress incoming and outgoing frames. The snappy compression algorithm
  12. // aims for very high speeds and reasonable compression.
  13. type SnappyCompressor struct{}
  14. func (s SnappyCompressor) Name() string {
  15. return "snappy"
  16. }
  17. func (s SnappyCompressor) Encode(data []byte) ([]byte, error) {
  18. return snappy.Encode(nil, data), nil
  19. }
  20. func (s SnappyCompressor) Decode(data []byte) ([]byte, error) {
  21. return snappy.Decode(nil, data)
  22. }