Documentation ¶
Overview ¶
Package kdb implements encoding and decoding of q ipc message format
Index ¶
- Constants
- Variables
- func Compress(b []byte) (dst []byte)
- func Decode(src *bufio.Reader) (data *K, msgtype ReqType, e error)
- func Encode(w io.Writer, msgtype ReqType, data *K) error
- func HandleClientConnection(conn net.Conn)
- func Uncompress(b []byte) (dst []byte)
- 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 Date(x time.Time) *K
- func DateV(x []time.Time) *K
- func Error(x error) *K
- func Float(x float64) *K
- func FloatV(x []float64) *K
- func Int(x int32) *K
- func IntV(x []int32) *K
- func Long(x int64) *K
- func LongV(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 RealV(x []float32) *K
- func Symbol(x string) *K
- func SymbolV(x []string) *K
- type KDBConn
- func DialKDB(host string, port int, auth string) (*KDBConn, error)
- func DialKDBTimeout(host string, port int, auth string, timeout time.Duration) (*KDBConn, error)
- func DialTLS(host string, port int, auth string, cfg *tls.Config) (*KDBConn, error)
- func DialUnix(host string, port int, auth string) (*KDBConn, error)
- 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 ReqType, e error)
- func (c *KDBConn) Response(data *K) (err error)
- func (c *KDBConn) WriteMessage(msgtype ReqType, data *K) (err error)
- type Minute
- type Month
- type ReqType
- type Second
- type Table
- type Time
Examples ¶
Constants ¶
const ( ASYNC ReqType = 0 SYNC = 1 RESPONSE = 2 )
Constants for recognised request types
const ( K0 int8 = 0 // generic type // type bytes qtype ctype KB int8 = 1 // 1 boolean char UU int8 = 2 // 16 guid U KG int8 = 4 // 1 byte char KH int8 = 5 // 2 short short KI int8 = 6 // 4 int int KJ int8 = 7 // 8 long long KE int8 = 8 // 4 real float KF int8 = 9 // 8 float double KC int8 = 10 // 1 char char KS int8 = 11 // * symbol char* KP int8 = 12 // 8 timestamp long nanoseconds from 2000.01.01 KM int8 = 13 // 4 month int months from 2000.01.01 KD int8 = 14 // 4 date int days from 2000.01.01 KZ int8 = 15 // 8 datetime double deprecated - DO NOT USE KN int8 = 16 // 8 timespan long nanoseconds KU int8 = 17 // 4 minute int KV int8 = 18 // 4 second int KT int8 = 19 // 4 time int millisecond // table,dict XT int8 = 98 // pointer to dictionary containing string keys(column names) and values XD int8 = 99 // 2 element generic list with 0 as keys and 1 as values SD int8 = 127 // sorted dict - acts as a step function // 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 loaded libraries - not available in IPC // error type KERR int8 = -128 // indicates error with 0 terminated string as a text )
Q type constants
const Nh int16 = math.MinInt16
Nh is a short nil
const Ni int32 = math.MinInt32
Ni is an int nil
const Nj int64 = math.MinInt64
Nj is a long nil
const Wh int16 = math.MaxInt16
Wh is a short infinity
const Wi int32 = math.MaxInt32
Wi is an int infinity
const Wj int64 = math.MaxInt64
Wj is a long infinity
Variables ¶
var ErrBadHeader = errors.New("Bad header")
ErrBadHeader to indicate invalid header
var ErrBadMsg = errors.New("Bad Message")
ErrBadMsg to indicate malformed or invalid message
var ErrSyncRequest = errors.New("nosyncrequest")
ErrSyncRequest cannot process sync requests
var Ne = float32(math.NaN())
Ne is a real nil
var Nf = math.NaN()
Nf is a double nil
var We = float32(math.Inf(+1))
We is a real infinity
var Wf = math.Inf(+1)
Wf is a double infinity
Functions ¶
func Uncompress ¶ added in v0.10.0
Uncompress byte array compressed with Q IPC compression
func UnmarshalDict ¶
UnmarshalDict decodes dict to a struct
func UnmarshalDictToMap ¶
UnmarshalDictToMap decodes dict into map[string]{}interface
func UnmarshalTable ¶
UnmarshalTable decodes table to array of structs
Types ¶
type Dict ¶
Dict represents ordered key->value mapping. Key and Value must be slices of the same length
type K ¶
K structure
type KDBConn ¶
KDBConn establishes connection and communicates using Q IPC protocol
func DialKDB ¶
DialKDB connects to host:port using supplied user:password. Wait until connected
Example ¶
con, err := kdb.DialKDB("localhost", 1234, "") if err != nil { fmt.Println("Failed to connect:", err) return } res, err := con.Call("til", kdb.Int(10)) if err != nil { fmt.Println("Query failed:", err) } fmt.Println("Result:", res)
Output:
func DialKDBTimeout ¶
DialKDBTimeout connects to host:port using supplied user:password. Wait timeout for connection
func DialUnix ¶ added in v0.10.0
DialUnix connects to port using unix domain sockets. host parameter is ignored.
func (*KDBConn) ReadMessage ¶
ReadMessage reads complete message from connection
type ReqType ¶ added in v0.20.0
type ReqType int8
ReqType represents type of message sent or recieved via ipc