chenBright commented on code in PR #3558:
URL: https://github.com/apache/brpc/pull/3558#discussion_r4100723629


##########
src/brpc/flatbuffers/message.h:
##########
@@ -0,0 +1,166 @@
+// 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.
+
+#ifndef BRPC_FLATBUFFERS_MESSAGE_H
+#define BRPC_FLATBUFFERS_MESSAGE_H
+
+#include "butil/config.h"
+
+#if BRPC_WITH_FLATBUFFERS
+#include <cstddef>
+#include <cstdint>
+#include <utility>
+#include <flatbuffers/flatbuffers.h>
+#include "butil/single_iobuf.h"
+#include "brpc/nonreflectable_message.h"
+
+namespace brpc {
+namespace flatbuffers {
+
+// Space preceding a payload, available to a future RPC transport.
+constexpr uint32_t kDefaultMetaSize = 64;
+// IOBuf slices need not start at an aligned address. The allocator corrects 
it.
+constexpr size_t kBufferAlignment = 64;
+
+class MessageBuilder;
+
+// FlatBufferBuilder cannot recover from a null allocation. Allocation failure
+// and sizes outside FlatBuffers' offset range are fatal, even in release 
builds.
+class SlabAllocator : public ::flatbuffers::Allocator {
+public:
+    SlabAllocator() : _data(nullptr), _capacity(0) {}
+    SlabAllocator(const SlabAllocator&) = delete;
+    SlabAllocator& operator=(const SlabAllocator&) = delete;
+    SlabAllocator(SlabAllocator&& other) noexcept : SlabAllocator() {
+        swap(other);
+    }
+    SlabAllocator& operator=(SlabAllocator&& other) noexcept;
+
+    uint8_t* allocate(size_t size) override;
+    void deallocate(uint8_t* p, size_t size) override;
+    uint8_t* reallocate_downward(uint8_t* old_p, size_t old_size,
+                                size_t new_size, size_t in_use_back,
+                                size_t in_use_front) override;
+    void swap(SlabAllocator& other) noexcept;
+
+private:
+    butil::SingleIOBuf _iobuf;
+    uint8_t* _data;
+    size_t _capacity;
+    friend class MessageBuilder;
+};
+
+// Construct the allocator before the FlatBufferBuilder base uses it, and
+// destroy it after that base has returned its buffer.
+struct SlabAllocatorMember {
+    SlabAllocator slab_allocator_;
+};
+
+// A move-only message. Parsing checks framing, not the schema: Verify<T>()
+// must succeed before reading data received from an untrusted peer.
+class Message : public NonreflectableMessage<Message> {
+public:
+    Message() : _meta_size(0), _msg_size(0) {}
+    Message(const Message&) = delete;
+    Message& operator=(const Message&) = delete;

Review Comment:
   Please use `DISALLOW_COPY_AND_ASSIGN(Message)`.



##########
src/brpc/flatbuffers/service.h:
##########
@@ -0,0 +1,127 @@
+// 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.
+
+#ifndef BRPC_FLATBUFFERS_SERVICE_H
+#define BRPC_FLATBUFFERS_SERVICE_H
+
+#include "butil/config.h"
+
+#if BRPC_WITH_FLATBUFFERS
+#include <cstdint>
+#include <memory>
+#include <string>
+#include <vector>
+
+namespace google {
+namespace protobuf {
+class Closure;
+class RpcController;
+}  // namespace protobuf
+}  // namespace google
+
+namespace brpc {
+namespace flatbuffers {
+class Message;
+class ServiceDescriptor;
+
+struct BrpcDescriptorTable {
+    // A namespace, optionally followed by one period. Empty means global 
scope.
+    std::string prefix;
+    std::string service_name;
+    // Whitespace-separated method names in declaration order.
+    std::string method_name_list;
+    // Stable wire IDs, NOT array positions. Empty retains legacy ordinal IDs.
+    // New schemas should specify every ID; IDs must be nonnegative and unique.
+    std::vector<int> method_ids;
+};
+
+class MethodDescriptor {
+public:
+    MethodDescriptor(const std::string& name, const ServiceDescriptor* service,
+                     int index);
+    const std::string& name() const { return _name; }
+    const std::string& full_name() const { return _full_name; }
+    int index() const { return _index; }
+    const ServiceDescriptor* service() const { return _service; }
+
+private:
+    std::string _name;
+    std::string _full_name;
+    const ServiceDescriptor* _service;
+    int _index;
+};
+
+// Immutable after successful initialization. Owns all method descriptors.
+class ServiceDescriptor {
+public:
+    ServiceDescriptor() : _index(0) {}
+    ServiceDescriptor(const ServiceDescriptor&) = delete;
+    ServiceDescriptor& operator=(const ServiceDescriptor&) = delete;
+    int init(const BrpcDescriptorTable& table);
+    const std::string& name() const { return _name; }
+    const std::string& full_name() const { return _full_name; }
+    // MurmurHash3 of the canonical fully-qualified service name, seed 1.
+    uint32_t index() const { return _index; }
+    int method_count() const { return static_cast<int>(_methods.size()); }
+    // Dense declaration-order lookup, for enumeration and generated stubs.
+    const MethodDescriptor* method(int position) const;
+    // Sparse stable-ID lookup, for wire dispatch. Missing IDs return nullptr.
+    const MethodDescriptor* FindMethodByIndex(int id) const;
+
+private:
+    std::string _name;
+    std::string _full_name;
+    uint32_t _index;
+    std::vector<std::unique_ptr<MethodDescriptor> > _methods;
+};
+
+// On success the caller owns *out; on failure *out is unchanged.
+int parse_service_descriptors(const BrpcDescriptorTable& table,
+                              ServiceDescriptor** out);
+
+class RpcChannel {
+public:
+    RpcChannel() = default;
+    virtual ~RpcChannel() = default;
+    RpcChannel(const RpcChannel&) = delete;
+    RpcChannel& operator=(const RpcChannel&) = delete;

Review Comment:
   Same as above.



##########
src/brpc/flatbuffers/service.h:
##########
@@ -0,0 +1,127 @@
+// 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.
+
+#ifndef BRPC_FLATBUFFERS_SERVICE_H
+#define BRPC_FLATBUFFERS_SERVICE_H
+
+#include "butil/config.h"
+
+#if BRPC_WITH_FLATBUFFERS
+#include <cstdint>
+#include <memory>
+#include <string>
+#include <vector>
+
+namespace google {
+namespace protobuf {
+class Closure;
+class RpcController;
+}  // namespace protobuf
+}  // namespace google
+
+namespace brpc {
+namespace flatbuffers {
+class Message;
+class ServiceDescriptor;
+
+struct BrpcDescriptorTable {
+    // A namespace, optionally followed by one period. Empty means global 
scope.
+    std::string prefix;
+    std::string service_name;
+    // Whitespace-separated method names in declaration order.
+    std::string method_name_list;
+    // Stable wire IDs, NOT array positions. Empty retains legacy ordinal IDs.
+    // New schemas should specify every ID; IDs must be nonnegative and unique.
+    std::vector<int> method_ids;
+};
+
+class MethodDescriptor {
+public:
+    MethodDescriptor(const std::string& name, const ServiceDescriptor* service,
+                     int index);
+    const std::string& name() const { return _name; }
+    const std::string& full_name() const { return _full_name; }
+    int index() const { return _index; }
+    const ServiceDescriptor* service() const { return _service; }
+
+private:
+    std::string _name;
+    std::string _full_name;
+    const ServiceDescriptor* _service;
+    int _index;
+};
+
+// Immutable after successful initialization. Owns all method descriptors.
+class ServiceDescriptor {
+public:
+    ServiceDescriptor() : _index(0) {}
+    ServiceDescriptor(const ServiceDescriptor&) = delete;
+    ServiceDescriptor& operator=(const ServiceDescriptor&) = delete;

Review Comment:
   Same as above.



##########
src/brpc/flatbuffers/service.h:
##########
@@ -0,0 +1,127 @@
+// 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.
+
+#ifndef BRPC_FLATBUFFERS_SERVICE_H
+#define BRPC_FLATBUFFERS_SERVICE_H
+
+#include "butil/config.h"
+
+#if BRPC_WITH_FLATBUFFERS
+#include <cstdint>
+#include <memory>
+#include <string>
+#include <vector>
+
+namespace google {
+namespace protobuf {
+class Closure;
+class RpcController;
+}  // namespace protobuf
+}  // namespace google
+
+namespace brpc {
+namespace flatbuffers {
+class Message;
+class ServiceDescriptor;
+
+struct BrpcDescriptorTable {
+    // A namespace, optionally followed by one period. Empty means global 
scope.
+    std::string prefix;
+    std::string service_name;
+    // Whitespace-separated method names in declaration order.
+    std::string method_name_list;
+    // Stable wire IDs, NOT array positions. Empty retains legacy ordinal IDs.
+    // New schemas should specify every ID; IDs must be nonnegative and unique.
+    std::vector<int> method_ids;
+};
+
+class MethodDescriptor {
+public:
+    MethodDescriptor(const std::string& name, const ServiceDescriptor* service,
+                     int index);
+    const std::string& name() const { return _name; }
+    const std::string& full_name() const { return _full_name; }
+    int index() const { return _index; }
+    const ServiceDescriptor* service() const { return _service; }
+
+private:
+    std::string _name;
+    std::string _full_name;
+    const ServiceDescriptor* _service;
+    int _index;
+};
+
+// Immutable after successful initialization. Owns all method descriptors.
+class ServiceDescriptor {
+public:
+    ServiceDescriptor() : _index(0) {}
+    ServiceDescriptor(const ServiceDescriptor&) = delete;
+    ServiceDescriptor& operator=(const ServiceDescriptor&) = delete;
+    int init(const BrpcDescriptorTable& table);
+    const std::string& name() const { return _name; }
+    const std::string& full_name() const { return _full_name; }
+    // MurmurHash3 of the canonical fully-qualified service name, seed 1.
+    uint32_t index() const { return _index; }
+    int method_count() const { return static_cast<int>(_methods.size()); }
+    // Dense declaration-order lookup, for enumeration and generated stubs.
+    const MethodDescriptor* method(int position) const;
+    // Sparse stable-ID lookup, for wire dispatch. Missing IDs return nullptr.
+    const MethodDescriptor* FindMethodByIndex(int id) const;
+
+private:
+    std::string _name;
+    std::string _full_name;
+    uint32_t _index;
+    std::vector<std::unique_ptr<MethodDescriptor> > _methods;
+};
+
+// On success the caller owns *out; on failure *out is unchanged.
+int parse_service_descriptors(const BrpcDescriptorTable& table,
+                              ServiceDescriptor** out);
+
+class RpcChannel {
+public:
+    RpcChannel() = default;
+    virtual ~RpcChannel() = default;
+    RpcChannel(const RpcChannel&) = delete;
+    RpcChannel& operator=(const RpcChannel&) = delete;
+    virtual void FBCallMethod(const MethodDescriptor* method,
+                              google::protobuf::RpcController* controller,
+                              const Message* request, Message* response,
+                              google::protobuf::Closure* done) = 0;
+};
+
+class Service {
+public:
+    Service() = default;
+    virtual ~Service() = default;
+    Service(const Service&) = delete;
+    Service& operator=(const Service&) = delete;

Review Comment:
   Same as above.



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