chaokunyang commented on code in PR #3374:
URL: https://github.com/apache/fory/pull/3374#discussion_r2890227703


##########
go/fory/buffer.go:
##########
@@ -28,12 +29,86 @@ type ByteBuffer struct {
        data        []byte // Most accessed field first for cache locality
        writerIndex int
        readerIndex int
+       reader      io.Reader
+       minCap      int
 }
 
 func NewByteBuffer(data []byte) *ByteBuffer {
        return &ByteBuffer{data: data}
 }
 
+func NewByteBufferFromReader(r io.Reader, minCap int) *ByteBuffer {
+       if minCap <= 0 {
+               minCap = 4096
+       }
+       return &ByteBuffer{
+               data:   make([]byte, 0, minCap),
+               reader: r,
+               minCap: minCap,
+       }
+}
+
+//go:noinline
+func (b *ByteBuffer) fill(n int, errOut *Error) bool {
+       if b.reader == nil {
+               if errOut != nil {
+                       *errOut = BufferOutOfBoundError(b.readerIndex, n, 
len(b.data))
+               }
+               return false
+       }
+
+       available := len(b.data) - b.readerIndex
+       if available >= n {
+               return true
+       }
+
+       if b.readerIndex > 0 {
+               copy(b.data, b.data[b.readerIndex:])
+               b.writerIndex -= b.readerIndex
+               b.readerIndex = 0
+               b.data = b.data[:b.writerIndex]

Review Comment:
   Why need to process on writerIndex?



-- 
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