From 8c782fbad623331564cfc69005cd2cee28645055 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 29 Nov 2018 15:54:57 +0000 Subject: [PATCH] Make varbitChunk.Size() more accurate Also un-export MarshalLen since it is not called from outside. Signed-off-by: Bryan Boreham --- encoding/varbit.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/encoding/varbit.go b/encoding/varbit.go index 387eea9d8ee24..01a2ed74bb988 100644 --- a/encoding/varbit.go +++ b/encoding/varbit.go @@ -287,7 +287,7 @@ func (c *varbitChunk) Slice(_, _ model.Time) Chunk { // Marshal implements chunk. func (c varbitChunk) Marshal(w io.Writer) error { - size := c.MarshalLen() + size := c.marshalLen() n, err := w.Write(c[:size]) if err != nil { return err @@ -300,8 +300,8 @@ func (c varbitChunk) Marshal(w io.Writer) error { // UnmarshalFromBuf implements chunk. func (c varbitChunk) UnmarshalFromBuf(buf []byte) error { - if copied := copy(c, buf); copied != cap(c) && copied != c.MarshalLen() { - return fmt.Errorf("incorrect byte count copied from buffer during unmarshaling, want %d or %d, got %d", c.MarshalLen(), ChunkLen, copied) + if copied := copy(c, buf); copied != cap(c) && copied != c.marshalLen() { + return fmt.Errorf("incorrect byte count copied from buffer during unmarshaling, want %d or %d, got %d", c.marshalLen(), ChunkLen, copied) } return nil } @@ -325,8 +325,8 @@ func (MarshalConfig) RegisterFlags(f *flag.FlagSet) { flag.BoolVar(&alwaysMarshalFullsizeChunks, "store.fullsize-chunks", alwaysMarshalFullsizeChunks, "When saving varbit chunks, pad to 1024 bytes") } -// MarshalLen implements chunk. -func (c varbitChunk) MarshalLen() int { +// marshalLen returns the number of bytes that should be marshalled for this chunk +func (c varbitChunk) marshalLen() int { if alwaysMarshalFullsizeChunks { return cap(c) } @@ -351,7 +351,7 @@ func (c varbitChunk) Len() int { } func (c varbitChunk) Size() int { - return len(c) + return c.marshalLen() } func (c varbitChunk) firstTime() model.Time {