Documentation
¶
Overview ¶
Package kdb implements encoding and decoding of q ipc message format
Index ¶
- Constants
- Variables
- func Encode(w io.Writer, msgtype int, data *K) (err error)
- func HandleClientConnection(conn net.Conn)
- func UnmarshalDict(t Dict, v interface{}) error
- func UnmarshalDictToMap(t Dict, v interface{}) error
- func UnmarshalTable(t Table, v interface{}) (interface{}, error)
- type Attr
- type Dict
- type Function
- type K
- func Atom(t int8, x interface{}) *K
- func Decode(src *bufio.Reader) (data *K, msgtype int, e error)
- func Error(x error) *K
- func Float(x float64) *K
- func Int(x int32) *K
- func Long(x int64) *K
- func NewDict(k, v *K) *K
- func NewFunc(ctx, body string) *K
- func NewList(x ...*K) *K
- func NewTable(cols []string, data []*K) *K
- func Real(x float32) *K
- func Symbol(x string) *K
- func SymbolV(x []string) *K
- type KDBConn
- func (c *KDBConn) AsyncCall(cmd string, args ...*K) (err error)
- func (c *KDBConn) Call(cmd string, args ...*K) (data *K, err error)
- func (c *KDBConn) Close() error
- func (c *KDBConn) ReadMessage() (data *K, msgtype int, e error)
- func (c *KDBConn) Response(data *K) (err error)
- func (c *KDBConn) WriteMessage(msgtype int, data *K) (err error)
- type Minute
- type Month
- type Second
- type Table
- type Time
Constants ¶
View Source
const ( ASYNC int = 0 SYNC int = 1 RESPONSE int = 2 )
Request type
View Source
const ( K0 int8 = 0 // generic type // type bytes qtype ctype accessor KB int8 = 1 // 1 boolean char kG UU int8 = 2 // 16 guid U kU KG int8 = 4 // 1 byte char kG KH int8 = 5 // 2 short short kH KI int8 = 6 // 4 int int kI KJ int8 = 7 // 8 long long kJ KE int8 = 8 // 4 real float kE KF int8 = 9 // 8 float double kF KC int8 = 10 // 1 char char kC KS int8 = 11 // * symbol char* kS KP int8 = 12 // 8 timestamp long kJ (nanoseconds from 2000.01.01) KM int8 = 13 // 4 month int kI (months from 2000.01.01) KD int8 = 14 // 4 date int kI (days from 2000.01.01) KZ int8 = 15 // 8 datetime double kF (DO NOT USE) KN int8 = 16 // 8 timespan long kJ (nanoseconds) KU int8 = 17 // 4 minute int kI KV int8 = 18 // 4 second int kI KT int8 = 19 // 4 time int kI (millisecond) // table,dict XT int8 = 98 // x->k is XD XD int8 = 99 // kK(x)[0] is keys. kK(x)[1] is values. SD int8 = 127 // sorted dict // function types KFUNC int8 = 100 KFUNCUP int8 = 101 // unary primitive KFUNCBP int8 = 102 // binary primitive KFUNCTR int8 = 103 // ternary (operator) KPROJ int8 = 104 // projection KCOMP int8 = 105 // composition KEACH int8 = 106 // f' KOVER int8 = 107 // f/ KSCAN int8 = 108 // f\ KPRIOR int8 = 109 // f': KEACHRIGHT int8 = 110 // f/: KEACHLEFT int8 = 111 // f\: KDYNLOAD int8 = 112 // dynamic load // error type KERR int8 = -128 )
View Source
const Nh int16 = math.MinInt16
short nil
View Source
const Ni int32 = math.MinInt32
int nil
View Source
const Nj int64 = math.MinInt64
long nil
View Source
const Wh int16 = math.MaxInt16
short infinity
View Source
const Wi int32 = math.MaxInt32
int infinity
View Source
const Wj int64 = math.MaxInt64
long infinity
Variables ¶
View Source
var ErrBadHeader = errors.New("Bad header")
msg header is invalid
View Source
var ErrBadMsg = errors.New("Bad Message")
message is malformated or invalid
View Source
var ErrSyncRequest = errors.New("nosyncrequest")
Cannot process sync requests
View Source
var Nf float64 = math.NaN()
double nil
View Source
var Wf float64 = math.Inf(1)
double infinity +ve
Functions ¶
func Encode ¶
func compress(b []byte) (dst []byte) {
i := byte(0)
var g int32
//j := int32(len(b))
f, h0, h, g, head := int32(0), int32(0), int32(0), int32(0), int32(17)
dst = make([]byte, len(b)/2)
c := 12
d := c
e := len(dst)
p := 0
q, r, s0 := 0, 0, 0
s := int32(8)
t := int32(len(b))
a := make([]int32, 256)
copy(dst[:4], b[:4])
dst[2] = 1
//dst[8:]=[]byte(strconv.Itoa(int(j)))
for ; s < t; i *= 2 {
if 0 == i {
if d > e-17 {
return b
}
i = 1
dst[c] = byte(f)
c = d
d++
f = 0
}
h = int(b[s] ^ b[s+1])
p = a[h]
g = (s > t-3) || (0 == p) || (0 != (b[s] ^ b[p]))
if 0 < s0 {
a[h0] = s0
s0 = 0
}
if g {
h0 = h
s0 = s
dst[d] = b[s]
d++
s++
} else {
a[h] = s
f |= int32(i)
p += 2
s += 2
r = s
q = min32(s+255, t)
for ; b[p] == b[s] && s < q; s++ {
p++
}
dst[d] = byte(h)
d++
dst[d] = byte(s - r)
d++
}
}
dst[c] = byte(f)
//dst[4:8]=d
return dst
}
Encode data to ipc format as msgtype(sync/async/response) to specified writer
func UnmarshalDictToMap ¶
Unmarshall Q dictionary to map[string]{}interface
func UnmarshalTable ¶
Types ¶
type Dict ¶
Dictionary: ordered key->value mapping. Key and Value should be slices of the same length
type KDBConn ¶
KDBConn establishes connection and communicates using Q IPC protocol
func DialKDBTimeout ¶
Connect to host:port using supplied user:password. Wait timeout for connection
func (*KDBConn) ReadMessage ¶
Read complete message from connection
Click to show internal directories.
Click to hide internal directories.