|
|
@@ -16,47 +16,47 @@ import (
|
|
|
)
|
|
|
|
|
|
var marshalTests = []struct {
|
|
|
- Info *TypeInfo
|
|
|
+ Info TypeInfo
|
|
|
Data []byte
|
|
|
Value interface{}
|
|
|
}{
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeVarchar},
|
|
|
+ NativeType{proto: 2, typ: TypeVarchar},
|
|
|
[]byte("hello world"),
|
|
|
[]byte("hello world"),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeVarchar},
|
|
|
+ NativeType{proto: 2, typ: TypeVarchar},
|
|
|
[]byte("hello world"),
|
|
|
"hello world",
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeVarchar},
|
|
|
+ NativeType{proto: 2, typ: TypeVarchar},
|
|
|
[]byte(nil),
|
|
|
[]byte(nil),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeVarchar},
|
|
|
+ NativeType{proto: 2, typ: TypeVarchar},
|
|
|
[]byte("hello world"),
|
|
|
MyString("hello world"),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeVarchar},
|
|
|
+ NativeType{proto: 2, typ: TypeVarchar},
|
|
|
[]byte("HELLO WORLD"),
|
|
|
CustomString("hello world"),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeBlob},
|
|
|
+ NativeType{proto: 2, typ: TypeBlob},
|
|
|
[]byte("hello\x00"),
|
|
|
[]byte("hello\x00"),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeBlob},
|
|
|
+ NativeType{proto: 2, typ: TypeBlob},
|
|
|
[]byte(nil),
|
|
|
[]byte(nil),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeTimeUUID},
|
|
|
+ NativeType{proto: 2, typ: TypeTimeUUID},
|
|
|
[]byte{0x3d, 0xcd, 0x98, 0x0, 0xf3, 0xd9, 0x11, 0xbf, 0x86, 0xd4, 0xb8, 0xe8, 0x56, 0x2c, 0xc, 0xd0},
|
|
|
func() UUID {
|
|
|
x, _ := UUIDFromBytes([]byte{0x3d, 0xcd, 0x98, 0x0, 0xf3, 0xd9, 0x11, 0xbf, 0x86, 0xd4, 0xb8, 0xe8, 0x56, 0x2c, 0xc, 0xd0})
|
|
|
@@ -64,217 +64,235 @@ var marshalTests = []struct {
|
|
|
}(),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInt},
|
|
|
+ NativeType{proto: 2, typ: TypeInt},
|
|
|
[]byte("\x00\x00\x00\x00"),
|
|
|
0,
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInt},
|
|
|
+ NativeType{proto: 2, typ: TypeInt},
|
|
|
[]byte("\x01\x02\x03\x04"),
|
|
|
int(16909060),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInt},
|
|
|
+ NativeType{proto: 2, typ: TypeInt},
|
|
|
[]byte("\x80\x00\x00\x00"),
|
|
|
int32(math.MinInt32),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInt},
|
|
|
+ NativeType{proto: 2, typ: TypeInt},
|
|
|
[]byte("\x7f\xff\xff\xff"),
|
|
|
int32(math.MaxInt32),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInt},
|
|
|
+ NativeType{proto: 2, typ: TypeInt},
|
|
|
[]byte("\x00\x00\x00\x00"),
|
|
|
"0",
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInt},
|
|
|
+ NativeType{proto: 2, typ: TypeInt},
|
|
|
[]byte("\x01\x02\x03\x04"),
|
|
|
"16909060",
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInt},
|
|
|
+ NativeType{proto: 2, typ: TypeInt},
|
|
|
[]byte("\x80\x00\x00\x00"),
|
|
|
"-2147483648", // math.MinInt32
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInt},
|
|
|
+ NativeType{proto: 2, typ: TypeInt},
|
|
|
[]byte("\x7f\xff\xff\xff"),
|
|
|
"2147483647", // math.MaxInt32
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeBigInt},
|
|
|
+ NativeType{proto: 2, typ: TypeBigInt},
|
|
|
[]byte("\x00\x00\x00\x00\x00\x00\x00\x00"),
|
|
|
0,
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeBigInt},
|
|
|
+ NativeType{proto: 2, typ: TypeBigInt},
|
|
|
[]byte("\x01\x02\x03\x04\x05\x06\x07\x08"),
|
|
|
72623859790382856,
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeBigInt},
|
|
|
+ NativeType{proto: 2, typ: TypeBigInt},
|
|
|
[]byte("\x80\x00\x00\x00\x00\x00\x00\x00"),
|
|
|
int64(math.MinInt64),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeBigInt},
|
|
|
+ NativeType{proto: 2, typ: TypeBigInt},
|
|
|
[]byte("\x7f\xff\xff\xff\xff\xff\xff\xff"),
|
|
|
int64(math.MaxInt64),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeBigInt},
|
|
|
+ NativeType{proto: 2, typ: TypeBigInt},
|
|
|
[]byte("\x00\x00\x00\x00\x00\x00\x00\x00"),
|
|
|
"0",
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeBigInt},
|
|
|
+ NativeType{proto: 2, typ: TypeBigInt},
|
|
|
[]byte("\x01\x02\x03\x04\x05\x06\x07\x08"),
|
|
|
"72623859790382856",
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeBigInt},
|
|
|
+ NativeType{proto: 2, typ: TypeBigInt},
|
|
|
[]byte("\x80\x00\x00\x00\x00\x00\x00\x00"),
|
|
|
"-9223372036854775808", // math.MinInt64
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeBigInt},
|
|
|
+ NativeType{proto: 2, typ: TypeBigInt},
|
|
|
[]byte("\x7f\xff\xff\xff\xff\xff\xff\xff"),
|
|
|
"9223372036854775807", // math.MaxInt64
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeBoolean},
|
|
|
+ NativeType{proto: 2, typ: TypeBoolean},
|
|
|
[]byte("\x00"),
|
|
|
false,
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeBoolean},
|
|
|
+ NativeType{proto: 2, typ: TypeBoolean},
|
|
|
[]byte("\x01"),
|
|
|
true,
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeFloat},
|
|
|
+ NativeType{proto: 2, typ: TypeFloat},
|
|
|
[]byte("\x40\x49\x0f\xdb"),
|
|
|
float32(3.14159265),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeDouble},
|
|
|
+ NativeType{proto: 2, typ: TypeDouble},
|
|
|
[]byte("\x40\x09\x21\xfb\x53\xc8\xd4\xf1"),
|
|
|
float64(3.14159265),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeDecimal},
|
|
|
+ NativeType{proto: 2, typ: TypeDecimal},
|
|
|
[]byte("\x00\x00\x00\x00\x00"),
|
|
|
inf.NewDec(0, 0),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeDecimal},
|
|
|
+ NativeType{proto: 2, typ: TypeDecimal},
|
|
|
[]byte("\x00\x00\x00\x00\x64"),
|
|
|
inf.NewDec(100, 0),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeDecimal},
|
|
|
+ NativeType{proto: 2, typ: TypeDecimal},
|
|
|
[]byte("\x00\x00\x00\x02\x19"),
|
|
|
decimalize("0.25"),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeDecimal},
|
|
|
+ NativeType{proto: 2, typ: TypeDecimal},
|
|
|
[]byte("\x00\x00\x00\x13\xD5\a;\x20\x14\xA2\x91"),
|
|
|
decimalize("-0.0012095473475870063"), // From the iconara/cql-rb test suite
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeDecimal},
|
|
|
+ NativeType{proto: 2, typ: TypeDecimal},
|
|
|
[]byte("\x00\x00\x00\x13*\xF8\xC4\xDF\xEB]o"),
|
|
|
decimalize("0.0012095473475870063"), // From the iconara/cql-rb test suite
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeDecimal},
|
|
|
+ NativeType{proto: 2, typ: TypeDecimal},
|
|
|
[]byte("\x00\x00\x00\x12\xF2\xD8\x02\xB6R\x7F\x99\xEE\x98#\x99\xA9V"),
|
|
|
decimalize("-1042342234234.123423435647768234"), // From the iconara/cql-rb test suite
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeDecimal},
|
|
|
+ NativeType{proto: 2, typ: TypeDecimal},
|
|
|
[]byte("\x00\x00\x00\r\nJ\x04\"^\x91\x04\x8a\xb1\x18\xfe"),
|
|
|
decimalize("1243878957943.1234124191998"), // From the datastax/python-driver test suite
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeDecimal},
|
|
|
+ NativeType{proto: 2, typ: TypeDecimal},
|
|
|
[]byte("\x00\x00\x00\x06\xe5\xde]\x98Y"),
|
|
|
decimalize("-112233.441191"), // From the datastax/python-driver test suite
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeDecimal},
|
|
|
+ NativeType{proto: 2, typ: TypeDecimal},
|
|
|
[]byte("\x00\x00\x00\x14\x00\xfa\xce"),
|
|
|
decimalize("0.00000000000000064206"), // From the datastax/python-driver test suite
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeDecimal},
|
|
|
+ NativeType{proto: 2, typ: TypeDecimal},
|
|
|
[]byte("\x00\x00\x00\x14\xff\x052"),
|
|
|
decimalize("-0.00000000000000064206"), // From the datastax/python-driver test suite
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeDecimal},
|
|
|
+ NativeType{proto: 2, typ: TypeDecimal},
|
|
|
[]byte("\xff\xff\xff\x9c\x00\xfa\xce"),
|
|
|
inf.NewDec(64206, -100), // From the datastax/python-driver test suite
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeTimestamp},
|
|
|
+ NativeType{proto: 2, typ: TypeTimestamp},
|
|
|
[]byte("\x00\x00\x01\x40\x77\x16\xe1\xb8"),
|
|
|
time.Date(2013, time.August, 13, 9, 52, 3, 0, time.UTC),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeTimestamp},
|
|
|
+ NativeType{proto: 2, typ: TypeTimestamp},
|
|
|
[]byte("\x00\x00\x01\x40\x77\x16\xe1\xb8"),
|
|
|
int64(1376387523000),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeList, Elem: &TypeInfo{Proto: 2, Type: TypeInt}},
|
|
|
+ CollectionType{
|
|
|
+ NativeType: NativeType{proto: 2, typ: TypeList},
|
|
|
+ Elem: NativeType{proto: 2, typ: TypeInt},
|
|
|
+ },
|
|
|
[]byte("\x00\x02\x00\x04\x00\x00\x00\x01\x00\x04\x00\x00\x00\x02"),
|
|
|
[]int{1, 2},
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeList, Elem: &TypeInfo{Proto: 2, Type: TypeInt}},
|
|
|
+ CollectionType{
|
|
|
+ NativeType: NativeType{proto: 2, typ: TypeList},
|
|
|
+ Elem: NativeType{proto: 2, typ: TypeInt},
|
|
|
+ },
|
|
|
[]byte("\x00\x02\x00\x04\x00\x00\x00\x01\x00\x04\x00\x00\x00\x02"),
|
|
|
[2]int{1, 2},
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeSet, Elem: &TypeInfo{Proto: 2, Type: TypeInt}},
|
|
|
+ CollectionType{
|
|
|
+ NativeType: NativeType{proto: 2, typ: TypeSet},
|
|
|
+ Elem: NativeType{proto: 2, typ: TypeInt},
|
|
|
+ },
|
|
|
[]byte("\x00\x02\x00\x04\x00\x00\x00\x01\x00\x04\x00\x00\x00\x02"),
|
|
|
[]int{1, 2},
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeSet, Elem: &TypeInfo{Proto: 2, Type: TypeInt}},
|
|
|
+ CollectionType{
|
|
|
+ NativeType: NativeType{proto: 2, typ: TypeSet},
|
|
|
+ Elem: NativeType{proto: 2, typ: TypeInt},
|
|
|
+ },
|
|
|
[]byte(nil),
|
|
|
[]int(nil),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeMap,
|
|
|
- Key: &TypeInfo{Proto: 2, Type: TypeVarchar},
|
|
|
- Elem: &TypeInfo{Proto: 2, Type: TypeInt},
|
|
|
+ CollectionType{
|
|
|
+ NativeType: NativeType{proto: 2, typ: TypeMap},
|
|
|
+ Key: NativeType{proto: 2, typ: TypeVarchar},
|
|
|
+ Elem: NativeType{proto: 2, typ: TypeInt},
|
|
|
},
|
|
|
[]byte("\x00\x01\x00\x03foo\x00\x04\x00\x00\x00\x01"),
|
|
|
map[string]int{"foo": 1},
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeMap,
|
|
|
- Key: &TypeInfo{Proto: 2, Type: TypeVarchar},
|
|
|
- Elem: &TypeInfo{Proto: 2, Type: TypeInt},
|
|
|
+ CollectionType{
|
|
|
+ NativeType: NativeType{proto: 2, typ: TypeMap},
|
|
|
+ Key: NativeType{proto: 2, typ: TypeVarchar},
|
|
|
+ Elem: NativeType{proto: 2, typ: TypeInt},
|
|
|
},
|
|
|
[]byte(nil),
|
|
|
map[string]int(nil),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeList, Elem: &TypeInfo{Proto: 2, Type: TypeVarchar}},
|
|
|
+ CollectionType{
|
|
|
+ NativeType: NativeType{proto: 2, typ: TypeList},
|
|
|
+ Elem: NativeType{proto: 2, typ: TypeVarchar},
|
|
|
+ },
|
|
|
bytes.Join([][]byte{
|
|
|
[]byte("\x00\x01\xFF\xFF"),
|
|
|
bytes.Repeat([]byte("X"), 65535)}, []byte("")),
|
|
|
[]string{strings.Repeat("X", 65535)},
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeMap,
|
|
|
- Key: &TypeInfo{Proto: 2, Type: TypeVarchar},
|
|
|
- Elem: &TypeInfo{Proto: 2, Type: TypeVarchar},
|
|
|
+ CollectionType{
|
|
|
+ NativeType: NativeType{proto: 2, typ: TypeMap},
|
|
|
+ Key: NativeType{proto: 2, typ: TypeVarchar},
|
|
|
+ Elem: NativeType{proto: 2, typ: TypeVarchar},
|
|
|
},
|
|
|
bytes.Join([][]byte{
|
|
|
[]byte("\x00\x01\xFF\xFF"),
|
|
|
@@ -286,82 +304,82 @@ var marshalTests = []struct {
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeVarint},
|
|
|
+ NativeType{proto: 2, typ: TypeVarint},
|
|
|
[]byte("\x00"),
|
|
|
0,
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeVarint},
|
|
|
+ NativeType{proto: 2, typ: TypeVarint},
|
|
|
[]byte("\x37\xE2\x3C\xEC"),
|
|
|
int32(937573612),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeVarint},
|
|
|
+ NativeType{proto: 2, typ: TypeVarint},
|
|
|
[]byte("\x37\xE2\x3C\xEC"),
|
|
|
big.NewInt(937573612),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeVarint},
|
|
|
+ NativeType{proto: 2, typ: TypeVarint},
|
|
|
[]byte("\x03\x9EV \x15\f\x03\x9DK\x18\xCDI\\$?\a["),
|
|
|
bigintize("1231312312331283012830129382342342412123"), // From the iconara/cql-rb test suite
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeVarint},
|
|
|
+ NativeType{proto: 2, typ: TypeVarint},
|
|
|
[]byte("\xC9v\x8D:\x86"),
|
|
|
big.NewInt(-234234234234), // From the iconara/cql-rb test suite
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeVarint},
|
|
|
+ NativeType{proto: 2, typ: TypeVarint},
|
|
|
[]byte("f\x1e\xfd\xf2\xe3\xb1\x9f|\x04_\x15"),
|
|
|
bigintize("123456789123456789123456789"), // From the datastax/python-driver test suite
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInet},
|
|
|
+ NativeType{proto: 2, typ: TypeInet},
|
|
|
[]byte("\x7F\x00\x00\x01"),
|
|
|
net.ParseIP("127.0.0.1").To4(),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInet},
|
|
|
+ NativeType{proto: 2, typ: TypeInet},
|
|
|
[]byte("\xFF\xFF\xFF\xFF"),
|
|
|
net.ParseIP("255.255.255.255").To4(),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInet},
|
|
|
+ NativeType{proto: 2, typ: TypeInet},
|
|
|
[]byte("\x7F\x00\x00\x01"),
|
|
|
"127.0.0.1",
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInet},
|
|
|
+ NativeType{proto: 2, typ: TypeInet},
|
|
|
[]byte("\xFF\xFF\xFF\xFF"),
|
|
|
"255.255.255.255",
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInet},
|
|
|
+ NativeType{proto: 2, typ: TypeInet},
|
|
|
[]byte("\x21\xDA\x00\xd3\x00\x00\x2f\x3b\x02\xaa\x00\xff\xfe\x28\x9c\x5a"),
|
|
|
"21da:d3:0:2f3b:2aa:ff:fe28:9c5a",
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInet},
|
|
|
+ NativeType{proto: 2, typ: TypeInet},
|
|
|
[]byte("\xfe\x80\x00\x00\x00\x00\x00\x00\x02\x02\xb3\xff\xfe\x1e\x83\x29"),
|
|
|
"fe80::202:b3ff:fe1e:8329",
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInet},
|
|
|
+ NativeType{proto: 2, typ: TypeInet},
|
|
|
[]byte("\x21\xDA\x00\xd3\x00\x00\x2f\x3b\x02\xaa\x00\xff\xfe\x28\x9c\x5a"),
|
|
|
net.ParseIP("21da:d3:0:2f3b:2aa:ff:fe28:9c5a"),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInet},
|
|
|
+ NativeType{proto: 2, typ: TypeInet},
|
|
|
[]byte("\xfe\x80\x00\x00\x00\x00\x00\x00\x02\x02\xb3\xff\xfe\x1e\x83\x29"),
|
|
|
net.ParseIP("fe80::202:b3ff:fe1e:8329"),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInt},
|
|
|
+ NativeType{proto: 2, typ: TypeInt},
|
|
|
[]byte(nil),
|
|
|
nil,
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeVarchar},
|
|
|
+ NativeType{proto: 2, typ: TypeVarchar},
|
|
|
[]byte("nullable string"),
|
|
|
func() *string {
|
|
|
value := "nullable string"
|
|
|
@@ -369,12 +387,12 @@ var marshalTests = []struct {
|
|
|
}(),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeVarchar},
|
|
|
+ NativeType{proto: 2, typ: TypeVarchar},
|
|
|
[]byte{},
|
|
|
(*string)(nil),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInt},
|
|
|
+ NativeType{proto: 2, typ: TypeInt},
|
|
|
[]byte("\x7f\xff\xff\xff"),
|
|
|
func() *int {
|
|
|
var value int = math.MaxInt32
|
|
|
@@ -382,22 +400,22 @@ var marshalTests = []struct {
|
|
|
}(),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInt},
|
|
|
+ NativeType{proto: 2, typ: TypeInt},
|
|
|
[]byte(nil),
|
|
|
(*int)(nil),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeTimeUUID},
|
|
|
+ NativeType{proto: 2, typ: TypeTimeUUID},
|
|
|
[]byte{0x3d, 0xcd, 0x98, 0x0, 0xf3, 0xd9, 0x11, 0xbf, 0x86, 0xd4, 0xb8, 0xe8, 0x56, 0x2c, 0xc, 0xd0},
|
|
|
&UUID{0x3d, 0xcd, 0x98, 0x0, 0xf3, 0xd9, 0x11, 0xbf, 0x86, 0xd4, 0xb8, 0xe8, 0x56, 0x2c, 0xc, 0xd0},
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeTimeUUID},
|
|
|
+ NativeType{proto: 2, typ: TypeTimeUUID},
|
|
|
[]byte{},
|
|
|
(*UUID)(nil),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeTimestamp},
|
|
|
+ NativeType{proto: 2, typ: TypeTimestamp},
|
|
|
[]byte("\x00\x00\x01\x40\x77\x16\xe1\xb8"),
|
|
|
func() *time.Time {
|
|
|
t := time.Date(2013, time.August, 13, 9, 52, 3, 0, time.UTC)
|
|
|
@@ -405,12 +423,12 @@ var marshalTests = []struct {
|
|
|
}(),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeTimestamp},
|
|
|
+ NativeType{proto: 2, typ: TypeTimestamp},
|
|
|
[]byte(nil),
|
|
|
(*time.Time)(nil),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeBoolean},
|
|
|
+ NativeType{proto: 2, typ: TypeBoolean},
|
|
|
[]byte("\x00"),
|
|
|
func() *bool {
|
|
|
b := false
|
|
|
@@ -418,7 +436,7 @@ var marshalTests = []struct {
|
|
|
}(),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeBoolean},
|
|
|
+ NativeType{proto: 2, typ: TypeBoolean},
|
|
|
[]byte("\x01"),
|
|
|
func() *bool {
|
|
|
b := true
|
|
|
@@ -426,12 +444,12 @@ var marshalTests = []struct {
|
|
|
}(),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeBoolean},
|
|
|
+ NativeType{proto: 2, typ: TypeBoolean},
|
|
|
[]byte(nil),
|
|
|
(*bool)(nil),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeFloat},
|
|
|
+ NativeType{proto: 2, typ: TypeFloat},
|
|
|
[]byte("\x40\x49\x0f\xdb"),
|
|
|
func() *float32 {
|
|
|
f := float32(3.14159265)
|
|
|
@@ -439,12 +457,12 @@ var marshalTests = []struct {
|
|
|
}(),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeFloat},
|
|
|
+ NativeType{proto: 2, typ: TypeFloat},
|
|
|
[]byte(nil),
|
|
|
(*float32)(nil),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeDouble},
|
|
|
+ NativeType{proto: 2, typ: TypeDouble},
|
|
|
[]byte("\x40\x09\x21\xfb\x53\xc8\xd4\xf1"),
|
|
|
func() *float64 {
|
|
|
d := float64(3.14159265)
|
|
|
@@ -452,12 +470,12 @@ var marshalTests = []struct {
|
|
|
}(),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeDouble},
|
|
|
+ NativeType{proto: 2, typ: TypeDouble},
|
|
|
[]byte(nil),
|
|
|
(*float64)(nil),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInet},
|
|
|
+ NativeType{proto: 2, typ: TypeInet},
|
|
|
[]byte("\x7F\x00\x00\x01"),
|
|
|
func() *net.IP {
|
|
|
ip := net.ParseIP("127.0.0.1").To4()
|
|
|
@@ -465,12 +483,15 @@ var marshalTests = []struct {
|
|
|
}(),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeInet},
|
|
|
+ NativeType{proto: 2, typ: TypeInet},
|
|
|
[]byte(nil),
|
|
|
(*net.IP)(nil),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeList, Elem: &TypeInfo{Proto: 2, Type: TypeInt}},
|
|
|
+ CollectionType{
|
|
|
+ NativeType: NativeType{proto: 2, typ: TypeList},
|
|
|
+ Elem: NativeType{proto: 2, typ: TypeInt},
|
|
|
+ },
|
|
|
[]byte("\x00\x02\x00\x04\x00\x00\x00\x01\x00\x04\x00\x00\x00\x02"),
|
|
|
func() *[]int {
|
|
|
l := []int{1, 2}
|
|
|
@@ -478,14 +499,18 @@ var marshalTests = []struct {
|
|
|
}(),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeList, Elem: &TypeInfo{Proto: 2, Type: TypeInt}},
|
|
|
+ CollectionType{
|
|
|
+ NativeType: NativeType{proto: 2, typ: TypeList},
|
|
|
+ Elem: NativeType{proto: 2, typ: TypeInt},
|
|
|
+ },
|
|
|
[]byte(nil),
|
|
|
(*[]int)(nil),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeMap,
|
|
|
- Key: &TypeInfo{Proto: 2, Type: TypeVarchar},
|
|
|
- Elem: &TypeInfo{Proto: 2, Type: TypeInt},
|
|
|
+ CollectionType{
|
|
|
+ NativeType: NativeType{proto: 2, typ: TypeMap},
|
|
|
+ Key: NativeType{proto: 2, typ: TypeVarchar},
|
|
|
+ Elem: NativeType{proto: 2, typ: TypeInt},
|
|
|
},
|
|
|
[]byte("\x00\x01\x00\x03foo\x00\x04\x00\x00\x00\x01"),
|
|
|
func() *map[string]int {
|
|
|
@@ -494,9 +519,10 @@ var marshalTests = []struct {
|
|
|
}(),
|
|
|
},
|
|
|
{
|
|
|
- &TypeInfo{Proto: 2, Type: TypeMap,
|
|
|
- Key: &TypeInfo{Proto: 2, Type: TypeVarchar},
|
|
|
- Elem: &TypeInfo{Proto: 2, Type: TypeInt},
|
|
|
+ CollectionType{
|
|
|
+ NativeType: NativeType{proto: 2, typ: TypeMap},
|
|
|
+ Key: NativeType{proto: 2, typ: TypeVarchar},
|
|
|
+ Elem: NativeType{proto: 2, typ: TypeInt},
|
|
|
},
|
|
|
[]byte(nil),
|
|
|
(*map[string]int)(nil),
|
|
|
@@ -610,7 +636,7 @@ func TestMarshalVarint(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
for i, test := range varintTests {
|
|
|
- data, err := Marshal(&TypeInfo{Proto: 2, Type: TypeVarint}, test.Value)
|
|
|
+ data, err := Marshal(NativeType{proto: 2, typ: TypeVarint}, test.Value)
|
|
|
if err != nil {
|
|
|
t.Errorf("error marshaling varint: %v (test #%d)", err, i)
|
|
|
}
|
|
|
@@ -620,7 +646,7 @@ func TestMarshalVarint(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
binder := new(big.Int)
|
|
|
- err = Unmarshal(&TypeInfo{Proto: 2, Type: TypeVarint}, test.Marshaled, binder)
|
|
|
+ err = Unmarshal(NativeType{proto: 2, typ: TypeVarint}, test.Marshaled, binder)
|
|
|
if err != nil {
|
|
|
t.Errorf("error unmarshaling varint: %v (test #%d)", err, i)
|
|
|
}
|
|
|
@@ -633,10 +659,10 @@ func TestMarshalVarint(t *testing.T) {
|
|
|
|
|
|
type CustomString string
|
|
|
|
|
|
-func (c CustomString) MarshalCQL(info *TypeInfo) ([]byte, error) {
|
|
|
+func (c CustomString) MarshalCQL(info TypeInfo) ([]byte, error) {
|
|
|
return []byte(strings.ToUpper(string(c))), nil
|
|
|
}
|
|
|
-func (c *CustomString) UnmarshalCQL(info *TypeInfo, data []byte) error {
|
|
|
+func (c *CustomString) UnmarshalCQL(info TypeInfo, data []byte) error {
|
|
|
*c = CustomString(strings.ToLower(string(data)))
|
|
|
return nil
|
|
|
}
|