-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
280f0aa
commit 921d082
Showing
15 changed files
with
2,689 additions
and
2,003 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package compressor | ||
|
||
import "github.com/golang/snappy" | ||
|
||
type Compressor interface { | ||
Name() string | ||
Encode(data []byte) ([]byte, error) | ||
Decode(data []byte) ([]byte, error) | ||
} | ||
|
||
// SnappyCompressor implements the Compressor interface and can be used to | ||
// compress incoming and outgoing frames. The snappy compression algorithm | ||
// aims for very high speeds and reasonable compression. | ||
type SnappyCompressor struct{} | ||
|
||
func (s SnappyCompressor) Name() string { | ||
return "snappy" | ||
} | ||
|
||
func (s SnappyCompressor) Encode(data []byte) ([]byte, error) { | ||
return snappy.Encode(nil, data), nil | ||
} | ||
|
||
func (s SnappyCompressor) Decode(data []byte) ([]byte, error) { | ||
return snappy.Decode(nil, data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package consistency | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type Consistency uint16 | ||
|
||
const ( | ||
Any Consistency = 0x00 | ||
One Consistency = 0x01 | ||
Two Consistency = 0x02 | ||
Three Consistency = 0x03 | ||
Quorum Consistency = 0x04 | ||
All Consistency = 0x05 | ||
LocalQuorum Consistency = 0x06 | ||
EachQuorum Consistency = 0x07 | ||
LocalOne Consistency = 0x0A | ||
) | ||
|
||
func (c Consistency) String() string { | ||
switch c { | ||
case Any: | ||
return "ANY" | ||
case One: | ||
return "ONE" | ||
case Two: | ||
return "TWO" | ||
case Three: | ||
return "THREE" | ||
case Quorum: | ||
return "QUORUM" | ||
case All: | ||
return "ALL" | ||
case LocalQuorum: | ||
return "LOCAL_QUORUM" | ||
case EachQuorum: | ||
return "EACH_QUORUM" | ||
case LocalOne: | ||
return "LOCAL_ONE" | ||
default: | ||
return fmt.Sprintf("UNKNOWN_CONS_0x%x", uint16(c)) | ||
} | ||
} | ||
|
||
func (c Consistency) MarshalText() (text []byte, err error) { | ||
return []byte(c.String()), nil | ||
} | ||
|
||
func (c *Consistency) UnmarshalText(text []byte) error { | ||
switch string(text) { | ||
case "ANY": | ||
*c = Any | ||
case "ONE": | ||
*c = One | ||
case "TWO": | ||
*c = Two | ||
case "THREE": | ||
*c = Three | ||
case "QUORUM": | ||
*c = Quorum | ||
case "ALL": | ||
*c = All | ||
case "LOCAL_QUORUM": | ||
*c = LocalQuorum | ||
case "EACH_QUORUM": | ||
*c = EachQuorum | ||
case "LOCAL_ONE": | ||
*c = LocalOne | ||
default: | ||
return fmt.Errorf("invalid consistency %q", string(text)) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func ParseConsistency(s string) Consistency { | ||
var c Consistency | ||
if err := c.UnmarshalText([]byte(strings.ToUpper(s))); err != nil { | ||
panic(err) | ||
} | ||
return c | ||
} | ||
|
||
// ParseConsistencyWrapper wraps gocql.ParseConsistency to provide an err | ||
// return instead of a panic | ||
func ParseConsistencyWrapper(s string) (consistency Consistency, err error) { | ||
err = consistency.UnmarshalText([]byte(strings.ToUpper(s))) | ||
return | ||
} | ||
|
||
// MustParseConsistency is the same as ParseConsistency except it returns | ||
// an error (never). It is kept here since breaking changes are not good. | ||
// DEPRECATED: use ParseConsistency if you want a panic on parse error. | ||
func MustParseConsistency(s string) (Consistency, error) { | ||
c, err := ParseConsistencyWrapper(s) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return c, nil | ||
} | ||
|
||
type SerialConsistency uint16 | ||
|
||
const ( | ||
Serial SerialConsistency = 0x08 | ||
LocalSerial SerialConsistency = 0x09 | ||
) | ||
|
||
func (s SerialConsistency) String() string { | ||
switch s { | ||
case Serial: | ||
return "SERIAL" | ||
case LocalSerial: | ||
return "LOCAL_SERIAL" | ||
default: | ||
return fmt.Sprintf("UNKNOWN_SERIAL_CONS_0x%x", uint16(s)) | ||
} | ||
} | ||
|
||
func (s SerialConsistency) MarshalText() (text []byte, err error) { | ||
return []byte(s.String()), nil | ||
} | ||
|
||
func (s *SerialConsistency) UnmarshalText(text []byte) error { | ||
switch string(text) { | ||
case "SERIAL": | ||
*s = Serial | ||
case "LOCAL_SERIAL": | ||
*s = LocalSerial | ||
default: | ||
return fmt.Errorf("invalid consistency %q", string(text)) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.