39 if(m_buffer_pos + input_size >= m_main_block_mod + m_final_minimum) {
40 size_t to_copy = std::min<size_t>(m_buffer.size() - m_buffer_pos, input_size);
42 copy_mem(&m_buffer[m_buffer_pos], input, to_copy);
43 m_buffer_pos += to_copy;
46 input_size -= to_copy;
48 const size_t available = std::min(m_buffer_pos, m_buffer_pos + input_size - m_final_minimum);
51 const size_t total_to_consume = available - (available % m_main_block_mod);
55 m_buffer_pos -= total_to_consume;
57 copy_mem(m_buffer.data(), m_buffer.data() + total_to_consume, m_buffer_pos);
60 if(input_size >= m_final_minimum) {
61 size_t full_blocks = (input_size - m_final_minimum) / m_main_block_mod;
62 size_t to_copy = full_blocks * m_main_block_mod;
68 input_size -= to_copy;
72 copy_mem(&m_buffer[m_buffer_pos], input, input_size);
73 m_buffer_pos += input_size;
80 if(m_buffer_pos < m_final_minimum) {
81 throw Invalid_State(
"Buffered filter end_msg without enough input");
84 size_t spare_blocks = (m_buffer_pos - m_final_minimum) / m_main_block_mod;
87 size_t spare_bytes = m_main_block_mod * spare_blocks;
89 buffered_final(&m_buffer[spare_bytes], m_buffer_pos - spare_bytes);