@@ -10,24 +10,24 @@ import (
1010
1111// RecBytes represents a single piece of data (a datapoint) that can be sent.
1212type RecBytes struct { // nolint:revive
13- Path []byte
14- RawVal []byte // this is to avoid discrepancies in precision and formatting
15- RawTime []byte // to avoid differences when encoding, and save time
16- // Raw string // to avoid wasting time for serialization
13+ Path []byte
14+ Val []byte
15+ Time []byte
16+
1717 Received time.Time
1818}
1919
20- // ParseRecBytes parses a single datapoint record from a string. Makes sure it's valid.
20+ // ParseRec parses a single datapoint record from a string. Makes sure it's valid.
2121// Performs normalizations.
22- func ParseRecBytes (s []byte , normalize bool , shouldLog bool , nowF func () time.Time , lg * zap.Logger ) (* RecBytes , error ) {
22+ func ParseRec (s []byte , normalize bool , shouldLog bool , nowF func () time.Time , lg * zap.Logger ) (* RecBytes , error ) {
2323 pathStart , pathEnd , valStart , valEnd , timeStart , timeEnd , err := recFields (s )
2424 if err != nil {
2525 return nil , errors .Wrap (err , "failed to break record into fields" )
2626 }
2727
2828 var path []byte
2929 if normalize {
30- path , err = normalizePathBytes (s [pathStart :pathEnd ])
30+ path , err = normalizePath (s [pathStart :pathEnd ])
3131 if err != nil {
3232 return nil , errors .Wrap (err , "failed to normalize path" )
3333 }
@@ -39,8 +39,8 @@ func ParseRecBytes(s []byte, normalize bool, shouldLog bool, nowF func() time.Ti
3939 Path : path ,
4040 Received : nowF (),
4141 }
42- res .RawVal = append (res .RawVal , s [valStart :valEnd ]... )
43- res .RawTime = append (res .RawTime , s [timeStart :timeEnd ]... )
42+ res .Val = append (res .Val , s [valStart :valEnd ]... )
43+ res .Time = append (res .Time , s [timeStart :timeEnd ]... )
4444
4545 return & res , nil
4646}
@@ -100,20 +100,19 @@ func isWhitespace(c byte) bool {
100100// Serialize makes record into a string ready to be sent via TCP w/ line protocol.
101101func (r * RecBytes ) Serialize () []byte {
102102 // TODO (grzkv): Copy can be avoided if string was not changed
103- res := make ([]byte , 0 , len (r .Path )+ len (r .RawTime )+ len (r .RawVal )+ 3 )
103+ res := make ([]byte , 0 , len (r .Path )+ len (r .Time )+ len (r .Val )+ 3 )
104104 res = append (res , r .Path ... )
105105 res = append (res , ' ' )
106- res = append (res , r .RawVal ... )
106+ res = append (res , r .Val ... )
107107 res = append (res , ' ' )
108- res = append (res , r .RawTime ... )
108+ res = append (res , r .Time ... )
109109 res = append (res , '\n' )
110110
111111 return res
112112}
113113
114114// normalizePath does path normalization as described in the docs
115- // returns: (updated path, was any normalization done)
116- func normalizePathBytes (s []byte ) ([]byte , error ) {
115+ func normalizePath (s []byte ) ([]byte , error ) {
117116 if len (s ) == 0 {
118117 return []byte {}, nil
119118 }
@@ -181,21 +180,21 @@ func (r RecBytes) Copy() (*RecBytes, error) {
181180 cpy := & RecBytes {
182181 Received : r .Received ,
183182 Path : make ([]byte , len (r .Path )),
184- RawVal : make ([]byte , len (r .RawVal )),
185- RawTime : make ([]byte , len (r .RawTime )),
183+ Val : make ([]byte , len (r .Val )),
184+ Time : make ([]byte , len (r .Time )),
186185 }
187186
188187 n := copy (cpy .Path , r .Path )
189188 if n != len (r .Path ) {
190189 return nil , errors .Errorf ("did not copy full path, expected %d bytes, copied %d bytes" , len (r .Path ), n )
191190 }
192- n = copy (cpy .RawVal , r .RawVal )
193- if n != len (r .RawVal ) {
194- return nil , errors .Errorf ("did not copy full value, expected %d bytes, copied %d bytes" , len (r .RawVal ), n )
191+ n = copy (cpy .Val , r .Val )
192+ if n != len (r .Val ) {
193+ return nil , errors .Errorf ("did not copy full value, expected %d bytes, copied %d bytes" , len (r .Val ), n )
195194 }
196- n = copy (cpy .RawTime , r .RawTime )
197- if n != len (r .RawTime ) {
198- return nil , errors .Errorf ("did not copy full time, expected %d bytes, copied %d bytes" , len (r .RawTime ), n )
195+ n = copy (cpy .Time , r .Time )
196+ if n != len (r .Time ) {
197+ return nil , errors .Errorf ("did not copy full time, expected %d bytes, copied %d bytes" , len (r .Time ), n )
199198 }
200199
201200 return cpy , nil
0 commit comments