1
#pragma once
2

            
3
#include <cstdint>
4
#include <string>
5

            
6
#include "envoy/buffer/buffer.h"
7
#include "envoy/common/platform.h"
8
#include "envoy/config/core/v3/grpc_service.pb.h"
9
#include "envoy/server/factory_context.h"
10

            
11
#include "grpcpp/grpcpp.h"
12

            
13
namespace Envoy {
14
namespace Grpc {
15

            
16
class GoogleGrpcUtils {
17
public:
18
  /**
19
   * Build grpc::ByteBuffer which aliases the data in a Buffer::InstancePtr.
20
   * @param buffer source data container.
21
   * @return byteBuffer target container aliased to the data in Buffer::Instance and owning the
22
   * Buffer::Instance.
23
   */
24
  static grpc::ByteBuffer makeByteBuffer(Buffer::InstancePtr&& buffer);
25

            
26
  /**
27
   * Build Buffer::Instance which aliases the data in a grpc::ByteBuffer.
28
   * @param buffer source data container.
29
   * @return a Buffer::InstancePtr aliased to the data in the provided grpc::ByteBuffer and
30
   * owning the corresponding grpc::Slice(s) or nullptr if the grpc::ByteBuffer is bad.
31
   */
32
  static Buffer::InstancePtr makeBufferInstance(const grpc::ByteBuffer& buffer);
33

            
34
  /**
35
   * Build grpc::ChannelArguments from gRPC service config.
36
   * @param config Google gRPC config.
37
   * @return grpc::ChannelArguments corresponding to config.
38
   */
39
  static grpc::ChannelArguments
40
  channelArgsFromConfig(const envoy::config::core::v3::GrpcService& config);
41

            
42
  /**
43
   * Build gRPC channel based on the given GrpcService configuration.
44
   * @param config Google gRPC config.
45
   * @param api reference to the Api object
46
   * @return static std::shared_ptr<grpc::Channel> a gRPC channel.
47
   */
48
  static std::shared_ptr<grpc::Channel>
49
  createChannel(const envoy::config::core::v3::GrpcService& config,
50
                Server::Configuration::CommonFactoryContext& context);
51
};
52

            
53
} // namespace Grpc
54
} // namespace Envoy