wwbmmm commented on code in PR #2171:
URL: https://github.com/apache/brpc/pull/2171#discussion_r1168130775


##########
CMakeLists.txt:
##########
@@ -152,6 +152,7 @@ endif()
 
 find_package(Protobuf REQUIRED)
 find_package(Threads REQUIRED)
+find_package (bson-1.0 1.7 REQUIRED)

Review Comment:
   这个是不是做成一个可选的编译选项比较好



##########
src/brpc/global.cpp:
##########
@@ -509,10 +509,12 @@ static void GlobalInitializeOrDieImpl() {
     }
 
     Protocol mongo_protocol = { ParseMongoMessage,
-                                NULL, NULL,
-                                ProcessMongoRequest, NULL,
+                                SerializeMongoRequest,
+                                PackMongoRequest,
+                                ProcessMongoRequest,

Review Comment:
   ProcessMongoRequest还要保留吗?



##########
src/butil/bson_util.cc:
##########
@@ -0,0 +1,244 @@
+// 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.
+
+#include "butil/bson_util.h"
+
+#include <cassert>
+
+#include "butil/logging.h"
+
+static ssize_t BsonReaderWrapper(void* handle, void* buf, size_t count) {
+    butil::IOBuf* iobuf = static_cast<butil::IOBuf*>(handle);
+    return iobuf->cutn(buf, count);
+}
+
+namespace butil {
+namespace bson {
+
+BsonEnumerator::BsonEnumerator(IOBuf* iobuf)
+    : _buf(iobuf)
+    , _reader(::bson_reader_new_from_handle(_buf, BsonReaderWrapper, NULL)) { 
+    if (!_reader) {
+        _has_error = true;
+    }
+}
+
+bool BsonEnumerator::HasError() {
+    return _has_error;
+}
+
+const bson_t* BsonEnumerator::Next() {
+    if (_has_error) {
+        return nullptr;
+    }
+
+    bool eof;
+    const bson_t* doc = bson_reader_read(_reader, &eof);
+    if (!doc && !eof) {
+        _has_error = true;
+    }
+    return doc;
+}
+
+BsonEnumerator::~BsonEnumerator() {
+    if (_reader) {
+        bson_reader_destroy(_reader);
+    }
+}
+
+UniqueBsonPtr ExtractBsonFromIOBuf(IOBuf& iobuf) {
+    uint32_t bson_length;
+    const size_t n = iobuf.copy_to(&bson_length, sizeof(bson_length));
+    if (n < sizeof(bson_length) || iobuf.size() < bson_length) {
+        return nullptr;
+    }
+    std::unique_ptr<uint8_t[]> buffer(new uint8_t[bson_length]);
+    iobuf.copy_to(buffer.get(), bson_length);
+    return UniqueBsonPtr(bson_new_from_data(buffer.get(), bson_length));
+}
+
+bool bson_get_double(bson_t* doc, const char *key, double *value) {
+    assert(doc);

Review Comment:
   这个可以用DCHECK?



##########
src/brpc/policy/mongo_protocol.cpp:
##########
@@ -183,13 +253,13 @@ void ProcessMongoRequest(InputMessageBase* msg_base) {
 
     const google::protobuf::ServiceDescriptor* srv_des = 
MongoService::descriptor();
     if (1 != srv_des->method_count()) {
-        LOG(WARNING) << "method count:" << srv_des->method_count()
-                     << " of MongoService should be equal to 1!";
+        LOG(WARNING) << "method count: " << srv_des->method_count()
+                     << "of MongoService should be equal to 1!";

Review Comment:
   这个空格不应该删吧



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