GRPC C++  1.30.0
Public Member Functions | Protected Member Functions | Friends
grpc::ProtoBufferWriter Class Reference

This is a specialization of the protobuf class ZeroCopyOutputStream. More...

#include <proto_buffer_writer.h>

Public Member Functions

 ProtoBufferWriter (ByteBuffer *byte_buffer, int block_size, int total_size)
 Constructor for this derived class. More...
 
 ~ProtoBufferWriter ()
 
bool Next (void **data, int *size) override
 Give the proto library the next buffer of bytes and its size. More...
 
void BackUp (int count) override
 Backup by count bytes because Next returned more bytes than needed (only used in the last buffer). More...
 
int64_t ByteCount () const override
 Returns the total number of bytes written since this object was created. More...
 

Protected Member Functions

grpc_slice_bufferslice_buffer ()
 
void set_byte_count (int64_t byte_count)
 

Friends

class internal::ProtoBufferWriterPeer
 

Detailed Description

This is a specialization of the protobuf class ZeroCopyOutputStream.

The principle is to give the proto layer one buffer of bytes at a time that it can use to serialize the next portion of the message, with the option to "backup" if more buffer is given than required at the last buffer.

Read more about ZeroCopyOutputStream interface here: https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.io.zero_copy_stream#ZeroCopyOutputStream

Constructor & Destructor Documentation

◆ ProtoBufferWriter()

grpc::ProtoBufferWriter::ProtoBufferWriter ( ByteBuffer byte_buffer,
int  block_size,
int  total_size 
)
inline

Constructor for this derived class.

Parameters
[out]byte_bufferA pointer to the grpc::ByteBuffer created
block_sizeHow big are the chunks to allocate at a time
total_sizeHow many total bytes are required for this proto

Create an empty raw byte buffer and look at its underlying slice buffer

◆ ~ProtoBufferWriter()

grpc::ProtoBufferWriter::~ProtoBufferWriter ( )
inline

Member Function Documentation

◆ BackUp()

void grpc::ProtoBufferWriter::BackUp ( int  count)
inlineoverride

Backup by count bytes because Next returned more bytes than needed (only used in the last buffer).

count must be less than or equal too the last buffer returned from next.

  1. Remove the partially-used last slice from the slice buffer
  2. Split it into the needed (if any) and unneeded part
  3. Add the needed part back to the slice buffer
  4. Mark that we still have the remaining part (for later use/unref)

◆ ByteCount()

int64_t grpc::ProtoBufferWriter::ByteCount ( ) const
inlineoverride

Returns the total number of bytes written since this object was created.

◆ Next()

bool grpc::ProtoBufferWriter::Next ( void **  data,
int *  size 
)
inlineoverride

Give the proto library the next buffer of bytes and its size.

It is safe for the caller to write from data[0, size - 1].

If we have a backup slice, we should use it first

◆ set_byte_count()

void grpc::ProtoBufferWriter::set_byte_count ( int64_t  byte_count)
inlineprotected

◆ slice_buffer()

grpc_slice_buffer* grpc::ProtoBufferWriter::slice_buffer ( )
inlineprotected

Friends And Related Function Documentation

◆ internal::ProtoBufferWriterPeer

friend class internal::ProtoBufferWriterPeer
friend

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