-
Notifications
You must be signed in to change notification settings - Fork 1
/
grpc_util.h
28 lines (25 loc) · 986 Bytes
/
grpc_util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <sys/time.h>
#include <grpc++/grpc++.h>
#include "grpc++/impl/codegen/proto_utils.h"
#include "grpc++/support/byte_buffer.h"
inline double GetTimestamp() {
struct timeval t0;
gettimeofday(&t0, 0);
return double(t0.tv_sec * 1000.0 + t0.tv_usec / 1000.0);
}
// A ZeroCopyInputStream that reads from a grpc::ByteBuffer.
class GrpcByteBufferSource : public ::grpc::protobuf::io::ZeroCopyInputStream {
public:
GrpcByteBufferSource();
bool Init(const ::grpc::ByteBuffer& src); // Can be called multiple times.
bool Next(const void** data, int* size) override;
void BackUp(int count) override;
bool Skip(int count) override;
::grpc::protobuf::int64 ByteCount() const override;
private:
std::vector<::grpc::Slice> slices_;
int cur_; // Current slice index.
int left_; // Number of bytes in slices_[cur_] left to yield.
const char* ptr_; // Address of next byte in slices_[cur_] to yield.
::grpc::protobuf::int64 byte_count_;
};