Browse Source

Merged changes

Adria Casajus 10 years ago
parent
commit
217ded470a
4 changed files with 19 additions and 6 deletions
  1. 1 0
      AUTHORS
  2. 2 2
      compressor.go
  3. 4 4
      compressor_test.go
  4. 12 0
      conn.go

+ 1 - 0
AUTHORS

@@ -50,4 +50,5 @@ Maciek Sakrejda <maciek@heroku.com>
 Jeff Mitchell <jeffrey.mitchell@gmail.com>
 Baptiste Fontaine <b@ptistefontaine.fr>
 Matt Heath <matt@mattheath.com>
+Jamie Cuthill <jamie.cuthill@gmail.com>
 Adrian Casajus <adriancasajus@gmail.com>

+ 2 - 2
compressor.go

@@ -1,7 +1,7 @@
 package gocql
 
 import (
-	"github.com/golang/snappy/snappy"
+	"github.com/golang/snappy"
 )
 
 type Compressor interface {
@@ -20,7 +20,7 @@ func (s SnappyCompressor) Name() string {
 }
 
 func (s SnappyCompressor) Encode(data []byte) ([]byte, error) {
-	return snappy.Encode(nil, data)
+	return snappy.Encode(nil, data), nil
 }
 
 func (s SnappyCompressor) Decode(data []byte) ([]byte, error) {

+ 4 - 4
compressor_test.go

@@ -4,8 +4,9 @@ package gocql
 
 import (
 	"bytes"
-	"github.com/golang/snappy/snappy"
 	"testing"
+
+	"github.com/golang/snappy"
 )
 
 func TestSnappyCompressor(t *testing.T) {
@@ -16,9 +17,8 @@ func TestSnappyCompressor(t *testing.T) {
 
 	str := "My Test String"
 	//Test Encoding
-	if expected, err := snappy.Encode(nil, []byte(str)); err != nil {
-		t.Fatalf("failed to encode '%v' with error %v", str, err)
-	} else if res, err := c.Encode([]byte(str)); err != nil {
+	expected := snappy.Encode(nil, []byte(str))
+	if res, err := c.Encode([]byte(str)); err != nil {
 		t.Fatalf("failed to encode '%v' with error %v", str, err)
 	} else if bytes.Compare(expected, res) != 0 {
 		t.Fatal("failed to match the expected encoded value with the result encoded value.")

+ 12 - 0
conn.go

@@ -10,6 +10,7 @@ import (
 	"errors"
 	"fmt"
 	"io"
+	"io/ioutil"
 	"log"
 	"net"
 	"strconv"
@@ -360,6 +361,17 @@ func (c *Conn) recv() error {
 		return err
 	}
 
+	if head.stream > len(c.calls) {
+		return fmt.Errorf("gocql: frame header stream is beyond call exepected bounds: %d", head.stream)
+	} else if head.stream < 0 {
+		// TODO: handle cassandra event frames, we shouldnt get any currently
+		_, err := io.CopyN(ioutil.Discard, c, int64(head.length))
+		if err != nil {
+			return err
+		}
+		return nil
+	}
+
 	call := &c.calls[head.stream]
 	err = call.framer.readFrame(&head)
 	if err != nil {