| 144 | } |
| 145 | |
| 146 | void KVBinaryOutputStream::write_element_prefix(uint8_t type) { |
| 147 | invariant(!m_stack.empty(), "unexpected root"); |
| 148 | |
| 149 | Level &level = m_stack.back(); |
| 150 | auto &s = stream(); |
| 151 | |
| 152 | if (verbose_debug) |
| 153 | std::cout << "write_element_prefix level.state=" << int(level.state) << std::endl; |
| 154 | if (level.state == State::Object) { |
| 155 | invariant(m_next_key.data(), ""); |
| 156 | write_element_name(s, m_next_key); |
| 157 | if (type != BIN_KV_SERIALIZE_TYPE_ARRAY) |
| 158 | s.write(&type, 1); |
| 159 | m_next_key = common::StringView(); |
| 160 | ++level.count; |
| 161 | } |
| 162 | if (level.state == State::ArrayPrefix) { |
| 163 | // if(type == BIN_KV_SERIALIZE_TYPE_INT64 || type == BIN_KV_SERIALIZE_TYPE_UINT64) |
| 164 | // std::cout << "Breakpoint" << std::endl; |
| 165 | unsigned char c = BIN_KV_SERIALIZE_FLAG_ARRAY | type; |
| 166 | s.write(&c, 1); |
| 167 | write_array_size(s, level.count); |
| 168 | if (verbose_tokens) |
| 169 | std::cout << "ARR t=" << int(type) << " c=" << level.count << std::endl; |
| 170 | level.state = State::Array; |
| 171 | level.array_type = type; |
| 172 | if (verbose_debug) |
| 173 | std::cout << "written BIN_KV_SERIALIZE_FLAG_ARRAY | type level.count=" << int(level.count) << std::endl; |
| 174 | } |
| 175 | if (level.state == State::Array && level.array_type != type) |
| 176 | throw std::logic_error("Array elements types are non-uniform"); |
| 177 | } |
| 178 | |
| 179 | common::VectorStream &KVBinaryOutputStream::stream() { |
| 180 | invariant(!m_objects_stack.empty(), ""); |
nothing calls this directly
no test coverage detected