17#ifndef FLATBUFFERS_GRPC_H_
18#define FLATBUFFERS_GRPC_H_
23#include "grpcpp/support/byte_buffer.h"
24#include "grpcpp/support/slice.h"
37 Message(::grpc::Slice slice) : slice_(slice) {}
49 const uint8_t *
data()
const {
return slice_.begin(); }
51 size_t size()
const {
return slice_.size(); }
55 return verifier.VerifyBuffer<T>(
nullptr);
60 const T *
GetRoot()
const {
return flatbuffers::GetRoot<T>(
data()); }
95 swap(slice_, other.slice_);
102 slice_ = ::grpc::Slice(
size);
103 return const_cast<uint8_t *
>(slice_.begin());
109 slice_ = ::grpc::Slice();
113 size_t new_size,
size_t in_use_back,
114 size_t in_use_front)
override {
118 ::grpc::Slice old_slice = slice_;
119 ::grpc::Slice new_slice = ::grpc::Slice(new_size);
120 uint8_t *new_p =
const_cast<uint8_t *
>(new_slice.begin());
128 ::grpc::Slice &get_slice(uint8_t *
p,
size_t size) {
134 ::grpc::Slice slice_;
143struct SliceAllocatorMember {
167 void (*dealloc)(
void *,
171 src.SwapBufAllocator(*
this);
175 slice_allocator_.slice_ = ::grpc::Slice(buf, capacity, dealloc);
177 slice_allocator_.slice_ = ::grpc::Slice();
199 slice_allocator_.swap(other.slice_allocator_);
214 slice = slice_allocator_.slice_;
215 slice_allocator_.slice_ = ::grpc::Slice();
235 auto begin = msg_data - buf_data;
236 auto end =
begin + msg_size;
238 ::grpc::Slice slice = slice_allocator_.get_slice(buf_data, buf_size);
240 ::grpc::Slice subslice = slice.sub(
begin, end);
261template<
class T>
class SerializationTraits<
flatbuffers::grpc::Message<T>> {
264 ByteBuffer *buffer,
bool *own_buffer) {
269 return grpc::Status::OK;
273 static grpc::Status Deserialize(ByteBuffer *buf,
276 if (!buf->TrySingleSlice(&slice).ok()) {
277 if (!buf->DumpToSingleSlice(&slice).ok()) {
279 return ::grpc::Status(::grpc::StatusCode::INTERNAL,
"No payload");
284#if FLATBUFFERS_GRPC_DISABLE_AUTO_VERIFICATION
285 return ::grpc::Status::OK;
288 return ::grpc::Status::OK;
290 return ::grpc::Status(::grpc::StatusCode::INTERNAL,
291 "Message verification failed");
#define FLATBUFFERS_ASSERT
void memcpy_downward(uint8_t *old_p, size_t old_size, uint8_t *new_p, size_t new_size, size_t in_use_back, size_t in_use_front)
static void dealloc(void *p, size_t)
uint8_t * ReleaseRaw(size_t &size, size_t &offset)
Get the released pointer to the serialized buffer.
vector_downward< SizeT > buf_
void Swap(FlatBufferBuilderImpl &other)
MessageBuilder & operator=(FlatBufferBuilder &&src)
void Swap(MessageBuilder &other)
Message< T > GetMessage()
MessageBuilder(const MessageBuilder &other)=delete
uint8_t * ReleaseRaw(size_t &size, size_t &offset, ::grpc::Slice &slice)
MessageBuilder(MessageBuilder &&other)
Message< T > ReleaseMessage()
MessageBuilder & operator=(MessageBuilder &&other)
MessageBuilder & operator=(const MessageBuilder &other)=delete
MessageBuilder(uoffset_t initial_size=1024)
MessageBuilder(FlatBufferBuilder &&src, void(*dealloc)(void *, size_t)=&DefaultAllocator::dealloc)
Create a MessageBuilder from a FlatBufferBuilder.
const uint8_t * mutable_data() const
const ::grpc::Slice & BorrowSlice() const
Message(::grpc::Slice slice)
const uint8_t * data() const
Message(Message &&other)=default
Message(const Message &other)=delete
Message & operator=(Message &&other)=default
const T * GetRoot() const
Message & operator=(const Message &other)=delete
SliceAllocator & operator=(SliceAllocator &&other)
virtual void deallocate(uint8_t *p, size_t size) override
SliceAllocator & operator=(const SliceAllocator &other)=delete
virtual ~SliceAllocator()
virtual uint8_t * allocate(size_t size) override
SliceAllocator(SliceAllocator &&other)
virtual 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
SliceAllocator(const SliceAllocator &other)=delete
void swap(SliceAllocator &other)
void swap_allocator(vector_downward &other)
uint8_t * scratch_data() const
__global uchar * offset(const Image *img, int x, int y)