Skip to content

Commit

Permalink
Use Size() instead of encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
jvshahid committed May 30, 2014
1 parent 6e46865 commit e9b2ce5
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/coordinator/protobuf_request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,7 @@ func (self *ProtobufRequestHandler) handleDropDatabase(request *protocol.Request
}

func (self *ProtobufRequestHandler) WriteResponse(conn net.Conn, response *protocol.Response) error {
data, err := response.Encode()
if err != nil {
log.Error("error encoding response: %s", err)
return err
}
if len(data) >= MAX_RESPONSE_SIZE {
if response.Size() >= MAX_RESPONSE_SIZE {
pointCount := len(response.Series.Points)
firstHalfPoints := response.Series.Points[:pointCount]
secondHalfPoints := response.Series.Points[pointCount:]
Expand All @@ -133,6 +128,12 @@ func (self *ProtobufRequestHandler) WriteResponse(conn net.Conn, response *proto
return self.WriteResponse(conn, response)
}

data, err := response.Encode()
if err != nil {
log.Error("error encoding response: %s", err)
return err
}

buff := bytes.NewBuffer(make([]byte, 0, len(data)+8))
binary.Write(buff, binary.LittleEndian, uint32(len(data)))
_, err = conn.Write(append(buff.Bytes(), data...))
Expand Down

0 comments on commit e9b2ce5

Please sign in to comment.