ONE - On-device Neural Engine
Loading...
Searching...
No Matches
flatbuffers::grpc::MessageBuilder Class Reference

#include <grpc.h>

Collaboration diagram for flatbuffers::grpc::MessageBuilder:

Public Member Functions

 MessageBuilder (uoffset_t initial_size=1024)
 
 MessageBuilder (const MessageBuilder &other)=delete
 
MessageBuilderoperator= (const MessageBuilder &other)=delete
 
 MessageBuilder (MessageBuilder &&other)
 
 MessageBuilder (FlatBufferBuilder &&src, void(*dealloc)(void *, size_t)=&DefaultAllocator::dealloc)
 Create a MessageBuilder from a FlatBufferBuilder.
 
MessageBuilderoperator= (FlatBufferBuilder &&src)
 
MessageBuilderoperator= (MessageBuilder &&other)
 
void Swap (MessageBuilder &other)
 
uint8_t * ReleaseRaw (size_t &size, size_t &offset, grpc_slice &slice)
 
 ~MessageBuilder ()
 
template<class T >
Message< T > GetMessage ()
 
template<class T >
Message< T > ReleaseMessage ()
 
- Public Member Functions inherited from flatbuffers::FlatBufferBuilder
 FlatBufferBuilder (size_t initial_size=1024, Allocator *allocator=nullptr, bool own_allocator=false, size_t buffer_minalign=AlignOf< largest_scalar_t >())
 Default constructor for FlatBufferBuilder.
 
 FlatBufferBuilder (FlatBufferBuilder &&other)
 Move constructor for FlatBufferBuilder.
 
FlatBufferBuilderoperator= (FlatBufferBuilder &&other)
 Move assignment operator for FlatBufferBuilder.
 
void Swap (FlatBufferBuilder &other)
 
 ~FlatBufferBuilder ()
 
void Reset ()
 
void Clear ()
 Reset all the state in this FlatBufferBuilder so it can be reused to construct another buffer.
 
uoffset_t GetSize () const
 The current size of the serialized buffer, counting from the end.
 
uint8_t * GetBufferPointer () const
 Get the serialized buffer (after you call Finish()).
 
flatbuffers::span< uint8_t > GetBufferSpan () const
 Get the serialized buffer (after you call Finish()) as a span.
 
uint8_t * GetCurrentBufferPointer () const
 Get a pointer to an unfinished buffer.
 
 FLATBUFFERS_ATTRIBUTE (deprecated("use Release() instead")) DetachedBuffer ReleaseBufferPointer()
 Get the released pointer to the serialized buffer.
 
DetachedBuffer Release ()
 Get the released DetachedBuffer.
 
uint8_t * ReleaseRaw (size_t &size, size_t &offset)
 Get the released pointer to the serialized buffer.
 
size_t GetBufferMinAlignment () const
 get the minimum alignment this buffer needs to be accessed properly. This is only known once all elements have been written (after you call Finish()). You can use this information if you need to embed a FlatBuffer in some other buffer, such that you can later read it without first having to copy it into its own buffer.
 
void ForceDefaults (bool fd)
 In order to save space, fields that are set to their default value don't get serialized into the buffer.
 
void DedupVtables (bool dedup)
 By default vtables are deduped in order to save space.
 
Offset< StringCreateString (const char *str, size_t len)
 Store a string in the buffer, which can contain any binary data.
 
Offset< StringCreateString (const char *str)
 Store a string in the buffer, which is null-terminated.
 
Offset< StringCreateString (char *str)
 Store a string in the buffer, which is null-terminated.
 
Offset< StringCreateString (const std::string &str)
 Store a string in the buffer, which can contain any binary data.
 
Offset< StringCreateString (const String *str)
 Store a string in the buffer, which can contain any binary data.
 
template<typename T >
Offset< StringCreateString (const T &str)
 Store a string in the buffer, which can contain any binary data.
 
Offset< StringCreateSharedString (const char *str, size_t len)
 Store a string in the buffer, which can contain any binary data. If a string with this exact contents has already been serialized before, instead simply returns the offset of the existing string.
 
Offset< StringCreateSharedString (const char *str)
 Store a string in the buffer, which null-terminated. If a string with this exact contents has already been serialized before, instead simply returns the offset of the existing string.
 
Offset< StringCreateSharedString (const std::string &str)
 Store a string in the buffer, which can contain any binary data. If a string with this exact contents has already been serialized before, instead simply returns the offset of the existing string.
 
Offset< StringCreateSharedString (const String *str)
 Store a string in the buffer, which can contain any binary data. If a string with this exact contents has already been serialized before, instead simply returns the offset of the existing string.
 
