jameshartig commented on code in PR #1822:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1822#discussion_r1959982653


##########
conn.go:
##########
@@ -777,6 +774,172 @@ func (c *Conn) handleTimeout() {
        }
 }
 
+func (c *Conn) recvSegment(ctx context.Context) error {
+       var (
+               frame           []byte
+               isSelfContained bool
+               err             error
+       )
+
+       // Read frame based on compression
+       if c.compressor != nil {
+               frame, isSelfContained, err = readCompressedSegment(c.r, 
c.compressor)
+       } else {
+               frame, isSelfContained, err = readUncompressedSegment(c.r)
+       }
+       if err != nil {
+               return err
+       }
+
+       if isSelfContained {
+               return c.processAllFramesInSegment(ctx, bytes.NewReader(frame))
+       }
+
+       head, err := readHeader(bytes.NewReader(frame), c.headerBuf[:])
+       if err != nil {
+               return err
+       }
+
+       const frameHeaderLength = 9
+       buf := bytes.NewBuffer(make([]byte, 0, head.length+frameHeaderLength))
+       buf.Write(frame)
+
+       // Computing how many bytes of message left to read
+       bytesToRead := head.length - len(frame) + frameHeaderLength
+
+       err = c.recvPartialFrames(buf, bytesToRead)
+       if err != nil {
+               return err
+       }
+
+       return c.processFrame(ctx, buf)
+}
+
+// recvPartialFrames reads proto v5 segments from Conn.r and writes decoded 
partial frames to dst.
+// It reads data until the bytesToRead is reached.
+// If Conn.compressor is not nil, it processes Compressed Format segments.
+func (c *Conn) recvPartialFrames(dst *bytes.Buffer, bytesToRead int) error {
+       var (
+               read            int
+               frame           []byte
+               isSelfContained bool
+               err             error
+       )
+
+       for read != bytesToRead {

Review Comment:
   should this be `read < bytesToRead`? Is it possible to over-read?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to