Public Member Functions | Protected Member Functions | Private Attributes | Friends | List of all members
grpc::ProtoBufferWriter Class Reference

#include <proto_buffer_writer.h>

Inheritance diagram for grpc::ProtoBufferWriter:
Inheritance graph
[legend]

Public Member Functions

void BackUp (int count) override
 
int64_t ByteCount () const override
 Returns the total number of bytes written since this object was created. More...
 
bool Next (void **data, int *size) override
 
 ProtoBufferWriter (ByteBuffer *byte_buffer, int block_size, int total_size)
 
 ~ProtoBufferWriter () override
 

Protected Member Functions

void set_byte_count (int64_t byte_count)
 
grpc_slice_bufferslice_buffer ()
 

Private Attributes

grpc_slice backup_slice_
 
const int block_size_
 size to alloc for each new grpc_slice needed More...
 
int64_t byte_count_
 bytes written since this object was created More...
 
bool have_backup_
 if we are holding a backup slice or not More...
 
grpc_slice slice_
 current slice passed back to the caller More...
 
grpc_slice_bufferslice_buffer_
 internal buffer of slices holding the serialized data More...
 
const int total_size_
 byte size of proto being serialized More...
 

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

Definition at line 55 of file impl/codegen/proto_buffer_writer.h.

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

Definition at line 62 of file impl/codegen/proto_buffer_writer.h.

◆ ~ProtoBufferWriter()

grpc::ProtoBufferWriter::~ProtoBufferWriter ( )
inlineoverride

Definition at line 75 of file impl/codegen/proto_buffer_writer.h.

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)

Definition at line 125 of file impl/codegen/proto_buffer_writer.h.

◆ ByteCount()

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

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

Definition at line 155 of file impl/codegen/proto_buffer_writer.h.

◆ 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

Definition at line 83 of file impl/codegen/proto_buffer_writer.h.

◆ set_byte_count()

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

Definition at line 163 of file impl/codegen/proto_buffer_writer.h.

◆ slice_buffer()

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

Definition at line 162 of file impl/codegen/proto_buffer_writer.h.

Friends And Related Function Documentation

◆ internal::ProtoBufferWriterPeer

friend class internal::ProtoBufferWriterPeer
friend

Definition at line 167 of file impl/codegen/proto_buffer_writer.h.

Member Data Documentation

◆ backup_slice_

grpc_slice grpc::ProtoBufferWriter::backup_slice_
private

holds space we can still write to, if the caller has called BackUp

Definition at line 174 of file impl/codegen/proto_buffer_writer.h.

◆ block_size_

const int grpc::ProtoBufferWriter::block_size_
private

size to alloc for each new grpc_slice needed

Definition at line 168 of file impl/codegen/proto_buffer_writer.h.

◆ byte_count_

int64_t grpc::ProtoBufferWriter::byte_count_
private

bytes written since this object was created

Definition at line 170 of file impl/codegen/proto_buffer_writer.h.

◆ have_backup_

bool grpc::ProtoBufferWriter::have_backup_
private

if we are holding a backup slice or not

Definition at line 173 of file impl/codegen/proto_buffer_writer.h.

◆ slice_

grpc_slice grpc::ProtoBufferWriter::slice_
private

current slice passed back to the caller

Definition at line 176 of file impl/codegen/proto_buffer_writer.h.

◆ slice_buffer_

grpc_slice_buffer* grpc::ProtoBufferWriter::slice_buffer_
private

internal buffer of slices holding the serialized data

Definition at line 172 of file impl/codegen/proto_buffer_writer.h.

◆ total_size_

const int grpc::ProtoBufferWriter::total_size_
private

byte size of proto being serialized

Definition at line 169 of file impl/codegen/proto_buffer_writer.h.


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


grpc
Author(s):
autogenerated on Fri May 16 2025 03:03:31