本文整理匯總了Golang中github.com/couchbaselabs/sync_gateway/channels.LogEntry.Encode方法的典型用法代碼示例。如果您正苦於以下問題:Golang LogEntry.Encode方法的具體用法?Golang LogEntry.Encode怎麽用?Golang LogEntry.Encode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/couchbaselabs/sync_gateway/channels.LogEntry
的用法示例。
在下文中一共展示了LogEntry.Encode方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: AddToChangeLog
// Adds a new change to a channel log.
func (db *Database) AddToChangeLog(channelName string, entry channels.LogEntry, parentRevID string) error {
if channelName == "*" && !EnableStarChannelLog {
return nil
}
var fullUpdate bool
var removedCount int
fullUpdateAttempts := 0
logDocID := channelLogDocID(channelName)
err := db.Bucket.WriteUpdate(logDocID, 0, func(currentValue []byte) ([]byte, walrus.WriteOptions, error) {
// (Be careful: this block can be invoked multiple times if there are races!)
// Should I do a full update of the change log, removing older entries to limit its size?
// This has to be done occasionaly, but it's slower than simply appending to it. This
// test is a heuristic that seems to strike a good balance in practice:
fullUpdate = AlwaysCompactChangeLog ||
(len(currentValue) > 20000 && (rand.Intn(100) < len(currentValue)/5000))
removedCount = 0
if len(currentValue) == 0 {
channelLog := channels.ChangeLog{}
channelLog.Add(entry)
return encodeChannelLog(&channelLog), walrus.Raw, nil
}
if fullUpdate {
fullUpdateAttempts++
var newValue bytes.Buffer
removedCount = channels.TruncateEncodedChangeLog(bytes.NewReader(currentValue),
MaxChangeLogLength-1, &newValue)
if removedCount > 0 {
entry.Encode(&newValue, parentRevID)
return newValue.Bytes(), walrus.Raw, nil
}
}
w := bytes.NewBuffer(make([]byte, 0, 50000))
entry.Encode(w, parentRevID)
currentValue = append(currentValue, w.Bytes()...)
return currentValue, walrus.Raw, nil
})
/*if fullUpdate {
base.Log("Removed %d entries from %q", removedCount, channelName)
} else if fullUpdateAttempts > 0 {
base.Log("Attempted to remove entries %d times but failed", fullUpdateAttempts)
}*/
return err
}