github.com/m3db/m3@v1.5.0/src/dbnode/encoding/null.go (about) 1 // Copyright (c) 2016 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package encoding 22 23 import ( 24 "fmt" 25 26 "github.com/m3db/m3/src/dbnode/namespace" 27 "github.com/m3db/m3/src/dbnode/ts" 28 "github.com/m3db/m3/src/dbnode/x/xio" 29 "github.com/m3db/m3/src/x/context" 30 xtime "github.com/m3db/m3/src/x/time" 31 ) 32 33 type nullEncoder struct { 34 sealed bool 35 } 36 37 // NewNullEncoder returns a new encoder that performs no operations 38 func NewNullEncoder() Encoder { 39 return &nullEncoder{} 40 } 41 42 func (e *nullEncoder) Encode(dp ts.Datapoint, timeUnit xtime.Unit, annotation ts.Annotation) error { 43 return nil 44 } 45 46 func (e *nullEncoder) Stream(ctx context.Context) (xio.SegmentReader, bool) { 47 return nil, false 48 } 49 func (e *nullEncoder) NumEncoded() int { return 0 } 50 func (e *nullEncoder) LastEncoded() (ts.Datapoint, error) { 51 return ts.Datapoint{}, fmt.Errorf("not implemented") 52 } 53 54 func (e *nullEncoder) LastAnnotationChecksum() (uint64, error) { 55 return 0, fmt.Errorf("not implemented") 56 } 57 func (e *nullEncoder) Empty() bool { return true } 58 func (e *nullEncoder) Len() int { return 0 } 59 func (e *nullEncoder) Seal() { e.sealed = true } 60 func (e *nullEncoder) Reset(xtime.UnixNano, int, namespace.SchemaDescr) {} 61 func (e *nullEncoder) Close() {} 62 func (e *nullEncoder) Discard() ts.Segment { return ts.Segment{} } 63 func (e *nullEncoder) DiscardReset(xtime.UnixNano, int, namespace.SchemaDescr) ts.Segment { 64 return ts.Segment{} 65 } 66 func (e *nullEncoder) SetSchema(_ namespace.SchemaDescr) {} 67 68 type nullReaderIterator struct{} 69 70 // NewNullReaderIterator returns a new reader iterator that performs no operations 71 func NewNullReaderIterator() ReaderIterator { 72 return &nullReaderIterator{} 73 } 74 75 func (r *nullReaderIterator) Current() (ts.Datapoint, xtime.Unit, ts.Annotation) { 76 return ts.Datapoint{}, xtime.Unit(0), nil 77 } 78 func (r *nullReaderIterator) Next() bool { return false } 79 func (r *nullReaderIterator) Err() error { return fmt.Errorf("not implemented") } 80 func (r *nullReaderIterator) Close() {} 81 func (r *nullReaderIterator) Reset(xio.Reader64, namespace.SchemaDescr) { 82 }