Add key type for rules

This commit is contained in:
Tobie Morgan Hitchcock 2016-09-06 13:27:59 +01:00
parent 33ef395d5b
commit d76038652b
2 changed files with 95 additions and 35 deletions

View file

@ -87,6 +87,11 @@ func TestMain(t *testing.T) {
obj: &FD{KV: "surreal", NS: "abcum", DB: "database", TB: "person", FD: "fullname"},
new: &FD{},
},
{
str: "/surreal/!/r/abcum/database/person/select",
obj: &RU{KV: "surreal", NS: "abcum", DB: "database", TB: "person", RU: "select"},
new: &RU{},
},
{
str: "/surreal/!/i/abcum/database/person/teenagers",
obj: &IX{KV: "surreal", NS: "abcum", DB: "database", TB: "person", IX: "teenagers"},
@ -162,33 +167,33 @@ func TestMain(t *testing.T) {
obj: &Point{KV: "surreal", NS: "abcum", DB: "database", TB: "person", IX: "uniqs", FD: []interface{}{false, "account:1", "lastname", nil, "firstname"}, ID: "873c2f37-ea03-4c5e-843e-cf393af44155"},
new: &Point{},
},
/*{
{
str: "Test key",
new: &Full{},
obj: &Full{
N: nil,
B: true,
F: false,
S: "Test",
T: clock,
N64: -9223372036854775807,
N32: -2147483647,
N16: -32767,
N8: -127,
I: 1,
I8: 127,
I16: 32767,
I32: 2147483647,
I64: 9223372036854775807,
UI: 1,
UI8: 255,
UI16: 65535,
UI32: 4294967295,
UI64: 18446744073709551615,
NF32: -0.00001,
NF64: -0.00002,
F32: 0.00001,
F64: 0.00002,
N: nil,
B: true,
F: false,
S: "Test",
T: clock,
N64: -9223372036854775807,
N32: -2147483647,
N16: -32767,
N8: -127,
I: 1,
I8: 127,
I16: 32767,
I32: 2147483647,
I64: 9223372036854775807,
UI: 1,
UI8: 255,
UI16: 65535,
UI32: 4294967295,
UI64: 18446744073709551615,
// NF32: -0.00001,
// NF64: -0.00002,
// F32: 0.00001,
// F64: 0.00002,
AB: []bool{true, false},
AS: []string{"A", "B", "C"},
AI8: []int8{127},
@ -199,18 +204,18 @@ func TestMain(t *testing.T) {
AUI16: []uint16{32767},
AUI32: []uint32{2147483647},
AUI64: []uint64{9223372036854775807},
AF32: []float32{0.1, 0.2, 0.3},
AF64: []float64{0.1, 0.2, 0.3},
IN: "Test",
IB: true,
IF: false,
IT: clock,
II: int64(19387),
ID: float64(183784.13413),
INA: []interface{}{true, false, nil, "Test", clock, int64(192), 0.1, 0.2, 0.3},
AIN: []interface{}{true, false, nil, "Test", clock, int64(192), int64(9223372036854775807), 0.1, 0.2, 0.3},
// AF32: []float32{0.1, 0.2, 0.3},
// AF64: []float64{0.1, 0.2, 0.3},
IN: "Test",
IB: true,
IF: false,
IT: clock,
II: int64(19387),
// ID: float64(183784.13413),
// INA: []interface{}{true, false, nil, "Test", clock, int64(192), 0.1, 0.2, 0.3},
// AIN: []interface{}{true, false, nil, "Test", clock, int64(192), int64(9223372036854775807), 0.1, 0.2, 0.3},
},
},*/
},
}
sorts = []Key{

55
util/keys/ru.go Normal file
View file

@ -0,0 +1,55 @@
// Copyright © 2016 Abcum Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package keys
import (
"fmt"
)
// RU ...
type RU struct {
KV interface{}
CF interface{}
TK interface{}
NS interface{}
DB interface{}
TB interface{}
RU interface{}
}
// init initialises the key
func (k *RU) init() *RU {
k.CF = "!"
k.TK = "r"
return k
}
// Encode encodes the key into binary
func (k *RU) Encode() []byte {
k.init()
return encode(k.KV, k.CF, k.TK, k.NS, k.DB, k.TB, k.RU)
}
// Decode decodes the key from binary
func (k *RU) Decode(data []byte) {
k.init()
decode(data, &k.KV, &k.CF, &k.TK, &k.NS, &k.DB, &k.TB, &k.RU)
}
// String returns a string representation of the key
func (k *RU) String() string {
k.init()
return fmt.Sprintf("/%s/%s/%s/%s/%s/%s/%s", k.KV, k.CF, k.TK, k.NS, k.DB, k.TB, k.RU)
}