Exemplo n.º 1
0
func reply(c *Client, msg string, result ds.List) {
	defer c.W.Flush()
	var resultN int32
	if result == nil {
		resultN = -1
	}
	if msg == success {
		resultN = 0
		if result != nil {
			resultN = int32(result.Len())
		}
	} else {
		c.CmdError = true
	}
	err := binary.Write(c.W, binary.BigEndian, &resultN)
	if err != nil {
		log.Println("reply()", err)
		return
	}
	if len(msg) == 0 {
		log.Println("reply()", "msg len == 0")
		return
	}
	var msgLen uint8 = uint8(len(msg))
	err = binary.Write(c.W, binary.BigEndian, &msgLen)
	if err != nil {
		log.Println("reply()", err)
		return
	}
	c.W.WriteString(msg)
	if result == nil || resultN == 0 {
		return
	}
	var objlen uint64
	var obj *ds.Object
	var ok bool
	for e := result.GetFirstNode(); e != nil; e = e.Next {
		if obj, ok = e.Value.(*ds.Object); !ok {
			continue
		}
		objlen = uint64(len(obj.GetBuffer()))
		if objlen == 0 {
			continue
		}
		err = binary.Write(c.W, binary.BigEndian, &objlen)
		if err != nil {
			log.Println("reply()", err)
			return
		}
		_, err = c.W.Write(obj.GetBuffer())
		if err != nil {
			log.Println("reply()", err)
			return
		}
	}
}
Exemplo n.º 2
0
func (dl *DataLog) PutKeyKeyValue(
	db *db.DB,
	key0 []byte,
	key1 []byte,
	op int8, obj *ds.Object) {
	var newBuffer []byte
	if op == None {
		buffer := obj.GetBuffer()
		newBuffer = make([]byte, len(buffer))
		copy(newBuffer, buffer)
	}
	dl.logWriteQ <- &dataRecord{
		witchdb:    db.Id,
		key0:       key0,
		key1:       key1,
		op:         op,
		objectType: obj.GetObjectType(),
		objectData: newBuffer,
		inqueueT:   time.Now(),
	}
}