template<typename T >
Offset< Vector< T > > CreateVector (const T *v, size_t len)
 Serialize an array into a FlatBuffer vector.
 
template<typename T >
Offset< Vector< Offset< T > > > CreateVector (const Offset< T > *v, size_t len)
 
template<typename T >
Offset< Vector< T > > CreateVector (const std::vector< T > &v)
 Serialize a std::vector into a FlatBuffer vector.
 
Offset< Vector< uint8_t > > CreateVector (const std::vector< bool > &v)
 
template<typename T >
Offset< Vector< T > > CreateVector (size_t vector_size, const std::function< T(size_t i)> &f)
 Serialize values returned by a function into a FlatBuffer vector. This is a convenience function that takes care of iteration for you.
 
template<typename T , typename F , typename S >
Offset< Vector< T > > CreateVector (size_t vector_size, F f, S *state)
 Serialize values returned by a function into a FlatBuffer vector. This is a convenience function that takes care of iteration for you.
 
Offset< Vector< Offset< String > > > CreateVectorOfStrings (const std::vector< std::string > &v)
 Serialize a std::vector<std::string> into a FlatBuffer vector. This is a convenience function for a common case.
 
template<typename T >
Offset< Vector< const T * > > CreateVectorOfStructs (const T *v, size_t len)
 Serialize an array of structs into a FlatBuffer vector.
 
template<typename T , typename S >
Offset< Vector< const T * > > CreateVectorOfNativeStructs (const S *v, size_t len, T((*const pack_func)(const S &)))
 Serialize an array of native structs into a FlatBuffer vector.
 
template<typename T , typename S >
Offset< Vector< const T * > > CreateVectorOfNativeStructs (const S *v, size_t len)
 Serialize an array of native structs into a FlatBuffer vector.
 
template<typename T >
Offset< Vector< const T * > > CreateVectorOfStructs (size_t vector_size, const std::function< void(size_t i, T *)> &filler)
 Serialize an array of structs into a FlatBuffer vector.
 
template<typename T , typename F , typename S >
Offset< Vector< const T * > > CreateVectorOfStructs (size_t vector_size, F f, S *state)
 Serialize an array of structs into a FlatBuffer vector.
 
template<typename T , typename Alloc >
Offset< Vector< const T * > > CreateVectorOfStructs (const std::vector< T, Alloc > &v)
 Serialize a std::vector of structs into a FlatBuffer vector.
 
template<typename T , typename S >
Offset< Vector< const T * > > CreateVectorOfNativeStructs (const std::vector< S > &v, T((*const pack_func)(const S &)))
 Serialize a std::vector of native structs into a FlatBuffer vector.
 
template<typename T , typename S >
Offset< Vector< const T * > > CreateVectorOfNativeStructs (const std::vector< S > &v)
 Serialize a std::vector of native structs into a FlatBuffer vector.
 
template<typename T >
Offset< Vector< const T * > > CreateVectorOfSortedStructs (std::vector< T > *v)
 Serialize a std::vector of structs into a FlatBuffer vector in sorted order.
 
template<typename T , typename S >
Offset< Vector< const T * > > CreateVectorOfSortedNativeStructs (std::vector< S > *v)
 Serialize a std::vector of native structs into a FlatBuffer vector in sorted order.
 
template<typename T >
Offset< Vector< const T * > > CreateVectorOfSortedStructs (T *v, size_t len)
 Serialize an array of structs into a FlatBuffer vector in sorted order.
 
template<typename T , typename S >
Offset< Vector< const T * > > CreateVectorOfSortedNativeStructs (S *v, size_t len)
 Serialize an array of native structs into a FlatBuffer vector in sorted order.
 
template<typename T >
Offset< Vector< Offset< T > > > CreateVectorOfSortedTables (Offset< T > *v, size_t len)
 Serialize an array of table offsets as a vector in the buffer in sorted order.
 
template<typename T >
Offset< Vector< Offset< T > > > CreateVectorOfSortedTables (std::vector< Offset< T > > *v)
 Serialize an array of table offsets as a vector in the buffer in sorted order.
 
uoffset_t CreateUninitializedVector (size_t len, size_t elemsize, uint8_t **buf)
 Specialized version of CreateVector for non-copying use cases. Write the data any time later to the returned buffer pointer buf.
 
template<typename T >
Offset< Vector< T > > CreateUninitializedVector (size_t len, T **buf)
 Specialized version of CreateVector for non-copying use cases. Write the data any time later to the returned buffer pointer buf.
 
template<typename T >
Offset< Vector< const T * > > CreateUninitializedVectorOfStructs (size_t len, T **buf)
 
template<typename T , typename U >
Offset< Vector< T > > CreateVectorScalarCast (const U *v, size_t len)
 
