Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "github.com/luci/luci-go/common/logdog/protocol" | |
| 9 ) | |
| 10 | |
| 11 // binaryThreshold is the amount of binary data that we will willingly yield | |
| 12 // if not requested to truncate. This helps build larger binary stream chunks. | |
| 13 const defaultBinaryThreshold = 8 * 1024 | |
| 14 | |
| 15 // binaryParser is a parser implementation for the LogDog BINARY stream type. | |
| 16 type binaryParser struct { | |
| 17 baseParser | |
| 18 | |
| 19 offset int64 | |
| 20 threshold int | |
| 21 } | |
| 22 | |
| 23 var _ parser = (*binaryParser)(nil) | |
| 24 | |
| 25 func (p *binaryParser) nextEntry(c *constraints) (*protocol.LogEntry, error) { | |
|
iannucci
2015/11/13 07:16:38
why return an error at all? this looks like it can
dnj
2015/11/14 00:30:36
This is implementing the "parser" interface, which
| |
| 26 threshold := p.getThreshold() | |
| 27 if c.truncate { | |
| 28 // If we're truncating, return _any_ available data. | |
| 29 threshold = 0 | |
| 30 } | |
| 31 | |
| 32 count := p.Len() | |
| 33 if count <= int64(threshold) { | |
| 34 return nil, nil | |
| 35 } | |
| 36 if count > int64(c.limit) { | |
| 37 count = int64(c.limit) | |
| 38 } | |
| 39 | |
| 40 // The integer conversion, since count has been bounded by our "int" lim it. | |
| 41 size := int(count) | |
| 42 | |
| 43 data := make([]byte, size) | |
| 44 size, _ = p.Reader().Read(data) | |
| 45 if int64(size) != count { | |
| 46 panic("partial buffer read") | |
| 47 } | |
| 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 } | |
| OLD | NEW |