explicit Builder(osmium::memory::Buffer& buffer, Builder* parent, osmium::memory::item_size_type size) : m_buffer(buffer), m_parent(parent), m_item_offset(buffer.written()) { m_buffer.reserve_space(size); assert(buffer.is_aligned()); if (m_parent) { m_parent->add_size(size); } }
/** * Add padding to buffer (if needed) to align data properly. * * This calculates how many padding bytes are needed and adds * as many zero bytes to the buffer. It also adds this number * to the size of the current item (if the "self" param is * true) and recursively to all the parent items. * * @param self If true add number of padding bytes to size * of current item. Size is always added to * parent item (if any). * */ void add_padding(bool self = false) { const auto padding = osmium::memory::align_bytes - (size() % osmium::memory::align_bytes); if (padding != osmium::memory::align_bytes) { std::fill_n(m_buffer.reserve_space(padding), padding, 0); if (self) { add_size(padding); } else if (m_parent) { m_parent->add_size(padding); assert(m_parent->size() % osmium::memory::align_bytes == 0); } } }
void add_size(uint32_t size) { item().add_size(size); if (m_parent) { m_parent->add_size(size); } }