template<typename T >
Offset< const T * > CreateStruct (const T &structobj)
 Write a struct by itself, typically to be part of a union.
 
template<typename T >
void Finish (Offset< T > root, const char *file_identifier=nullptr)
 Finish serializing a buffer by writing the root offset.
 
template<typename T >
void FinishSizePrefixed (Offset< T > root, const char *file_identifier=nullptr)
 Finish a buffer with a 32 bit size field pre-fixed (size of the buffer following the size field). These buffers are NOT compatible with standard buffers created by Finish, i.e. you can't call GetRoot on them, you have to use GetSizePrefixedRoot instead. All >32 bit quantities in this buffer will be aligned when the whole size pre-fixed buffer is aligned. These kinds of buffers are useful for creating a stream of FlatBuffers.
 
void SwapBufAllocator (FlatBufferBuilder &other)
 

Additional Inherited Members

- Static Public Attributes inherited from flatbuffers::FlatBufferBuilder
static const size_t kFileIdentifierLength = 4
 The length of a FlatBuffer file header.
 
- Protected Types inherited from flatbuffers::FlatBufferBuilder
typedef std::set< Offset< String >, StringOffsetCompareStringOffsetMap
 
- Protected Member Functions inherited from flatbuffers::FlatBufferBuilder
 FlatBufferBuilder (const FlatBufferBuilder &)
 
FlatBufferBuilderoperator= (const FlatBufferBuilder &)
 
void Finish (uoffset_t root, const char *file_identifier, bool size_prefix)
 
- Protected Attributes inherited from flatbuffers::FlatBufferBuilder
vector_downward buf_
 
uoffset_t num_field_loc
 
voffset_t max_voffset_
 
bool nested
 
bool finished
 
size_t minalign_
 
bool force_defaults_
 
bool dedup_vtables_
 
StringOffsetMapstring_pool
 

Detailed Description

Definition at line 173 of file grpc.h.

Constructor & Destructor Documentation

◆ MessageBuilder() [1/4]

flatbuffers::grpc::MessageBuilder::MessageBuilder ( uoffset_t  initial_size = 1024)
inlineexplicit

Definition at line 176 of file grpc.h.

177 : FlatBufferBuilder(initial_size, &slice_allocator_, false)
178 {
179 }
FlatBufferBuilder(size_t initial_size=1024, Allocator *allocator=nullptr, bool own_allocator=false, size_t buffer_minalign=AlignOf< largest_scalar_t >())
Default constructor for FlatBufferBuilder.

◆ MessageBuilder() [2/4]

flatbuffers::grpc::MessageBuilder::MessageBuilder ( const MessageBuilder other)
delete

◆ MessageBuilder() [3/4]

flatbuffers::grpc::MessageBuilder::MessageBuilder ( MessageBuilder &&  other)
inline

Definition at line 184 of file grpc.h.

184 : FlatBufferBuilder(1024, &slice_allocator_, false)
185 {
186 // Default construct and swap idiom.
187 Swap(other);
188 }
void Swap(MessageBuilder &other)
Definition grpc.h:228

References Swap().

◆ MessageBuilder() [4/4]

flatbuffers::grpc::MessageBuilder::MessageBuilder ( FlatBufferBuilder &&  src,
void(*)(void *, size_t)  dealloc = &DefaultAllocator::dealloc 
)
inlineexplicit

Create a MessageBuilder from a FlatBufferBuilder.

Definition at line 191 of file grpc.h.

193 : FlatBufferBuilder(1024, &slice_allocator_, false)
194 {
195 src.Swap(*this);
196 src.SwapBufAllocator(*this);
197 if (buf_.capacity())
198 {
199 uint8_t *buf = buf_.scratch_data(); // pointer to memory
200 size_t capacity = buf_.capacity(); // size of memory
201 slice_allocator_.slice_ = grpc_slice_new_with_len(buf, capacity, dealloc);
202 }
203 else
204 {
205 slice_allocator_.slice_ = grpc_empty_slice();
206 }
207 }
uint8_t * scratch_data() const

References flatbuffers::FlatBufferBuilder::buf_, flatbuffers::vector_downward::capacity(), flatbuffers::vector_downward::scratch_data(), and flatbuffers::FlatBufferBuilder::Swap().

◆ ~MessageBuilder()

flatbuffers::grpc::MessageBuilder::~MessageBuilder ( )
inline

Definition at line 251 of file grpc.h.

251{}

Member Function Documentation

◆ GetMessage()

template<class T >
Message< T > flatbuffers::grpc::MessageBuilder::GetMessage ( )
inline

Definition at line 256 of file grpc.h.

