29#ifndef ACORE_BUFFER_BUILDER_H_
30#define ACORE_BUFFER_BUILDER_H_
106 return ac_buffer_size(&pBuilder->ac_buffer);
113static inline void ac_buffer_builder_set_length(
ac_buffer_builder_t *pBuilder,
size_t length)
115 if (ac_buffer_data(&pBuilder->ac_buffer) + length > pBuilder->data + pBuilder->size) {
118 pBuilder->ac_buffer.size = length;
127 return (uint8_t *)ac_buffer_data(&pBuilder->ac_buffer) + ac_buffer_size(&pBuilder->ac_buffer);
136 return ac_buffer_data(&pBuilder->ac_buffer) + ac_buffer_size(&pBuilder->ac_buffer) - pBuilder->data;
143static inline void ac_buffer_builder_set_write_offset(
ac_buffer_builder_t *pBuilder,
size_t off)
145 if (off > pBuilder->size) {
148 if (pBuilder->data + off > pBuilder->ac_buffer.data) {
149 pBuilder->ac_buffer.size = off - (pBuilder->ac_buffer.data - pBuilder->data);
151 pBuilder->ac_buffer.size = 0;
161 return ac_buffer_data(&pBuilder->ac_buffer) - pBuilder->data;
168static inline void ac_buffer_builder_set_read_offset(
ac_buffer_builder_t *pBuilder,
size_t off)
170 if (off > pBuilder->size) {
173 if (pBuilder->data + off < pBuilder->ac_buffer.data + pBuilder->ac_buffer.size) {
174 pBuilder->ac_buffer.size = pBuilder->ac_buffer.data - (pBuilder->data + off);
176 pBuilder->ac_buffer.size = 0;
178 pBuilder->ac_buffer.data = pBuilder->data + off;
187 return &pBuilder->ac_buffer;
196 return pBuilder->size - (ac_buffer_data(&pBuilder->ac_buffer) - pBuilder->data + ac_buffer_size(&pBuilder->ac_buffer));
205 return (ac_buffer_builder_length(pBuilder) == 0);
214 return (ac_buffer_builder_space(pBuilder) == 0);
230static inline void ac_buffer_builder_write_nu16(
ac_buffer_builder_t *pBuilder, uint16_t hu16)
239static inline void ac_buffer_builder_write_nu24(
ac_buffer_builder_t *pBuilder, uint32_t hu24)
248static inline void ac_buffer_builder_write_nu32(
ac_buffer_builder_t *pBuilder, uint32_t hu32)
257static inline void ac_buffer_builder_write_nu64(
ac_buffer_builder_t *pBuilder, uint64_t hu64)
267static inline void ac_buffer_builder_write_n_bytes(
ac_buffer_builder_t *pBuilder,
const uint8_t *data,
size_t size)
277static inline void ac_buffer_builder_write_nu8_at(
ac_buffer_builder_t *pBuilder,
size_t off, uint8_t hu8)
287static inline void ac_buffer_builder_write_nu16_at(
ac_buffer_builder_t *pBuilder,
size_t off, uint16_t hu16)
297static inline void ac_buffer_builder_write_nu24_at(
ac_buffer_builder_t *pBuilder,
size_t off, uint32_t hu24)
307static inline void ac_buffer_builder_write_nu32_at(
ac_buffer_builder_t *pBuilder,
size_t off, uint32_t hu32)
317static inline void ac_buffer_builder_write_nu64_at(
ac_buffer_builder_t *pBuilder,
size_t off, uint64_t hu64)
328static inline void ac_buffer_builder_write_n_bytes_at(
ac_buffer_builder_t *pBuilder,
size_t off,
const uint8_t *data,
size_t size)
358 return ac_buffer_builder_space(pBuilder);
void ac_buffer_builder_copy_n_bytes(ac_buffer_builder_t *pBuilderOut, ac_buffer_t *pBufIn, size_t size)
Copy n bytes from buffer to builder.
void ac_buffer_builder_compact(ac_buffer_builder_t *pBuilder)
Compact builder Will move underlying buffer's byte to start of allocated buffer.
void ac_buffer_builder_set_full(ac_buffer_builder_t *pBuilder)
Set ac_buffer builder's ac_buffer to full size.
void ac_buffer_builder_write_le_at(ac_buffer_builder_t *pBuilder, size_t pos, const uint8_t *buf, size_t size)
Write data to little endian ac_buffer at specific position (on a LE architecture, byte order will be ...
void ac_buffer_builder_from_buffer(ac_buffer_builder_t *pBuilder)
Initialize ac_buffer builder from underlying ac_buffer.
void ac_buffer_builder_write_n_skip(ac_buffer_builder_t *pBuilder, size_t size)
Skip n-bytes in ac_buffer builder.
void ac_buffer_builder_reset(ac_buffer_builder_t *pBuilder)
Reset ac_buffer builder.
void ac_buffer_builder_init(ac_buffer_builder_t *pBuilder, uint8_t *data, size_t size)
Initialize ac_buffer builder.
void ac_buffer_builder_write_le(ac_buffer_builder_t *pBuilder, const uint8_t *buf, size_t size)
Write data to little endian ac_buffer (on a LE architecture, byte order will be preserved)
void ac_buffer_builder_write_be_at(ac_buffer_builder_t *pBuilder, size_t pos, const uint8_t *buf, size_t size)
Write data to big endian ac_buffer at specific position (on a LE architecture, byte order will be swa...
void ac_buffer_builder_write_be(ac_buffer_builder_t *pBuilder, const uint8_t *buf, size_t size)
Write data to big endian ac_buffer (on a LE architecture, byte order will be swapped)