本文整理匯總了Golang中github.com/elastic/beats/libbeat/common/streambuf.Buffer.Restore方法的典型用法代碼示例。如果您正苦於以下問題:Golang Buffer.Restore方法的具體用法?Golang Buffer.Restore怎麽用?Golang Buffer.Restore使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/elastic/beats/libbeat/common/streambuf.Buffer
的用法示例。
在下文中一共展示了Buffer.Restore方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: dispatch
func (p *parser) dispatch(depth int, buf *streambuf.Buffer) (common.NetString, bool, bool, bool) {
if buf.Len() == 0 {
return empty, false, true, false
}
var value common.NetString
var iserror, ok, complete bool
snapshot := buf.Snapshot()
switch buf.Bytes()[0] {
case '*':
value, iserror, ok, complete = p.parseArray(depth, buf)
case '$':
value, ok, complete = p.parseString(buf)
case ':':
value, ok, complete = p.parseInt(buf)
case '+':
value, ok, complete = p.parseSimpleString(buf)
case '-':
iserror = true
value, ok, complete = p.parseSimpleString(buf)
default:
if isDebug {
debugf("Unexpected message starting with %s", buf.Bytes()[0])
}
return empty, false, false, false
}
if !ok || !complete {
buf.Restore(snapshot)
}
return value, iserror, ok, complete
}
示例2: parse
func (p *parser) parse(buf *streambuf.Buffer) (bool, bool) {
snapshot := buf.Snapshot()
content, iserror, ok, complete := p.dispatch(0, buf)
if !ok || !complete {
// on error or incomplete message drop all parsing progress, due to
// parse not being statefull among multiple calls
// => parser needs to restart parsing all content
buf.Restore(snapshot)
return ok, complete
}
p.message.isError = iserror
p.message.size = buf.BufferConsumed()
p.message.message = content
return true, true
}