257 {
258 auto buf_data = buf_.scratch_data(); // pointer to memory
259 auto buf_size = buf_.capacity(); // size of memory
260 auto msg_data = buf_.data(); // pointer to msg
261 auto msg_size = buf_.size(); // size of msg
262 // Do some sanity checks on data/size
263 FLATBUFFERS_ASSERT(msg_data);
264 FLATBUFFERS_ASSERT(msg_size);
265 FLATBUFFERS_ASSERT(msg_data >= buf_data);
266 FLATBUFFERS_ASSERT(msg_data + msg_size <= buf_data + buf_size);
267 // Calculate offsets from the buffer start
268 auto begin = msg_data - buf_data;
269 auto end = begin + msg_size;
270 // Get the slice we are working with (no refcount change)
271 grpc_slice slice = slice_allocator_.get_slice(buf_data, buf_size);
272 // Extract a subslice of the existing slice (increment refcount)
273 grpc_slice subslice = grpc_slice_sub(slice, begin, end);
274 // Wrap the subslice in a `Message<T>`, but don't increment refcount
275 Message<T> msg(subslice, false);
276 return msg;
277 }
#define FLATBUFFERS_ASSERT
Definition base.h:37
ShapeIterator end(const Shape &s)
int32_t begin[5]
Definition Slice.cpp:33

References begin, flatbuffers::FlatBufferBuilder::buf_, flatbuffers::vector_downward::capacity(), flatbuffers::vector_downward::data(), FLATBUFFERS_ASSERT, flatbuffers::vector_downward::scratch_data(), and flatbuffers::vector_downward::size().

◆ operator=() [1/3]

MessageBuilder & flatbuffers::grpc::MessageBuilder::operator= ( const MessageBuilder other)
delete

◆ operator=() [2/3]

MessageBuilder & flatbuffers::grpc::MessageBuilder::operator= ( FlatBufferBuilder &&  src)
inline

Move-assign a FlatBufferBuilder to a MessageBuilder. Only FlatBufferBuilder with default allocator (basically, nullptr) is supported.

Definition at line 212 of file grpc.h.

213 {
214 // Move construct a temporary and swap
215 MessageBuilder temp(std::move(src));
216 Swap(temp);
217 return *this;
218 }
MessageBuilder(uoffset_t initial_size=1024)
Definition grpc.h:176

References Swap().

◆ operator=() [3/3]

MessageBuilder & flatbuffers::grpc::MessageBuilder::operator= ( MessageBuilder &&  other)
inline

Definition at line 220 of file grpc.h.

221 {
222 // Move construct a temporary and swap
223 MessageBuilder temp(std::move(other));
224 Swap(temp);
225 return *this;
226 }

References Swap().

◆ ReleaseMessage()

template<class T >
Message< T > flatbuffers::grpc::MessageBuilder::ReleaseMessage ( )
inline

Definition at line 279 of file grpc.h.

280 {
281 Message<T> msg = GetMessage<T>();
282 Reset();
283 return msg;
284 }

References flatbuffers::FlatBufferBuilder::Reset().

◆ ReleaseRaw()

uint8_t * flatbuffers::grpc::MessageBuilder::ReleaseRaw ( size_t &  size,
size_t &  offset,
grpc_slice &  slice 
)
inline

Definition at line 243 of file grpc.h.

244 {
246 slice = slice_allocator_.slice_;
247 slice_allocator_.slice_ = grpc_empty_slice();
248 return buf;
249 }
uint8_t * ReleaseRaw(size_t &size, size_t &offset)
Get the released pointer to the serialized buffer.
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540
int32_t size[5]
Definition Slice.cpp:35

References offset(), flatbuffers::FlatBufferBuilder::ReleaseRaw(), and size.

◆ Swap()

void flatbuffers::grpc::MessageBuilder::Swap ( MessageBuilder other)
inline

Definition at line 228 of file grpc.h.

229 {
230 slice_allocator_.swap(other.slice_allocator_);
232 // After swapping the FlatBufferBuilder, we swap back the allocator, which
233 // restores the original allocator back in place. This is necessary because
234 // MessageBuilder's allocator is its own member (SliceAllocatorMember). The
235 // allocator passed to FlatBufferBuilder::vector_downward must point to this
236 // member.
237 buf_.swap_allocator(other.buf_);
238 }
void Swap(FlatBufferBuilder &other)
void swap_allocator(vector_downward &other)

References flatbuffers::FlatBufferBuilder::buf_, flatbuffers::FlatBufferBuilder::Swap(), and flatbuffers::vector_downward::swap_allocator().

Referenced by MessageBuilder(), operator=(), and operator=().


The documentation for this class was generated from the following file: