yiguolei commented on code in PR #52735:
URL: https://github.com/apache/doris/pull/52735#discussion_r2193702315
##########
be/src/vec/common/string_buffer.hpp:
##########
@@ -91,4 +93,105 @@ class BufferReadable {
using VectorBufferReader = BufferReadable;
using BufferReader = BufferReadable;
+// Write a variable-length unsigned integer to the buffer
+// maybe it's better not to use this
+inline void write_var_uint(UInt64 x, BufferWritable& buf) {
+ char bytes[9];
+ uint8_t i = 0;
+ while (i < 9) {
+ uint8_t byte = x & 0x7F;
+ if (x > 0x7F) {
+ byte |= 0x80;
+ }
+
+ bytes[i++] = byte;
+
+ x >>= 7;
+ if (!x) {
+ break;
+ }
+ }
+ buf.write((char*)&i, 1);
+ buf.write(bytes, i);
+}
+
+inline void read_var_uint(UInt64& x, BufferReadable& buf) {
+ x = 0;
+ // get length from first byte firstly
+ uint8_t len = 0;
+ buf.read((char*)&len, 1);
+ auto ref = buf.read(len);
+ // read data and set it to x per byte.
+ char* bytes = const_cast<char*>(ref.data);
+ for (size_t i = 0; i < 9; ++i) {
+ UInt64 byte = bytes[i];
+ x |= (byte & 0x7F) << (7 * i);
+
+ if (!(byte & 0x80)) {
+ return;
+ }
+ }
+}
+
+template <typename Type>
+void write_binary(const Type& x, BufferWritable& buf) {
Review Comment:
是不是把这两个方法做为static 方法,放到bufferwriteable和buffereadable 里更好啊?
--
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]