Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Unified Diff: client/internal/logdog/butler/bundler/binaryParser.go

Issue 1412063008: logdog: Add bundler library. (Closed) Base URL: https://github.com/luci/luci-go@logdog-review-streamserver
Patch Set: Updated from comments. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | client/internal/logdog/butler/bundler/binaryParser_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/internal/logdog/butler/bundler/binaryParser.go
diff --git a/client/internal/logdog/butler/bundler/binaryParser.go b/client/internal/logdog/butler/bundler/binaryParser.go
new file mode 100644
index 0000000000000000000000000000000000000000..f0aed600798d364ce993d8662ab993aa2e583a55
--- /dev/null
+++ b/client/internal/logdog/butler/bundler/binaryParser.go
@@ -0,0 +1,68 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package bundler
+
+import (
+ "errors"
+
+ "github.com/luci/luci-go/common/logdog/protocol"
+)
+
+// binaryThreshold is the amount of binary data that we will willingly yield
+// if not allowed to split. This helps build larger binary stream chunks.
+const defaultBinaryThreshold = 8 * 1024
+
+// binaryParser is a parser implementation for the LogDog BINARY stream type.
+type binaryParser struct {
+ baseParser
+
+ offset int64
+ threshold int
+}
+
+var _ parser = (*binaryParser)(nil)
+
+func (p *binaryParser) nextEntry(c *constraints) (*protocol.LogEntry, error) {
+ threshold := p.getThreshold()
+ if c.allowSplit {
+ // If we're allowed to split, return _any_ available data.
+ threshold = 0
+ }
+
+ count := p.Len()
+ if count <= int64(threshold) {
+ return nil, nil
+ }
+ if count > int64(c.limit) {
+ count = int64(c.limit)
+ }
+
+ // The integer conversion, since count has been bounded by our "int" limit.
+ size := int(count)
+
+ data := make([]byte, size)
+ size, _ = p.View().Read(data)
+ memoryCorruptionIf(int64(size) != count, errors.New("partial buffer read"))
+
+ ts, _ := p.firstChunkTime()
+ e := p.baseLogEntry(ts)
+ e.Content = &protocol.LogEntry_Binary{Binary: &protocol.Binary{
+ Offset: uint64(p.offset),
+ Data: data[:size],
+ }}
+ e.Sequence = uint64(p.offset)
+
+ p.Consume(int64(size))
+ p.offset += int64(size)
+ return e, nil
+}
+
+func (p *binaryParser) getThreshold() int {
+ result := p.threshold
+ if result == 0 {
+ result = defaultBinaryThreshold
+ }
+ return result
+}
« no previous file with comments | « no previous file | client/internal/logdog/butler/bundler/binaryParser_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698