Welcome to little lamb

Code » limb » release » tree

[release] / src / doc / buffer.h / buffer_patrim_put.3.md

% limb manual
% buffer_patrim_put(3)
% limb 0.1.0
% 2023-07-24

# NAME

buffer\_patrim\_put, buffer\_patrim\_putv, buffer\_patrim\_get - write/read data
in PATRIM format

# SYNOPSIS

    #include <limb/buffer.h>

```pre hl
ssize_t buffer_patrim_put(buffer *<em>buf</em>, u64 <em>id</em>, u64 <em>u</em>, const char *<em>data</em>)
ssize_t buffer_patrim_putv(buffer *<em>buf</em>, u64 <em>id</em>, const struct iovec <em>v</em>[], unsigned int <em>n</em>)
int buffer_patrim_get(buffer *<em>buf</em>, u64 *<em>id</em>, u64 *<em>u</em>)
```

# DESCRIPTION

The `buffer_patrim_put`() function writes into the buffer `buf` the data for the
given `id` and its associated value or length, `u`, encoded in [patrim](5)
format.

So `u` must be either the value for an integer, or the length of the byte array
pointed by `data` for a blob.

The `buffer_patrim_putv`() function is similar, but only works for `id`
representing a blob, whose data must be pointed by the array `v` of length `n`.

The `buffer_patrim_get`() function reads [patrim](5)-encoded data from the
buffer `buf`, placing the ID in the value pointed by `id` and its associated
value or length, depending whether the ID represents an integer or a blob, in
the value pointed by `u`.

In case of a blob, the actual content is not read, it is up to the caller to
get as many bytes from `buf` as the value placed into `u`.

# RETURN VALUE

The `buffer_patrim_put`() and `buffer_patrim_putv`() functions return the number
of bytes written on success. Otherwise they return -1 and set `errno` to
indicate the error.

The `buffer_patrim_get`() function returns 1 on success, 0 on failure.

# ERRORS

The `buffer_patrim_put`() and `buffer_patrim_putv`() functions may fail and set
`errno` for any of the errors specified for [buffer_putv](3).

The `buffer_patrim_get`() function may fail if :

: *EPIPE*
:: Not enough data could be read from the buffer before reaching end-of-file.

It may also fail for any of the error specified for [buffer_fill](3).