Q1ngbo commented on code in PR #3062:
URL: https://github.com/apache/brpc/pull/3062#discussion_r2297409037


##########
src/butil/single_iobuf.h:
##########
@@ -0,0 +1,107 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// SingleIOBuf - A continuous zero-copied buffer
+
+#ifndef BUTIL_SINGLE_IOBUF_H
+#define BUTIL_SINGLE_IOBUF_H
+
+#include "butil/iobuf.h"
+#include "butil/iobuf_inl.h"
+
+namespace butil {
+
+// SingleIOBuf is a lightweight buffer that manages a single IOBuf::Block.
+// It always ensures that the underlying memory is contiguous and 
+// avoids unnecessary memory copies.
+// It is primarily used to efficiently serialize and deserialize 
+// RPC requests in flatbuffers.
+class SingleIOBuf {
+public:
+    SingleIOBuf();
+    ~SingleIOBuf();
+    SingleIOBuf(const IOBuf::BlockRef& ref);
+    SingleIOBuf(const SingleIOBuf& other);
+    SingleIOBuf& operator=(const SingleIOBuf& rhs);
+    void swap(SingleIOBuf& other);
+
+    // Allocates a contiguous memory region of the specified size.
+    // Returns a pointer to the start of allocated space within the block.
+    void* allocate(uint32_t size);
+    // Deallocates the block if the given pointer matches its starting address.
+    void deallocate(void* p);
+
+    // Reallocates the current buffer to a larger size.
+    void* reallocate_downward(uint32_t new_size,
+                            uint32_t in_use_back,
+                            uint32_t in_use_front);

Review Comment:
   All done.



-- 
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: dev-unsubscr...@brpc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to