PB_REPEATED(3)

NAME
pb_repeated - protocol buffers repeated fields

LIBRARY
Protocol buffers library (libpicopb, -lpicopb)

SYNOPSIS
#include <pb.h>
size_t
pb_repeated_count(const struct pb_repeated *repeated);
int
pb_repeated_add(const struct pb_repeated *repeated, size_t *ip);
int
pb_repeated_alloc(const struct pb_repeated *repeated, size_t n);

DESCRIPTION
The pb_repeated functions manage repeated fields in the in-memory representation of protobuf messages. A repeated field of type T is stored in C message structure with the type:

    struct {
            struct pb_repeated      repeated;
            T                       *item;
    };

The array of T objects pointed to by the item member of this struct is allocated by pb_repeated using the enclosing message's allocator (see pb(3) about allocators). Elements can be added dynamically one by one with pb_repeated_add(), or a batch of elements can be allocated up front with pb_repeated_alloc() and then filled by the user.

FUNCTIONS

pb_repeated_count(repeated)
    Returns the number of elements currently stored in the array associated with repeated.

pb_repeated_add(repeated, ip)
    Allocate space for another element in the array associated with repeated and return its index in *ip.

    Returns zero on success or ENOMEM if out of memory.

pb_repeated_alloc(repeated, n)
    Allocate or deallocate space for repeated to store n elements. If n is larger than the number of elements previously stored by repeated, new elements at the end are initialized as if with pb_init(3). If n is smaller than the number of elements previously stored by repeated, old elements at the end are destroyed as if with pb_destroy(3).

    Returns zero on success or ENOMEM if out of memory.

SEE ALSO
picopbc(1), errno(2), pb(3)

AUTHORS
Taylor R Campbell <campbell+picopb@mumble.net>