forked from apache/cassandra-gocql-driver
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolve conversations for serialization.Set
- Loading branch information
Showing
14 changed files
with
224 additions
and
266 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package funcs | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"gopkg.in/inf.v0" | ||
"math/big" | ||
"reflect" | ||
"unsafe" | ||
|
||
"github.com/gocql/gocql/marshal/tests/mod" | ||
) | ||
|
||
func EqualData(in1, in2 []byte) bool { | ||
if in1 == nil || in2 == nil { | ||
return in1 == nil && in2 == nil | ||
} | ||
return bytes.Equal(in1, in2) | ||
} | ||
|
||
func EqualVals(in1, in2 interface{}) bool { | ||
rin1 := reflect.ValueOf(in1) | ||
rin2 := reflect.ValueOf(in2) | ||
if rin1.Kind() == reflect.Ptr && (rin1.IsNil() || rin2.IsNil()) { | ||
return rin1.IsNil() && rin2.IsNil() | ||
} | ||
|
||
switch vin1 := in1.(type) { | ||
case float32: | ||
vin2 := in2.(float32) | ||
return *(*[4]byte)(unsafe.Pointer(&vin1)) == *(*[4]byte)(unsafe.Pointer(&vin2)) | ||
case *float32: | ||
vin2 := in2.(*float32) | ||
return *(*[4]byte)(unsafe.Pointer(vin1)) == *(*[4]byte)(unsafe.Pointer(vin2)) | ||
case *mod.Float32: | ||
vin2 := in2.(*mod.Float32) | ||
return *(*[4]byte)(unsafe.Pointer(vin1)) == *(*[4]byte)(unsafe.Pointer(vin2)) | ||
case mod.Float32: | ||
vin2 := in2.(mod.Float32) | ||
return *(*[4]byte)(unsafe.Pointer(&vin1)) == *(*[4]byte)(unsafe.Pointer(&vin2)) | ||
case float64: | ||
vin2 := in2.(float64) | ||
return *(*[8]byte)(unsafe.Pointer(&vin1)) == *(*[8]byte)(unsafe.Pointer(&vin2)) | ||
case *float64: | ||
vin2 := in2.(*float64) | ||
return *(*[8]byte)(unsafe.Pointer(vin1)) == *(*[8]byte)(unsafe.Pointer(vin2)) | ||
case *mod.Float64: | ||
vin2 := in2.(*mod.Float64) | ||
return *(*[8]byte)(unsafe.Pointer(vin1)) == *(*[8]byte)(unsafe.Pointer(vin2)) | ||
case mod.Float64: | ||
vin2 := in2.(mod.Float64) | ||
return *(*[8]byte)(unsafe.Pointer(&vin1)) == *(*[8]byte)(unsafe.Pointer(&vin2)) | ||
case big.Int: | ||
vin2 := in2.(big.Int) | ||
return vin1.Cmp(&vin2) == 0 | ||
case *big.Int: | ||
vin2 := in2.(*big.Int) | ||
return vin1.Cmp(vin2) == 0 | ||
case inf.Dec: | ||
vin2 := in2.(inf.Dec) | ||
return vin1.Cmp(&vin2) == 0 | ||
case *inf.Dec: | ||
vin2 := in2.(*inf.Dec) | ||
return vin1.Cmp(vin2) == 0 | ||
case fmt.Stringer: | ||
vin2 := in2.(fmt.Stringer) | ||
return vin1.String() == vin2.String() | ||
default: | ||
return reflect.DeepEqual(in1, in2) | ||
} | ||
} |
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,23 @@ | ||
package funcs | ||
|
||
import ( | ||
"reflect" | ||
) | ||
|
||
func New(in interface{}) interface{} { | ||
return getNew(reflect.ValueOf(in)) | ||
} | ||
|
||
func getNew(orig reflect.Value) reflect.Value { | ||
if orig.Kind() != reflect.Ptr { | ||
return reflect.Zero(orig.Type()) | ||
} | ||
if orig.IsNil() { | ||
return reflect.Zero(orig.Type()) | ||
} else if orig.IsZero() { | ||
return reflect.Zero(orig.Type()) | ||
} | ||
newVal := reflect.New(orig.Type().Elem()) | ||
newVal.Elem().Set(getNew(orig.Elem())) | ||
return newVal | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,18 +1,22 @@ | ||
package mod | ||
|
||
var All = Mods{IntoCustom, IntoRef, IntoCustomRef} | ||
|
||
type Mods []Mod | ||
|
||
// Mod - value modifiers. | ||
// Designed for test case generators, such as gen.Group, marshal.Group and unmarshal.Group. | ||
type Mod interface { | ||
Name() string | ||
Apply([]interface{}) []interface{} | ||
type Mod func(vals ...interface{}) []interface{} | ||
|
||
func To(vals ...interface{}) Vals { | ||
return vals | ||
} | ||
|
||
var ( | ||
IntoCustom intoCustom | ||
IntoRef intoRef | ||
IntoCustomRef intoCustomRef | ||
type Vals []interface{} | ||
|
||
All = Mods{IntoCustom, IntoRef, IntoCustomRef} | ||
) | ||
func (v Vals) AddVariants(mods ...Mod) Vals { | ||
out := append(make([]interface{}, 0), v...) | ||
for _, mod := range mods { | ||
out = append(out, mod(v...)...) | ||
} | ||
return out | ||
} |
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 |
---|---|---|
@@ -1,12 +1,5 @@ | ||
package mod | ||
|
||
type intoCustomRef struct{} | ||
|
||
func (m intoCustomRef) Name() string { | ||
return "*custom" | ||
} | ||
|
||
func (m intoCustomRef) Apply(vals []interface{}) []interface{} { | ||
custom := intoCustom{}.Apply(vals) | ||
return intoRef{}.Apply(custom) | ||
var IntoCustomRef Mod = func(vals ...interface{}) []interface{} { | ||
return IntoRef(IntoCustom(vals...)...) | ||
} |
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
Oops, something went wrong.