本文整理匯總了Golang中github.com/valyala/ybc/bindings/go/ybc.Item.Read方法的典型用法代碼示例。如果您正苦於以下問題:Golang Item.Read方法的具體用法?Golang Item.Read怎麽用?Golang Item.Read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/valyala/ybc/bindings/go/ybc.Item
的用法示例。
在下文中一共展示了Item.Read方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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)
}
示例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
}
示例3: readItemMetadata
func readItemMetadata(it *ybc.Item) (casid uint64, flags uint32, validateExpiration time.Time, validateTtl uint32, ok bool) {
var buf [metadataSize]byte
n, err := it.Read(buf[:])
if err != nil {
log.Printf("Cannot read metadata for cached item: [%s]", err)
return
}
if n != len(buf) {
log.Printf("Unexpected result returned from ybc.Item.Read(): %d. Expected %d", n, len(buf))
return
}
casid = binary.LittleEndian.Uint64(buf[:])
flags = binary.LittleEndian.Uint32(buf[casidSize:])
validateTtl = binary.LittleEndian.Uint32(buf[casidSize+flagsSize:])
validateExpiration64 := binary.LittleEndian.Uint64(buf[casidSize+flagsSize+validateTtlSize:])
validateExpiration = time.Unix(0, int64(validateExpiration64))
ok = true
return
}
示例4: checkAndUpdateCasid
func checkAndUpdateCasid(item *ybc.Item, casid *uint64) (isModified, ok bool) {
casidOld := *casid
var buf [casidSize]byte
n, err := item.Read(buf[:])
if err != nil {
log.Printf("Cannod read casid from item: [%s]", err)
return
}
if n != len(buf) {
log.Printf("Unexpected result returned from ybc.Item.Read(): %d. Expected %d", n, len(buf))
return
}
*casid = binary.LittleEndian.Uint64(buf[:])
if _, err := item.Seek(-casidSize, 1); err != nil {
log.Fatalf("Unexpected error returned from ybc.Item.Seek(%d, 1): [%s]", -casidSize, err)
}
isModified = (casidOld != *casid)
ok = true
return
}