| 296 | |
| 297 | template <typename T> |
| 298 | inline void add_primitives(OutputStream* stream, |
| 299 | Serializer::GroupInfo & group_info, |
| 300 | const T* values, size_t n) { |
| 301 | if (!stream->good()) { |
| 302 | return; |
| 303 | } |
| 304 | if (!array_add_item(stream, group_info, GetFieldType<T>::value, n)) { |
| 305 | return stream->set_bad(); |
| 306 | } |
| 307 | if (group_info.isomorphic) { |
| 308 | stream->append(values, sizeof(T) * n); |
| 309 | } else { |
| 310 | // Even for mcpack arrays, we need to batch the values into an array |
| 311 | // of head+value and write the array into stream for (much) better |
| 312 | // throughput. |
| 313 | static const size_t BATCH = 128; |
| 314 | size_t nwritten = 0; |
| 315 | while (n) { |
| 316 | const size_t cur_batch = std::min(n, BATCH); |
| 317 | FixedHeadAndValue<T> tmp[cur_batch]; |
| 318 | for (size_t i = 0; i < cur_batch; ++i) { |
| 319 | tmp[i].head.set_type(GetFieldType<T>::value); |
| 320 | tmp[i].head.set_name_size(0); |
| 321 | tmp[i].value = values[nwritten + i]; |
| 322 | } |
| 323 | nwritten += cur_batch; |
| 324 | n -= cur_batch; |
| 325 | stream->append(tmp, sizeof(FixedHeadAndValue<T>) * cur_batch); |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | void Serializer::add_int8(const StringWrapper& name, int8_t value) |
| 331 | { add_primitive(_stream, peek_group_info(), name, value); } |
no test coverage detected