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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | client/internal/logdog/butler/bundler/binaryParser_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package bundler
6
7 import (
8 "errors"
9
10 "github.com/luci/luci-go/common/logdog/protocol"
11 )
12
13 // binaryThreshold is the amount of binary data that we will willingly yield
14 // if not allowed to split. This helps build larger binary stream chunks.
15 const defaultBinaryThreshold = 8 * 1024
16
17 // binaryParser is a parser implementation for the LogDog BINARY stream type.
18 type binaryParser struct {
19 baseParser
20
21 offset int64
22 threshold int
23 }
24
25 var _ parser = (*binaryParser)(nil)
26
27 func (p *binaryParser) nextEntry(c *constraints) (*protocol.LogEntry, error) {
28 threshold := p.getThreshold()
29 if c.allowSplit {
30 // If we're allowed to split, return _any_ available data.
31 threshold = 0
32 }
33
34 count := p.Len()
35 if count <= int64(threshold) {
36 return nil, nil
37 }
38 if count > int64(c.limit) {
39 count = int64(c.limit)
40 }
41
42 // The integer conversion, since count has been bounded by our "int" lim it.
43 size := int(count)
44
45 data := make([]byte, size)
46 size, _ = p.View().Read(data)
47 memoryCorruptionIf(int64(size) != count, errors.New("partial buffer read "))
48
49 ts, _ := p.firstChunkTime()
50 e := p.baseLogEntry(ts)
51 e.Content = &protocol.LogEntry_Binary{Binary: &protocol.Binary{
52 Offset: uint64(p.offset),
53 Data: data[:size],
54 }}
55 e.Sequence = uint64(p.offset)
56
57 p.Consume(int64(size))
58 p.offset += int64(size)
59 return e, nil
60 }
61
62 func (p *binaryParser) getThreshold() int {
63 result := p.threshold
64 if result == 0 {
65 result = defaultBinaryThreshold
66 }
67 return result
68 }
OLDNEW
« 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