MCPcopy Create free account
hub / github.com/apache/fory / write_configured_map_data

Function write_configured_map_data

cpp/fory/serialization/struct_serializer.h:999–1044  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

997template <typename MapType, typename StructT, size_t Index, int8_t KeyNode,
998 int8_t ValueNode>
999void write_configured_map_data(const MapType &map, WriteContext &ctx) {
1000 using Key = key_type_t<MapType>;
1001 using Value = mapped_type_t<MapType>;
1002 ctx.write_var_uint32(static_cast<uint32_t>(map.size()));
1003 if (map.empty()) {
1004 return;
1005 }
1006 size_t header_offset = 0;
1007 uint8_t pair_counter = 0;
1008 bool need_write_header = true;
1009 for (const auto &[key, value] : map) {
1010 if (need_write_header) {
1011 ctx.enter_flush_barrier();
1012 header_offset = ctx.buffer().writer_index();
1013 ctx.write_uint16(0);
1014 ctx.buffer().unsafe_put_byte(
1015 header_offset, static_cast<uint8_t>(DECL_KEY_TYPE | DECL_VALUE_TYPE));
1016 need_write_header = false;
1017 }
1018 if constexpr (KeyNode >= 0) {
1019 write_configured_value<Key, StructT, Index, KeyNode>(
1020 key, ctx, RefMode::None, false, true);
1021 } else {
1022 Serializer<Key>::write_data(key, ctx);
1023 }
1024 if constexpr (ValueNode >= 0) {
1025 write_configured_value<Value, StructT, Index, ValueNode>(
1026 value, ctx, RefMode::None, false, true);
1027 } else {
1028 Serializer<Value>::write_data(value, ctx);
1029 }
1030 ++pair_counter;
1031 if (pair_counter == MAX_CHUNK_SIZE) {
1032 write_chunk_size(ctx, header_offset, pair_counter);
1033 ctx.exit_flush_barrier();
1034 ctx.try_flush();
1035 pair_counter = 0;
1036 need_write_header = true;
1037 }
1038 }
1039 if (pair_counter > 0) {
1040 write_chunk_size(ctx, header_offset, pair_counter);
1041 ctx.exit_flush_barrier();
1042 ctx.try_flush();
1043 }
1044}
1045
1046template <typename MapType, typename StructT, size_t Index, int8_t KeyNode,
1047 int8_t ValueNode>

Callers

nothing calls this directly

Calls 12

write_dataFunction · 0.85
writer_indexMethod · 0.80
unsafe_put_byteMethod · 0.80
write_chunk_sizeFunction · 0.70
write_var_uint32Method · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
enter_flush_barrierMethod · 0.45
bufferMethod · 0.45
write_uint16Method · 0.45
exit_flush_barrierMethod · 0.45
try_flushMethod · 0.45

Tested by

no test coverage detected