MCPcopy Create free account
hub / github.com/apache/brpc / add_primitives

Function add_primitives

src/mcpack2pb/serializer.cpp:298–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

296
297template <typename T>
298inline 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
330void Serializer::add_int8(const StringWrapper& name, int8_t value)
331{ add_primitive(_stream, peek_group_info(), name, value); }

Callers 11

add_multiple_int8Method · 0.85
add_multiple_int16Method · 0.85
add_multiple_int32Method · 0.85
add_multiple_int64Method · 0.85
add_multiple_uint8Method · 0.85
add_multiple_uint16Method · 0.85
add_multiple_uint32Method · 0.85
add_multiple_uint64Method · 0.85
add_multiple_boolMethod · 0.85
add_multiple_floatMethod · 0.85
add_multiple_doubleMethod · 0.85

Calls 6

array_add_itemFunction · 0.85
goodMethod · 0.45
set_badMethod · 0.45
appendMethod · 0.45
set_typeMethod · 0.45
set_name_sizeMethod · 0.45

Tested by

no test coverage detected