當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Item.Available方法代碼示例

本文整理匯總了Golang中github.com/valyala/ybc/bindings/go/ybc.Item.Available方法的典型用法代碼示例。如果您正苦於以下問題:Golang Item.Available方法的具體用法?Golang Item.Available怎麽用?Golang Item.Available使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/valyala/ybc/bindings/go/ybc.Item的用法示例。


在下文中一共展示了Item.Available方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: writeGetResponse

func writeGetResponse(w *bufio.Writer, key []byte, item *ybc.Item, shouldWriteCasid bool, scratchBuf *[]byte) bool {
	var casid uint64
	var buf [casidSize + flagsSize]byte
	n, err := item.Read(buf[:])
	if err != nil {
		log.Printf("error when reading item metadata: [%s]", err)
		return false
	}
	if n != len(buf) {
		log.Printf("Unexpected result returned from ybc.Item.Read(): %d. Expected %d", n, len(buf))
		return false
	}
	if shouldWriteCasid {
		casid = binary.LittleEndian.Uint64(buf[:])
	}
	flags := binary.LittleEndian.Uint32(buf[casidSize:])

	size := item.Available()
	if !writeStr(w, strValue) || !writeStr(w, key) || !writeWs(w) ||
		!writeUint32(w, flags, scratchBuf) || !writeWs(w) ||
		!writeInt(w, size, scratchBuf) {
		return false
	}

	if shouldWriteCasid {
		if !writeWs(w) || !writeUint64(w, casid, scratchBuf) {
			return false
		}
	}

	return writeStr(w, strCrLf) && writeItem(w, item, size)
}
開發者ID:rjmcguire,項目名稱:ybc,代碼行數:32,代碼來源:server.go

示例2: setItemValue

func setItemValue(it *ybc.Item, item *Item) error {
	size := it.Available()
	item.Value = make([]byte, size)
	n, err := it.Read(item.Value)
	if err != nil {
		log.Fatalf("Unexpected error in Item.Read(size=%d): [%s]", size, err)
	}
	if n != size {
		log.Fatalf("Unexpected number of bytes read in Item.Read(size=%d): %d", size, n)
	}
	return nil
}
開發者ID:kangkot,項目名稱:ybc,代碼行數:12,代碼來源:caching_client.go

示例3: updateLocalItem

func updateLocalItem(cache ybc.Cacher, it *ybc.Item, key []byte, casid uint64, flags, validateTtl uint32) {
	size := it.Available()
	defer it.Seek(-int64(size), 2)

	txn := writeItemMetadata(cache, key, size, casid, flags, validateTtl)
	if txn == nil {
		return
	}
	defer txn.Commit()

	n, err := txn.ReadFrom(it)
	if err != nil {
		log.Fatalf("Unexpected error in SetTxn.ReadFrom(size=%d): [%s]", size, err)
	}
	if n != int64(size) {
		log.Fatalf("Unexpected number of bytes copied in SetTxn.ReadFrom(size=%d): %d", size, n)
	}
}
開發者ID:kangkot,項目名稱:ybc,代碼行數:18,代碼來源:caching_client.go

示例4: writeCgetResponse

func writeCgetResponse(w *bufio.Writer, etag uint64, item *ybc.Item, scratchBuf *[]byte) bool {
	var validateTtl, flags uint32
	if err := binaryRead(item, &validateTtl, "validateTtl"); err != nil {
		return false
	}
	if err := binaryRead(item, &flags, "flags"); err != nil {
		return false
	}

	size := item.Available()
	expiration := item.Ttl()
	return writeStr(w, strValue) && writeInt(w, size, scratchBuf) && writeWs(w) &&
		writeUint32(w, flags, scratchBuf) && writeWs(w) &&
		writeExpiration(w, expiration, scratchBuf) && writeWs(w) &&
		writeUint64(w, etag, scratchBuf) && writeWs(w) &&
		writeUint32(w, validateTtl, scratchBuf) && writeCrLf(w) &&
		writeItem(w, item, size)
}
開發者ID:inthecloud247,項目名稱:ybc,代碼行數:18,代碼來源:server.go

示例5: writeGetResponse

func writeGetResponse(w *bufio.Writer, key []byte, item *ybc.Item, cas bool, scratchBuf *[]byte) bool {
	var flags uint32
	if err := binaryRead(item, &flags, "flags"); err != nil {
		return false
	}

	size := item.Available()
	if !writeStr(w, strValue) || !writeStr(w, key) || !writeWs(w) ||
		!writeUint32(w, flags, scratchBuf) || !writeWs(w) ||
		!writeInt(w, size, scratchBuf) {
		return false
	}
	if cas {
		if !writeWs(w) || !writeZero(w) {
			return false
		}
	}
	return writeCrLf(w) && writeItem(w, item, size)
}
開發者ID:inthecloud247,項目名稱:ybc,代碼行數:19,代碼來源:server.go

示例6: updateLocalItem

func updateLocalItem(cache ybc.Cacher, it *ybc.Item, item *Item, etag uint64, validateTtl uint32) {
	size := it.Available()
	offset := it.Size() - size
	defer it.Seek(int64(offset), 0)

	txn := writeItemMetadata(cache, item.Key, size, it.Ttl(), etag, validateTtl, item.Flags)
	if txn == nil {
		return
	}
	defer txn.Commit()

	n, err := txn.ReadFrom(it)
	if err != nil {
		log.Fatalf("Unexpected error in SetTxn.ReadFrom(size=%d): [%s]", size, err)
	}
	if n != int64(size) {
		log.Fatalf("Unexpected number of bytes copied in SetTxn.ReadFrom(size=%d): %d", size, n)
	}

}
開發者ID:inthecloud247,項目名稱:ybc,代碼行數:20,代碼來源:caching_client.go


注:本文中的github.com/valyala/ybc/bindings/go/ybc.Item.Available方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。