コード例 #1
0
ファイル: context.go プロジェクト: tradia/gotable
func (c *Context) goDump(oneTable bool, tableId, colSpace uint8,
	rowKey, colKey []byte, score int64, startSlotId, endSlotId uint16,
	done chan *Call) (*Call, error) {
	call := c.cli.newCall(proto.CmdDump, done)
	if call.err != nil {
		return call, call.err
	}

	var p proto.PkgDumpReq
	p.Seq = call.seq
	p.DbId = c.dbId
	p.Cmd = call.cmd
	if oneTable {
		p.PkgFlag |= proto.FlagDumpTable
	}
	p.StartSlotId = startSlotId
	p.EndSlotId = endSlotId
	p.TableId = tableId
	p.RowKey = rowKey
	p.ColKey = colKey
	p.SetColSpace(colSpace)
	p.SetScore(score)

	var pkgLen = p.Length()
	if pkgLen > proto.MaxPkgLen {
		c.cli.errCall(call, ErrInvPkgLen)
		return call, call.err
	}

	call.pkg = make([]byte, pkgLen)
	_, err := p.Encode(call.pkg)
	if err != nil {
		c.cli.errCall(call, err)
		return call, err
	}

	call.ctx = dumpContext{oneTable, tableId,
		startSlotId, endSlotId, startSlotId, false}

	c.cli.sending <- call

	return call, nil
}
コード例 #2
0
ファイル: table_test.go プロジェクト: tradia/gotable
func myDump(in proto.PkgDumpReq, au Authorize, t *testing.T) proto.PkgDumpResp {
	var pkg = make([]byte, in.Length())
	_, err := in.Encode(pkg)
	if err != nil {
		t.Fatalf("Encode failed: ", err)
	}

	pkg = testTbl.Dump(&PkgArgs{in.Cmd, in.DbId, in.Seq, pkg}, au)

	var out proto.PkgDumpResp
	_, err = out.Decode(pkg)
	if err != nil {
		t.Fatalf("Decode failed: ", err)
	}

	if out.ErrCode != 0 {
		t.Fatalf("Failed with ErrCode %d", out.ErrCode)
	}
	if out.DbId != in.DbId || out.Seq != in.Seq {
		t.Fatalf("DbId/Seq mismatch")
	}

	return out
}