protobuf-c 1.5.1
Protocol Buffers implementation in C
ProtobufCBufferSimple Struct Reference

Simple buffer "subclass" of ProtobufCBuffer. More...

Data Fields

ProtobufCBuffer base
 "Base class".
 
size_t alloced
 Number of bytes allocated in data.
 
size_t len
 Number of bytes currently stored in data.
 
uint8_t * data
 Data bytes.
 
protobuf_c_boolean must_free_data
 Whether data must be freed.
 
ProtobufCAllocatorallocator
 Allocator to use.
 

Detailed Description

Simple buffer "subclass" of ProtobufCBuffer.

A ProtobufCBufferSimple object is declared on the stack and uses a scratch buffer provided by the user for the initial allocation. It performs exponential resizing, using dynamically allocated memory. A ProtobufCBufferSimple object can be created and used as follows:

uint8_t pad[128];
ProtobufCBuffer *buffer = (ProtobufCBuffer *) &simple;

buffer can now be used with protobuf_c_message_pack_to_buffer(). Once a message has been serialized to a ProtobufCBufferSimple object, the serialized data bytes can be accessed from the .data field.

To free the memory allocated by a ProtobufCBufferSimple object, if any, call PROTOBUF_C_BUFFER_SIMPLE_CLEAR() on the object, for example:

See also
PROTOBUF_C_BUFFER_SIMPLE_INIT
PROTOBUF_C_BUFFER_SIMPLE_CLEAR

Field Documentation

◆ base

ProtobufCBuffer ProtobufCBufferSimple::base

"Base class".

◆ alloced

size_t ProtobufCBufferSimple::alloced

Number of bytes allocated in data.

◆ len

size_t ProtobufCBufferSimple::len

Number of bytes currently stored in data.

◆ data

uint8_t* ProtobufCBufferSimple::data

Data bytes.

◆ must_free_data

protobuf_c_boolean ProtobufCBufferSimple::must_free_data

Whether data must be freed.

◆ allocator

ProtobufCAllocator* ProtobufCBufferSimple::allocator

Allocator to use.

May be NULL to indicate the system allocator.