go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/logdog/common/fetcher/buffer.go (about) 1 // Copyright 2015 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package fetcher 16 17 import ( 18 "container/list" 19 20 "go.chromium.org/luci/logdog/api/logpb" 21 ) 22 23 type logBuffer struct { 24 l list.List 25 cur []*logpb.LogEntry 26 curIdx int 27 28 count int 29 } 30 31 func (b *logBuffer) current() *logpb.LogEntry { 32 for b.curIdx >= len(b.cur) { 33 if b.l.Len() == 0 { 34 return nil 35 } 36 b.cur = b.l.Remove(b.l.Front()).([]*logpb.LogEntry) 37 b.curIdx = 0 38 } 39 40 return b.cur[b.curIdx] 41 } 42 43 func (b *logBuffer) next() { 44 b.curIdx++ 45 b.count-- 46 } 47 48 func (b *logBuffer) append(le ...*logpb.LogEntry) { 49 b.l.PushBack(le) 50 b.count += len(le) 51 } 52 53 func (b *logBuffer) size() int { 54 return b.count 55 }